Unity编辑器类在Scene下绘制贝塞尔曲线
在Editor文件夹下创建脚本 HandlerTest 如下
using UnityEngine;
using System.Collections;
using UnityEditor;
[CustomEditor(typeof(Arraw))]
public class HandlerTest : Editor {
Vector3[] positions;
void OnSceneGUI()
{
float width = HandleUtility.GetHandleSize(Vector3.zero) * 0.5f;
Arraw arraw = (Arraw)target;
Handles.DrawBezier(arraw.transform.position, Vector3.zero, new Vector3(20, 20, 20), new Vector3(10, 10, 10), Color.yellow, null, width);
//参数1 开始点坐标, 参数2,结束点坐标, 参数3 开始切线位置, 参数 4,结束切线位置, 参数 5 线的颜色 ,参数六 线的宽度
if (GUI.changed)
{
EditorUtility.SetDirty(arraw);
}
}
}
Arraw脚本如下,将其拖拽到需要画线的对象即可
using UnityEngine;
using System.Collections;
public class Arraw : MonoBehaviour {
}