读一读

using UnityEditor;
[MenuItem("Item/1")]
public static void Item(){
	Debug.Log ("1");
}


新建类放在Editor文件夹下,不需要继承自MonoBehaviour,菜单使用特性MenuItem声明,参数为菜单路径,触发调用的为下面的方法(静态方法)


//定义两个点
public class Line:MonoBehaviour{
    public Vector3 p0,p1;
}
//定制编辑器
using UnityEditor;
using UnityEngine;

[CustomEditor(typeof(Line))]
public class LineInspector:Editor{
    private void OnSceneGUI(){
        Line line = target as Line;
        Transform handleTransform = line.transform;
        Vector3 p0 = handleTransform.Transform.TransformPoint(line.p0);
        Vector3 p1 = handleTransform.Transform.TransformPoint(line.p1);
        Handles.color = Color.white;
        Handles.DrawLine(p0,p1);
    }
}


继承自Editor的类需要放在Editor文件夹里面

在场景中附加Line脚本,编辑器的方法就会生效了

选中Line物体时,就可以在场景中看到相对本身的两点的线了