Unity GUI内绘制贝塞尔曲线

时间:2023-03-08 16:07:04

用Handles可以直接在GUI下绘制贝塞尔

using UnityEditor;
using UnityEngine;
using System.Collections;

public class GUIBezier : EditorWindow
{
    Vector3 mOri;
    Vector3 mEnd;
    Vector3 mOriTang;
    Vector3 mEndTang;

    [MenuItem("GUIBezierTest/GUIBezier")]
    public static void CallFunc()
    {
        EditorWindow.GetWindow<GUIBezier>();
    }

    void OnGUI()
    {
        mOri = EditorGUILayout.Vector3Field("ori", mOri);
        mOriTang = EditorGUILayout.Vector3Field("oriTang", mOriTang);
        mEnd = EditorGUILayout.Vector3Field("end", mEnd);
        mEndTang = EditorGUILayout.Vector3Field("endTang", mEndTang);

        Handles.DrawBezier(mOri, mEnd, mOriTang, mEndTang, Color.black, null, 2f);
    }
}

Unity GUI内绘制贝塞尔曲线