Exemple #1
0
        public override void OnInspectorGUI()
        {
            Color c = GUI.color;

            if (spline != null && !spline.Equals(null))
            {
                BezierUtils.DrawSplineInspectorGUI(spline);

                if (point == null || point.Equals(null))
                {
                    return;
                }

                EditorGUILayout.Space();
                DrawSeparator();

                GUILayout.BeginHorizontal();

                if (GUILayout.Button("<-", GUILayout.Width(45)))
                {
                    int prevIndex = spline.IndexOf(point) - 1;
                    if (prevIndex < 0)
                    {
                        prevIndex = spline.Count - 1;
                    }

                    Selection.activeTransform = spline[prevIndex].transform;
                    return;
                }

                GUILayout.Box("Selected Point: " + (spline.IndexOf(point) + 1) + " / " + spline.Count, GUILayout.ExpandWidth(true));

                if (GUILayout.Button("->", GUILayout.Width(45)))
                {
                    int nextIndex = spline.IndexOf(point) + 1;
                    if (nextIndex >= spline.Count)
                    {
                        nextIndex = 0;
                    }

                    Selection.activeTransform = spline[nextIndex].transform;
                    return;
                }

                GUILayout.EndHorizontal();

                EditorGUILayout.Space();

                if (GUILayout.Button("Decrement Point's Index"))
                {
                    int index    = spline.IndexOf(point);
                    int newIndex = index - 1;
                    if (newIndex < 0)
                    {
                        newIndex = spline.Count - 1;
                    }

                    if (index != newIndex)
                    {
                        Undo.IncrementCurrentGroup();
                        Undo.RegisterCompleteObjectUndo(point.transform.parent, "Change point index");

                        spline.SwapPointsAt(index, newIndex);
                        SceneView.RepaintAll();
                    }
                }

                if (GUILayout.Button("Increment Point's Index"))
                {
                    int index    = spline.IndexOf(point);
                    int newIndex = index + 1;
                    if (newIndex >= spline.Count)
                    {
                        newIndex = 0;
                    }

                    if (index != newIndex)
                    {
                        Undo.IncrementCurrentGroup();
                        Undo.RegisterCompleteObjectUndo(point.transform.parent, "Change point index");

                        spline.SwapPointsAt(index, newIndex);
                        SceneView.RepaintAll();
                    }
                }

                EditorGUILayout.Space();

                if (GUILayout.Button("Insert Point Before"))
                {
                    InsertNewPointAt(spline.IndexOf(point));
                }

                if (GUILayout.Button("Insert Point After"))
                {
                    InsertNewPointAt(spline.IndexOf(point) + 1);
                }

                EditorGUILayout.Space();

                if (GUILayout.Button("Duplicate Point"))
                {
                    DuplicatePointAt(spline.IndexOf(point));
                }

                EditorGUILayout.Space();
            }

            EditorGUI.BeginChangeCheck();
            BezierPoint.HandleMode handleMode = (BezierPoint.HandleMode)EditorGUILayout.EnumPopup("Handle Mode", point.handleMode);
            if (EditorGUI.EndChangeCheck())
            {
                Undo.RecordObject(point, "Change Point Handle Mode");
                point.handleMode = handleMode;

                SceneView.RepaintAll();
            }

            EditorGUILayout.Space();

            EditorGUI.BeginChangeCheck();
            Vector3 position = EditorGUILayout.Vector3Field("Preceding Control Point Local Position", point.precedingControlPointLocalPosition);

            if (EditorGUI.EndChangeCheck())
            {
                Undo.RecordObject(point, "Change Point Position");
                point.precedingControlPointLocalPosition = position;

                SceneView.RepaintAll();
            }

            EditorGUI.BeginChangeCheck();
            position = EditorGUILayout.Vector3Field("Following Control Point Local Position", point.followingControlPointLocalPosition);
            if (EditorGUI.EndChangeCheck())
            {
                Undo.RecordObject(point, "Change Point Position");
                point.followingControlPointLocalPosition = position;

                SceneView.RepaintAll();
            }

            EditorGUILayout.Space();

            if (GUILayout.Button("Swap Control Points"))
            {
                Undo.RecordObject(point, "Swap Control Points");
                Vector3 precedingControlPointLocalPos = point.precedingControlPointLocalPosition;
                point.precedingControlPointLocalPosition = point.followingControlPointLocalPosition;
                point.followingControlPointLocalPosition = precedingControlPointLocalPos;

                SceneView.RepaintAll();
            }

            EditorGUILayout.Space();

            DrawSeparator();

            if (spline != null && !spline.Equals(null))
            {
                GUI.color = RESET_POINT_BUTTON_COLOR;

                if (GUILayout.Button("Reset Point"))
                {
                    ResetEndPointAt(spline.IndexOf(point));
                    SceneView.RepaintAll();
                }

                EditorGUILayout.Space();

                GUI.color = REMOVE_POINT_BUTTON_COLOR;

                if (spline.Count <= 2)
                {
                    GUI.enabled = false;
                }

                if (GUILayout.Button("Remove Point"))
                {
                    RemovePointAt(spline.IndexOf(point));
                }

                GUI.enabled = true;
            }

            GUI.color = c;
        }
Exemple #2
0
 public override void OnInspectorGUI()
 {
     BezierUtils.DrawSplineInspectorGUI(spline);
 }