Gizmos

作者:追风剑情 发布于:2019-4-22 21:57 分类:Unity3d

示例一


using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class DrawGizmos : MonoBehaviour
{
    public GizmoType gizmoType;
    public Color32 color = Color.white;

    void OnDrawGizmos()
    {
        Gizmos.color = color;
        switch (gizmoType)
        {
            case GizmoType.Sphere:
                Gizmos.DrawSphere(transform.position, 0.2f);
                break;
            case GizmoType.Ray:
                Gizmos.DrawRay(transform.position, Vector3.up);
                break;
            case GizmoType.Line:
                Gizmos.DrawLine(transform.position, transform.position + Vector3.one);
                break;
            case GizmoType.Cube:
                Gizmos.DrawCube(transform.position, Vector3.one/2);
                break;
            case GizmoType.Frustum:
                Gizmos.DrawFrustum(transform.position, 30, 4, 1, 1);
                break;
            case GizmoType.Icon:
                //要绘制的图标需放在 Assets/Gizmos 目录下
                Gizmos.DrawIcon(transform.position, "icon", true);
                break;
            case GizmoType.WireSphere:
                Gizmos.DrawWireSphere(transform.position, 0.2f);
                break;
        }
    }
}

public enum GizmoType
{
    Sphere,
    Ray,
    Line,
    Cube,
    Frustum,
    Icon,
    WireSphere
}


Scene场景

111.png222.png

标签: Unity3d

Powered by emlog  蜀ICP备18021003号-1   sitemap

川公网安备 51019002001593号