示例#1
0
    private void DrawEditInspector()
    {
        if (selectedIndex >= 0)
        {
            if (component.GetConnectedIndex(activeSpline, selectedIndex) >= 0)
            {
                GUILayout.BeginHorizontal();
                if (GUILayout.Button("Previous", GUILayout.Height(EditorGUIUtility.singleLineHeight)))
                {
                    ControlPoint newPoint = component.GetConnectedPoint(activeSpline, selectedIndex, -1);
                    activeSpline   = component.GetSpline(newPoint);
                    selectedIndex  = component.GetIndex(activeSpline, newPoint);
                    selectedHandle = 0;
                    SceneView.RepaintAll();
                }
                int    connectedIndex = component.GetConnectedIndex(activeSpline, selectedIndex);
                string label          = string.Concat("( Handle ", component.GetIndexInConnection(activeSpline, selectedIndex) + 1, " of ", component.GetConnectionPointCount(connectedIndex), " )");
                GUILayout.Label(label, GUILayout.Width(100));
                if (GUILayout.Button("  Next  ", GUILayout.Height(EditorGUIUtility.singleLineHeight)))
                {
                    ControlPoint newPoint = component.GetConnectedPoint(activeSpline, selectedIndex, 1);
                    activeSpline   = component.GetSpline(newPoint);
                    selectedIndex  = component.GetIndex(activeSpline, newPoint);
                    selectedHandle = 0;
                    SceneView.RepaintAll();
                }
                GUILayout.EndHorizontal();
            }

            EditorGUILayout.Space();
            GUILayout.Label("Anchor:");
            EditorGUI.indentLevel++;

            EditorGUI.BeginChangeCheck();
            Vector3 anchor = EditorGUILayout.Vector3Field("Position", component.GetPoint(activeSpline, selectedIndex));
            if (EditorGUI.EndChangeCheck())
            {
                Undo.RecordObject(component, "Move Anchor");
                EditorUtility.SetDirty(component);
                component.SetAnchorPosition(activeSpline, selectedIndex, anchor);
            }

            EditorGUI.BeginChangeCheck();
            Vector3 rotation = EditorGUILayout.Vector3Field("Rotation", component.GetEulerAngles(activeSpline, selectedIndex));
            if (EditorGUI.EndChangeCheck())
            {
                Undo.RecordObject(component, "Rotate Anchor");
                EditorUtility.SetDirty(component);
                component.SetRotation(activeSpline, selectedIndex, Quaternion.Euler(rotation));
            }

            EditorGUI.indentLevel--;
            EditorGUILayout.Space();
            GUILayout.Label("Handles:");
            EditorGUI.indentLevel++;

            EditorGUI.BeginChangeCheck();
            BezierControlPointMode mode = (BezierControlPointMode)EditorGUILayout.EnumPopup("Mode", component.GetMode(activeSpline, selectedIndex));
            if (EditorGUI.EndChangeCheck())
            {
                Undo.RecordObject(component, "Change Point Mode");
                EditorUtility.SetDirty(component);
                component.SetMode(activeSpline, selectedIndex, mode);
            }

            EditorGUI.BeginChangeCheck();
            float handle_0 = EditorGUILayout.FloatField(mode == BezierControlPointMode.Mirrored ? "Scale" : "Scale (Back)",
                                                        component.GetHandleMagnitude(activeSpline, selectedIndex, 0));
            if (EditorGUI.EndChangeCheck())
            {
                Undo.RecordObject(component, "Move handle");
                EditorUtility.SetDirty(component);
                component.SetHandleMagnitude(activeSpline, selectedIndex, 0, handle_0);
            }

            if (mode == BezierControlPointMode.Aligned)
            {
                EditorGUI.BeginChangeCheck();
                float handle_1 = EditorGUILayout.FloatField("Scale (Forward)",
                                                            component.GetHandleMagnitude(activeSpline, selectedIndex, 1));
                if (EditorGUI.EndChangeCheck())
                {
                    Undo.RecordObject(component, "Move handle");
                    EditorUtility.SetDirty(component);
                    component.SetHandleMagnitude(activeSpline, selectedIndex, 1, handle_1);
                }
            }

            EditorGUI.indentLevel--;
            EditorGUILayout.Space();

            Texture before = Resources.Load <Texture>("AddPoint_MB");
            Texture after  = Resources.Load <Texture>("AddPoint_MA");
            Texture remove = Resources.Load <Texture>("AddPoint_MR");
            if (selectedIndex == 0)
            {
                before = Resources.Load <Texture>("AddPoint_SB");
                after  = Resources.Load <Texture>("AddPoint_SA");
                remove = Resources.Load <Texture>("AddPoint_SR");
            }
            else if (selectedIndex == component.PointCount(activeSpline) - 1)
            {
                before = Resources.Load <Texture>("AddPoint_EB");
                after  = Resources.Load <Texture>("AddPoint_EA");
                remove = Resources.Load <Texture>("AddPoint_ER");
            }

            GUILayout.BeginHorizontal();
            if (GUILayout.Button(before, GUILayout.Height(EditorGUIUtility.singleLineHeight + 3)))
            {
                Undo.RecordObject(component, "Add point before current");
                EditorUtility.SetDirty(component);
                component.InsertControlPoint(activeSpline, selectedIndex);
            }
            if (GUILayout.Button(after, GUILayout.Height(EditorGUIUtility.singleLineHeight + 3)))
            {
                Undo.RecordObject(component, "Add point after current");
                EditorUtility.SetDirty(component);
                if (selectedIndex == component.PointCount(activeSpline) - 1)
                {
                    component.AddControlPoint(activeSpline);
                }
                else
                {
                    component.InsertControlPoint(activeSpline, selectedIndex + 1);
                }
                selectedIndex++;
            }
            GUILayout.EndHorizontal();

            GUILayout.BeginHorizontal();
            if (GUILayout.Button(remove, GUILayout.Height(EditorGUIUtility.singleLineHeight + 3)))
            {
                Undo.RecordObject(component, "Remove point");
                EditorUtility.SetDirty(component);
                component.RemovePoint(activeSpline, selectedIndex);
                activeSpline   = -1;
                selectedIndex  = -1;
                selectedHandle = 0;
            }
            if (GUILayout.Button(Resources.Load <Texture>("AddPoint_NS"), GUILayout.Height(EditorGUIUtility.singleLineHeight + 3)))
            {
                Undo.RecordObject(component, "Start new curve");
                EditorUtility.SetDirty(component);
                component.AddSpline(activeSpline, selectedIndex);
                activeSpline   = component.splineCount - 1;
                selectedIndex  = 1;
                selectedHandle = 0;
            }
            GUILayout.EndHorizontal();
            EditorGUILayout.Space();
        }
    }