//定义两个点
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物体时,就可以在场景中看到相对本身的两点的线了