Unity之Handles箭头

Unity编辑器类,在Scene下创建箭头

Unity之Handles箭头_第1张图片



在Editor文件夹下创建脚本如下,

using UnityEngine;
using System.Collections;
using UnityEditor;


[CustomEditor(typeof(Arraw))]
public class HandlerTest : Editor {

    int arrowSize = 1;

    void OnSceneGUI()
    {
        Handles.color = Color.red;  //颜色 
        Arraw ArrawTarget =(Arraw)target;  //目标脚本
        Handles.ArrowCap( 0, ArrawTarget.transform.position + new Vector3( 5.0f, 0.0f, 0.0f),
            ArrawTarget.transform.rotation, arrowSize); // 参数1 控制ID, 参数2 位置,参数3 旋转角度, 参数4 箭头长度


        Handles.color = Color.green;
        Handles.ArrowCap( 0, ArrawTarget.transform.position + new Vector3(0.0f, 5.0f, 0.0f),
            ArrawTarget.transform.rotation, arrowSize);

        Handles.color = Color.yellow;
        Handles.ArrowCap( 0, ArrawTarget.transform.position + new Vector3(0.0f, 0.0f,5.0f),
            ArrawTarget.transform.rotation, arrowSize);
    }


}





Arraw脚本如下,什么都没写,需要给哪个对象画箭头,将该脚本拖拽到该对象上即可
using UnityEngine;
using System.Collections;

public class Arraw : MonoBehaviour {
}





你可能感兴趣的:(Unity之Editor)