示例#1
0
    private void DrawInspectorBezierPointControls()
    {
        List <BezierPoint> points = bezierCurve.GetAnchorPoints();

        string[] bezierPointTypes = System.Enum.GetNames(typeof(BezierPointType));

        if (points == null)
        {
            return;
        }

        for (int i = 0; i < points.Count; i++)
        {
            BezierPoint bezierPoint = points [i];

            GUILayout.BeginHorizontal();
            GUILayout.Label(bezierPoint.name);
            EditorGUI.BeginChangeCheck();
            BezierPointType pointType = (BezierPointType)EditorGUILayout.Popup((int)bezierPoint.pointType, bezierPointTypes);
            if (EditorGUI.EndChangeCheck())
            {
                Undo.RecordObject(bezierCurve, "Change Point Type");

                bezierPoint.pointType = pointType;
                SceneView.RepaintAll();
            }
            if (GUILayout.Button("X", GUILayout.Width(15), GUILayout.Height(15)))
            {
                RemovePoint(bezierPoint);
            }
            GUILayout.EndHorizontal();

            Vector3 position = EditorGUILayout.Vector3Field("    Position: ", bezierPoint.position);

            if (bezierPoint.pointType != BezierPointType.None)
            {
                Vector3 handle1 = EditorGUILayout.Vector3Field("    Handle 1: ", bezierPoint.handle1);
                Vector3 handle2 = EditorGUILayout.Vector3Field("    Handle 2: ", bezierPoint.handle2);

                if (bezierPoint.GetHandle1LocalPosition() != handle1)
                {
                    Undo.RecordObject(target, "Move Handle Point 1");
                    bezierPoint.handle1 = handle1;
                }
                if (bezierPoint.GetHandle2LocalPosition() != handle2)
                {
                    Undo.RecordObject(target, "Move Handle Point 2");
                    bezierPoint.handle2 = handle2;
                }
            }

            if (bezierPoint.GetLocalPosition() != position)
            {
                Undo.RecordObject(target, "Move Point");
                bezierPoint.SetPosition(position);
            }
        }
    }