Gizmos-绘制坐标轴方向的辅助线

#

#if UNITY_EDITOR

using UnityEditor;
using UnityEngine;

public class GizmosDrawAxis : MonoBehaviour
{

    public Color color = Color.yellow;
    public bool isSelectedDraw = false;
    [Range(1, 20)]
    public float length = 5;
    public bool upLineShow = true;
    public bool forwardLineShow = true;
    public bool rightLineShow = true;

    [DrawGizmo(GizmoType.Selected | GizmoType.NonSelected)]
    static void MyDrawGizmos(GizmosDrawAxis target, GizmoType gizmoType)
    {
        if (!target.isSelectedDraw && 0 != (gizmoType & GizmoType.Selected))
        {
            return;
        }

        var transform = target.transform;

        var colorBak = Gizmos.color;

        Gizmos.color = target.color;
        var myPos = transform.position;

        if (target.upLineShow)
        {
            var upPos = myPos + transform.up * target.length;
            Gizmos.DrawLine(myPos, upPos);
        }

        if (target.forwardLineShow)
        {
            var forwardPos = myPos + transform.forward * target.length;
            Gizmos.DrawLine(myPos, forwardPos);
        }

        if (target.rightLineShow)
        {
            var rightPos = myPos + transform.right * target.length;
            Gizmos.DrawLine(myPos, rightPos);
        }

        Gizmos.color = colorBak;
    }

}

#endif

 

【关于Gizmos如何翻译?】

小工具? 一些小工具? 各类小工具? 一系列辅助工具? 小的指示器?

 

【参考】

Unity 小工具菜单(Gizmos menu)_w3cschool

untiy 脚本API之可视化辅助类Gizmos_BlueBones_fan的博客-CSDN博客

 

posted @ 2022-06-17 23:22  yanghui01  阅读(239)  评论(0)    收藏  举报