Exemplo n.º 1
0
        public override void OnInspectorGUI()
        {
            //adjust math if needed
            AdjustMath(BGPrivateField.GetSettings(Curve), Math);

            //styles
            BGEditorUtility.Assign(ref stickerStyle, () => new GUIStyle("Label") {fontSize = 18, alignment = TextAnchor.MiddleCenter, normal = new GUIStyleState {textColor = Color.white}});

            serializedObject.Update();

            // =========== Header
            DrawLogo();

            // =========== lock view
            BGEditorUtility.Horizontal(() =>
            {
                var temp = BGCurveSettingsForEditor.LockView;
                BGCurveSettingsForEditor.LockView = BGEditorUtility.ButtonOnOff(ref temp, "Lock view", "Disable selection of any object in the scene, except points", LockViewActiveColor,
                    new GUIContent("Turn Off", "Click to turn this mode off"),
                    new GUIContent("Turn On", "Click to turn this mode on"));

                if (GUILayout.Button(BGBinaryResources.BGSettingsIcon123, GUILayout.MaxWidth(24), GUILayout.MaxHeight(24))) BGCurveSettingsForEditorWindow.Open(BGCurveSettingsForEditor.I);
            });

            //warning
            BGEditorUtility.HelpBox("You can not chose another objects in the scene, except points.", MessageType.Warning, BGCurveSettingsForEditor.LockView, () => GUILayout.Space(8));

            // =========== Tabs
            var currentTab = BGCurveSettingsForEditor.CurrentTab;
            if (currentTab < 0 || currentTab > headers.Length - 1) currentTab = 0;
            var newTab = GUILayout.Toolbar(currentTab, headers, GUILayout.Height(ToolBarHeight));
            //do not move this method(GUILayoutUtility.GetLastRect() is used) 
            ShowStickers();
            if (currentTab != newTab) GUI.FocusControl("");
            BGCurveSettingsForEditor.CurrentTab = newTab;
            editors[newTab].OnInspectorGui();

            if (!GUI.changed) return; // if no change- return

            foreach (var editor in editors) editor.OnApply();

            transformMonitor.CheckForChange();
        }
Exemplo n.º 2
0
        // ================================================================================ Inspector
        public override void OnInspectorGui()
        {
            var settings = BGPrivateField.GetSettings(Curve);

            BGEditorUtility.HelpBox("Curve UI is disabled in settings. All handles are disabled too.", MessageType.Warning, !settings.ShowCurve);

            BGEditorUtility.Assign(ref systemUi, () => new TableUi("System fields", new[] { "Name", "Value" }, new[] { LabelWidth, 100 - LabelWidth }));
            BGEditorUtility.Assign(ref customUi, () => new TableUi("Custom fields", new[] { "Name", "Value" }, new[] { LabelWidth, 100 - LabelWidth }));

            BGEditorUtility.Assign(ref systemFields, () => new[]
            {
                (SystemField) new SystemFieldPosition(settings),
                new SystemFieldControls(settings),
                new SystemFieldControlsType(settings),
            });

            //warnings
            BGEditorUtility.HelpBox("All handles for positions are disabled.", MessageType.Warning, settings.HandlesSettings.Disabled);
            BGEditorUtility.HelpBox("All handles for controls are disabled.", MessageType.Warning, settings.ControlHandlesSettings.Disabled);

            systemUi.Init();

            foreach (var field in systemFields)
            {
                field.Ui(systemUi);
            }

            //inform layout manager
            GUILayoutUtility.GetRect(systemUi.Width, systemUi.Height);

            customUi.Init();
            customUi.NextRow("Custom fields are not supported in this version.");

            GUILayoutUtility.GetRect(customUi.Width, customUi.Height);

            GUILayout.Space(4);
        }
Exemplo n.º 3
0
        // ================================================================================ Inspector
        public override void OnInspectorGui()
        {
            var settings = Settings;

            editorSelection.Reset();

            // ======================================== Top section
            InspectorTopSection();

            // ======================================== Points
            GUILayout.Space(5);

            if (Curve.PointsCount > 0)
            {
                BGEditorUtility.VerticalBox(() =>
                {
                    var temp = BGCurveSettingsForEditor.DisableInspectorPointMenu;
                    BGCurveSettingsForEditor.DisableInspectorPointMenu = BGEditorUtility.ButtonOnOff(ref temp, "Points menu [" + Curve.PointsCount + "]", "Show points in Editor inspector",
                                                                                                     HiddenPointMenuColor,
                                                                                                     new GUIContent("Show", "Click to show points menu"),
                                                                                                     new GUIContent("Hide", "Click to hide points menu"), () =>
                    {
                        const string title = "Reverse points";

                        if (!GUILayout.Button(new GUIContent(title, "Reverse all points, but keep curve intact")))
                        {
                            return;
                        }

                        if (Curve.PointsCount < 2)
                        {
                            BGEditorUtility.Inform(title, "There should be at least 2 points. Curve has " + Curve.PointsCount);
                            return;
                        }
                        if (!BGEditorUtility.Confirm(title, "Are you sure you want to reverse the order of " + Curve.PointsCount + " points? Curve will remain intact.", "Reverse"))
                        {
                            return;
                        }

                        Curve.Reverse();
                    });

                    //show points!
                    if (!BGCurveSettingsForEditor.DisableInspectorPointMenu)
                    {
                        SwapVector2Labels(Curve.Mode2D, () => Curve.ForEach((point, index, count) => editorPoint.OnInspectorGui(point, index, settings)));
                    }
                });

                // ======================================== Selections operations
                editorSelection.InspectorSelectionOperations();

                //warning
                BGEditorUtility.HelpBox("Selection mode is on", MessageType.Warning, !editorSelection.Changed && editorSelection.HasSelected());
            }
            else
            {
                BGEditorUtility.HorizontalBox(() =>
                {
                    EditorGUILayout.LabelField("No points!");

                    if (BGEditorUtility.ButtonWithIcon(BGBinaryResources.BGAdd123, "Add new point at (0,0,0) local coordinates"))
                    {
                        BGCurveEditor.AddPoint(Curve, new BGCurvePoint(Curve, Vector3.zero, settings.ControlType, Vector3.right, Vector3.left), 0);
                    }
                });
            }

            if (!editorSelection.Changed)
            {
                return;
            }

            Editor.Repaint();
            SceneView.RepaintAll();
        }
        //OnInspectorGui for selection
        public void InspectorSelectionOperations()
        {
            BGEditorUtility.VerticalBox(() =>
            {
                // ================================================ Global operations
                BGEditorUtility.HorizontalBox(() =>
                {
                    BGEditorUtility.SwapLabelWidth(80, () => EditorGUILayout.LabelField("Selected (" + points.Count + ")"));

                    if (BGEditorUtility.ButtonWithIcon(deleteTexture, "Delete selected points"))
                    {
                        if (!DeleteSelected())
                        {
                            return;
                        }
                    }

                    GUILayout.Space(4);
                    if (BGEditorUtility.ButtonWithIcon(selectAllTexture, "Select all points", 35))
                    {
                        Changed = Changed || points.Count != curve.PointsCount;

                        points.Clear();

                        foreach (var point1 in curve.Points)
                        {
                            points.Add(point1);
                        }
                    }

                    GUILayout.Space(4);

                    if (BGEditorUtility.ButtonWithIcon(deselectAllTexture, "Deselect all points", 35))
                    {
                        Clear();
                    }
                });


                // ================================================ Selections operations
                // skip mouse buttons events which change selection
                if (Changed)
                {
                    return;
                }

                GUILayout.Space(5);
                if (HasSelected())
                {
                    BGEditorUtility.SwapGuiBackgroundColor(SelectedBackgroundColor, () =>
                    {
                        BGEditorUtility.VerticalBox(() =>
                        {
                            var averagePositionSelected = GetAveragePosition();

                            // =====================================================  Control handles
                            BGEditorUtility.Horizontal(() =>
                            {
                                controlType = (BGCurvePoint.ControlTypeEnum)EditorGUILayout.EnumPopup("Controls", controlType);
                                if (!BGEditorUtility.ButtonWithIcon(convertAll2D, "Set control type for all selected points", 44))
                                {
                                    return;
                                }

                                SetControlTypeForSelected(controlType);
                            });

                            // =====================================================  Average positions & delete
                            BGEditorUtility.Vector3Field("Average position", "Average points position. Change several points positions at once, keeping distance difference intact",
                                                         averagePositionSelected,
                                                         newAverage =>
                            {
                                var delta = newAverage - averagePositionSelected;
                                curve.Transaction(() => { foreach (var point in points)
                                                          {
                                                              point.PositionWorld += delta;
                                                          }
                                                  });
                            });
                            // =====================================================  Set position directly
                            BGEditorUtility.Vector3Field("Set position", "Set points position directly",
                                                         averagePositionSelected,
                                                         newPosition =>
                            {
                                curve.Transaction(() =>
                                {
                                    if (BGEditorUtility.AnyChange(averagePositionSelected.x, newPosition.x))
                                    {
                                        SetX(newPosition.x);
                                    }
                                    if (BGEditorUtility.AnyChange(averagePositionSelected.y, newPosition.y))
                                    {
                                        SetY(newPosition.y);
                                    }
                                    if (BGEditorUtility.AnyChange(averagePositionSelected.z, newPosition.z))
                                    {
                                        SetZ(newPosition.z);
                                    }
                                });
                            });

                            // =====================================================  Set control positions directly
                            var count = 0;
                            var averageControl1Sum = Vector3.zero;
                            var averageControl2Sum = Vector3.zero;
                            foreach (var point in points.Where(point => point.ControlType != BGCurvePoint.ControlTypeEnum.Absent))
                            {
                                count++;
                                averageControl1Sum += point.ControlFirstLocal;
                                averageControl2Sum += point.ControlSecondLocal;
                            }

                            if (count == 0)
                            {
                                return;
                            }

                            //has points with bezier controls
                            BGEditorUtility.Vector3Field("Set Control 1", "Set 1st control position directly",
                                                         averageControl1Sum / count,
                                                         newPosition =>
                            {
                                curve.Transaction(
                                    () => { foreach (var point in points.Where(point => point.ControlType != BGCurvePoint.ControlTypeEnum.Absent))
                                            {
                                                point.ControlFirstLocal = newPosition;
                                            }
                                    });
                            });

                            BGEditorUtility.Vector3Field("Set Control 2", "Set 2nd control position directly",
                                                         averageControl2Sum / count,
                                                         newPosition =>
                            {
                                curve.Transaction(
                                    () => { foreach (var point in points.Where(point => point.ControlType != BGCurvePoint.ControlTypeEnum.Absent))
                                            {
                                                point.ControlSecondLocal = newPosition;
                                            }
                                    });
                            });
                        });
                    });
                }
                else
                {
                    BGEditorUtility.HelpBox("Hold shift to use rectangular selection\r\nClick or click+drag over tick icons to (de)select points", MessageType.Info, curve.PointsCount > 0);
                }
            });
        }
Exemplo n.º 5
0
        public override void OnInspectorGUI()
        {
            serializedObject.Update();


            var componentChanged = BGEditorUtility.ChangeCheck(() =>
            {
                //custom fields
                InternalOnInspectorGUI();

                // -------------  parents
                if (parentClass != null)
                {
                    var possibleParents = cc.GetComponents(parentClass);
                    if (possibleParents.Length > 1)
                    {
                        BGEditorUtility.Horizontal(() =>
                        {
                            GUILayout.Space(10);
                            BGEditorUtility.VerticalBox(() =>
                            {
                                var myParent = cc.GetParent(parentClass);
                                var options  = new string[possibleParents.Length];
                                var index    = 0;
                                for (var i = 0; i < possibleParents.Length; i++)
                                {
                                    var possibleParent = possibleParents[i];
                                    if (possibleParent == myParent)
                                    {
                                        index = i;
                                    }
                                    options[i] = ((BGCc)possibleParent).CcName;
                                }

                                //show popup
                                var label    = BGCc.GetDescriptor(parentClass).Name ?? parentClass.Name;
                                var newIndex = EditorGUILayout.Popup(label, index, options);
                                if (newIndex != index)
                                {
                                    Undo.RecordObject(cc, "parent change");
                                    cc.SetParent((BGCc)possibleParents[newIndex]);
                                    if (ChangedParent != null)
                                    {
                                        ChangedParent(this, null);
                                    }
                                }
                            });
                        });
                    }
                }
            });


            //--------------  handles
            if (cc.SupportHandles && !BGCurveSettingsForEditor.CcInspectorHandlesOff && !cc.HideHandlesInInspector)
            {
                BGEditorUtility.Horizontal(() =>
                {
                    GUILayout.Space(10);
                    BGEditorUtility.VerticalBox(() =>
                    {
                        var showHandlesProperty = serializedObject.FindProperty("showHandles");
                        EditorGUILayout.PropertyField(showHandlesProperty);
                        if (cc.SupportHandlesSettings && showHandlesProperty.boolValue)
                        {
                            BGEditorUtility.Indent(1, ShowHandlesSettings);
                        }
                    });
                });
            }

            //--------------  status
            var info = cc.Info;

            BGEditorUtility.HelpBox(info, MessageType.Info, !string.IsNullOrEmpty(info));

            //--------------  warning
            var warning = cc.Warning;

            BGEditorUtility.HelpBox(warning, MessageType.Warning, !string.IsNullOrEmpty(warning));

            //--------------  error
            var error = cc.Error;

            BGEditorUtility.HelpBox(error, MessageType.Error, !string.IsNullOrEmpty(error));

            if (!GUI.changed)
            {
                return;
            }

            Undo.RecordObject(cc, "fields change");

            serializedObject.ApplyModifiedProperties();
            EditorUtility.SetDirty(cc);

            if (componentChanged)
            {
                cc.FireChangedParams();
            }

            InternalOnInspectorGUIPost();
        }
        public override void OnInspectorGui()
        {
            settings = SerializedObject.FindProperty("settings");
            var settingsObj = Settings;

            // Save & Load
            showSaveLoad = EditorGUILayout.Foldout(showSaveLoad, "Save and load settings");
            if (showSaveLoad)
            {
                BGEditorUtility.VerticalBox(() =>
                {
                    var path = BGCurveSettingsOperations.GetPath();

                    BGEditorUtility.HelpBox("Folder is not set", MessageType.Info, path == null, () =>
                    {
                        EditorGUILayout.LabelField("Folder", path);

                        BGEditorUtility.HelpBox("Folder is not found", MessageType.Warning, !BGCurveSettingsOperations.IsValid(path), () =>
                        {
                            // =================================  Load settings
                            var all = BGCurveSettingsOperations.GetAll();

                            BGEditorUtility.HelpBox("Folder does not have any settings", MessageType.Warning, all == null || all.Length == 0, () =>
                            {
                                BGEditorUtility.Horizontal(() =>
                                {
                                    var options = new List <GUIContent> {
                                        new GUIContent("")
                                    };
                                    options.AddRange(all.Select(setting => new GUIContent(setting)));
                                    var selected = EditorGUILayout.Popup(new GUIContent("Load", "Load a specified settings for current object"), 0, options.ToArray());
                                    if (selected > 0)
                                    {
                                        var newSettings = BGCurveSettingsOperations.Load(options[selected].text);
                                        if (newSettings != null)
                                        {
                                            BGPrivateField.SetSettings(Curve, newSettings);
                                            EditorUtility.SetDirty(Curve);
                                            lastOperation = options[selected].text + " was loaded";
                                        }
                                        else
                                        {
                                            lastOperation = "Unable to load a settings " + options[selected].text;
                                        }
                                    }

                                    if (GUILayout.Button(new GUIContent("Reload", "Reload settings from disk. This operation does not change settings for the curent object.")))
                                    {
                                        BGCurveSettingsOperations.Reload(BGCurveSettingsOperations.GetPath());
                                        lastOperation = "Settings was reloaded from disk";
                                    }
                                });
                            });

                            // =================================  Save settings
                            BGEditorUtility.Horizontal(() =>
                            {
                                newAssetName = EditorGUILayout.TextField(new GUIContent("Save", "Save current setting on disk"), newAssetName);
                                if (!GUILayout.Button(new GUIContent("Save", "Save current setting on disk")))
                                {
                                    return;
                                }

                                if (newAssetName == null || newAssetName.Trim().Equals(""))
                                {
                                    BGEditorUtility.Inform("Invalid asset name", "Please, enter the name for new asset");
                                }
                                else
                                {
                                    lastOperation = BGCurveSettingsOperations.Save(settingsObj, newAssetName) ? newAssetName + " was saved on disk" : "Unable to save " + newAssetName + " on disk";
                                }
                            });

                            BGEditorUtility.HelpBox(lastOperation, MessageType.Info, lastOperation != null);
                        });
                    });

                    BGEditorUtility.Horizontal(() =>
                    {
                        if (GUILayout.Button(new GUIContent("Save as default", "Save current settings as default for future curves")))
                        {
                            lastOperation = BGCurveSettingsOperations.SaveDefault(settingsObj) ? "Current settings was saved as default" : "Unable to save settings on disk as default";
                        }

                        if (GUILayout.Button(new GUIContent("Chose a folder", "Chose a folder where to store settings files")))
                        {
                            BGCurveSettingsOperations.ChoseDir();
                        }
                    });
                });
            }

            EditorGUILayout.HelpBox("All fields settings are under Fields tab", MessageType.Warning);

            BGEditorUtility.ChangeCheck(() =>
            {
                //Points
                BGEditorUtility.VerticalBox(() =>
                {
                    //Hide handles
                    EditorGUILayout.PropertyField(Find("hideHandles"));

                    EditorGUILayout.PropertyField(Find("newPointDistance"));
                    EditorGUILayout.PropertyField(Find("showPointMenu"));
                    EditorGUILayout.PropertyField(Find("restrictGizmoz"));
                    if (settingsObj.RestrictGizmozSettings.Valid && settingsObj.RestrictGizmozSettings.HasValue)
                    {
                        EditorGUILayout.HelpBox("Gizmos are shown for specified points only", MessageType.Warning);
                    }
                });

                var tangentProp = Find("showTangents");

                //curve
                BGEditorUtility.FadeGroup(showCurveProp, () =>
                {
//                    EditorGUILayout.PropertyField(Find("showCurveMode"));
                    EditorGUILayout.PropertyField(Find("showCurveOption"));
                    EditorGUILayout.PropertyField(Find("sections"));
                    EditorGUILayout.PropertyField(Find("vRay"));
                    EditorGUILayout.PropertyField(Find("lineColor"));

                    //tangents
                    BGEditorUtility.VerticalBox(() =>
                    {
                        EditorGUILayout.PropertyField(tangentProp);
                        if (settingsObj.ShowTangents)
                        {
                            BGEditorUtility.Indent(1, () =>
                            {
                                EditorGUILayout.PropertyField(Find("tangentsSize"));
                                EditorGUILayout.PropertyField(Find("tangentsPerSection"));
                                EditorGUILayout.PropertyField(Find("tangentsColor"));
                            });
                        }
                    });
                });
            }, () =>
            {
                //if any change
                SerializedObject.ApplyModifiedProperties();
                SceneView.RepaintAll();
            });
        }
        // ================================================================================ Inspector
        public override void OnInspectorGui()
        {
            BGEditorUtility.Assign(ref whiteTexture, () => BGEditorUtility.Texture1X1(Color.white));

            components = Curve.GetComponents <BGCc>();
            var length = components.Length;

            tree.Refresh(components);

            if (tree.InitException != null)
            {
                EditorGUILayout.HelpBox("There was an error initializing editors for component's Tree View: " + tree.InitException.Message +
                                        "\r\n\r\nYou still can use default Unity's editors for components below.", MessageType.Error);
                return;
            }


            var hasError   = HasError;
            var hasWarning = HasWarning;

            BGEditorUtility.HorizontalBox(() =>
            {
                EditorGUILayout.LabelField("Components: " + length + " (" + (hasError ? "Error" : "Ok") + ")");

                GUILayout.FlexibleSpace();

                // turn on/off handles
                var handlesOff = BGCurveSettingsForEditor.CcInspectorHandlesOff;
                if (BGEditorUtility.ButtonWithIcon(
                        handlesOff
                        ? BGBinaryResources.BGHandlesOff123
                        : BGBinaryResources.BGHandlesOn123,
                        "Turn on/off handles settings in Inspector"))
                {
                    BGCurveSettingsForEditor.CcInspectorHandlesOff = !BGCurveSettingsForEditor.CcInspectorHandlesOff;
                }
                EditorGUILayout.Separator();

                // turn on/off colored tree
                if (BGEditorUtility.ButtonWithIcon(customEditorsOn ? BGBinaryResources.BGOn123: BGBinaryResources.BGOff123, "Use custom UI for components (colored tree) and hide standard unity editors for components"))
                {
                    customEditorsOn = !customEditorsOn;
                    tree.Refresh(null, true);
                }
                EditorGUILayout.Separator();

                if (length > 0)
                {
                    // collapse/expand
                    if (BGEditorUtility.ButtonWithIcon(BGBinaryResources.BGCollapseAll123, "Collapse all components"))
                    {
                        tree.ExpandCollapseAll(true);
                    }
                    EditorGUILayout.Separator();
                    if (BGEditorUtility.ButtonWithIcon(BGBinaryResources.BGExpandAll123, "Expand all components"))
                    {
                        tree.ExpandCollapseAll(false);
                    }
                    EditorGUILayout.Separator();


                    // delete all Ccs
                    if (BGEditorUtility.ButtonWithIcon(BGBinaryResources.BGDelete123, "Delete all components") &&
                        BGEditorUtility.Confirm("Delete", "Are you sure you want to delete " + length + " component(s)?", "Delete"))
                    {
                        tree.Delete();
                    }
                    EditorGUILayout.Separator();
                }

                //add new Cc
                if (BGEditorUtility.ButtonWithIcon(BGBinaryResources.BGAdd123, "Add new component"))
                {
                    BGCcAddWindow.Open(Curve, type => AddComponent(Curve, type));
                }
            });


            if (length > 0)
            {
                // warnings/errors
                if (hasWarning || hasError)
                {
                    for (var i = 0; i < components.Length; i++)
                    {
                        var component = components[i];

                        var name = (component.Descriptor != null ? component.Descriptor.Name + " " : "") + component.CcName;

                        var error = component.Error;
                        if (!string.IsNullOrEmpty(error))
                        {
                            BGEditorUtility.HelpBox("Component error [" + name + "]: " + error, MessageType.Error);
                        }

                        var warning = component.Warning;
                        if (!string.IsNullOrEmpty(warning))
                        {
                            BGEditorUtility.HelpBox("Component warning [" + name + "]: " + warning, MessageType.Warning);
                        }
                    }
                }
                else
                {
                    BGEditorUtility.HelpBox("No warnings or errors", MessageType.Info);
                }

                // tree GUI
                tree.OnInspectorGui();
            }
            else
            {
                EditorGUILayout.HelpBox(
                    "Hit the Plus icon to add a component"
                    + "\r\n"
                    + "\r\n"
                    + "Components allows to add functionality without any scripting."
                    , MessageType.Info);
            }


            if (hasError ^ HasError || hasWarning ^ HasWarning)
            {
                EditorApplication.RepaintHierarchyWindow();
            }
        }
Exemplo n.º 8
0
        public override void OnInspectorGUI()
        {
            //adjust math if needed
            AdjustMath(BGPrivateField.GetSettings(Curve), Math);

            //styles
            BGEditorUtility.Assign(ref stickerStyle, () => new GUIStyle("Label")
            {
                fontSize = 18, alignment = TextAnchor.MiddleCenter, normal = new GUIStyleState {
                    textColor = Color.white
                }
            });
            BGEditorUtility.Assign(ref settingsTexture, () => BGEditorUtility.LoadTexture2D(BGEditorUtility.Image.BGSettingsIcon123));

            serializedObject.Update();

            // =========== Header
            DrawLogo();

            // =========== lock view
            BGEditorUtility.Horizontal(() =>
            {
                var temp = BGCurveSettingsForEditor.LockView;
                BGCurveSettingsForEditor.LockView = BGEditorUtility.ButtonOnOff(ref temp, "Lock view", "Disable selection of other objects in the scene", LockViewActiveColor,
                                                                                new GUIContent("Turn Off", "Click to turn this mode off"),
                                                                                new GUIContent("Turn On", "Click to turn this mode on"));

                if (BGEditorUtility.ButtonWithIcon(settingsTexture, "Open BGCurve Editor Settings", 24, 24))
                {
                    BGCurveSettingsForEditorWindow.Open();
                }
            });

            //warning
            BGEditorUtility.HelpBox("You can not chose another objects in the scene, except points.\r\n Use rectangular selection without pressing shift", MessageType.Warning,
                                    BGCurveSettingsForEditor.LockView, () => GUILayout.Space(8));

            // =========== Tabs
            if (BGCurveSettingsForEditor.CurrentTab < 0 || BGCurveSettingsForEditor.CurrentTab > headers.Length - 1)
            {
                BGCurveSettingsForEditor.CurrentTab = 0;
            }
            BGCurveSettingsForEditor.CurrentTab = GUILayout.Toolbar(BGCurveSettingsForEditor.CurrentTab, headers, GUILayout.Height(ToolBarHeight));
            //do not move this method(GUILayoutUtility.GetLastRect() is used)
            ShowStickers();
            editors[BGCurveSettingsForEditor.CurrentTab].OnInspectorGui();


            if (!GUI.changed)
            {
                return;               // if no change- return
            }
            foreach (var editor in editors)
            {
                editor.OnBeforeApply();
            }

            serializedObject.ApplyModifiedProperties();
            EditorUtility.SetDirty(Curve);

            foreach (var editor in editors)
            {
                editor.OnApply();
            }

            transformMonitor.Check();
        }
Exemplo n.º 9
0
        // ================================================================================ Inspector
        public override void OnInspectorGui()
        {
            var settings = BGPrivateField.GetSettings(Curve);

            BGEditorUtility.HelpBox("Curve UI is disabled in settings. All handles are disabled too.", MessageType.Warning, !settings.ShowCurve);

            // Custom fields
            var warning = "";

            BGEditorUtility.Assign(ref customUi, () => new BGTableView("Custom fields", new[] { "#", "Name", "Type", "?", "Delete" }, new[] { 5, 40, 40, 5, 10 }, () =>
            {
                //add row
                customUi.NextColumn(rect => EditorGUI.LabelField(rect, "Name"), 12);
                customUi.NextColumn(rect => newFieldName = EditorGUI.TextField(rect, newFieldName), 28);
                customUi.NextColumn(rect => BGEditorUtility.PopupField(rect, newFieldType, @enum => newFieldType = (BGCurvePointField.TypeEnum)@enum), 50);
                customUi.NextColumn(rect =>
                {
                    if (!GUI.Button(rect, BGBinaryResources.BGAdd123))
                    {
                        return;
                    }

                    if (NameHasError(Curve, newFieldName))
                    {
                        return;
                    }

                    BGPrivateField.Invoke(Curve, BGCurve.MethodAddField, newFieldName, newFieldType, (Func <BGCurvePointField>)(() => Undo.AddComponent <BGCurvePointField>(Curve.gameObject)));
                    GUIUtility.hotControl = 0;
                    GUIUtility.ExitGUI();
                }, 10);

                customUi.NextRow();

                if (customFields == null || customFields.Length == 0)
                {
                    customUi.NextRow("Name should be 16 chars max, starts with a letter and contain English chars and numbers only.");
                }
                else
                {
                    //header
                    customUi.DrawHeaders();

                    //fields
                    var quaternionWithHandlesCount = 0;

                    BGEditorUtility.ChangeCheck(() =>
                    {
                        foreach (var customField in customFields)
                        {
                            if (customField.Field.Type == BGCurvePointField.TypeEnum.Quaternion && BGPrivateField.GetHandlesType(customField.Field) != 0)
                            {
                                quaternionWithHandlesCount++;
                            }
                            customField.Ui(customUi);
                        }
                    }, SceneView.RepaintAll);

                    if (quaternionWithHandlesCount > 1)
                    {
                        warning = "You have more than one Quaternion field with Handles enabled. Only first field will be shown in Scene View";
                    }
                    //footer
                    customUi.NextRow("?- Show in Points Menu/Scene View");
                }
            }));

            // System fields
            BGEditorUtility.Assign(ref systemUi, () => new BGTableView("System fields", new[] { "Name", "Value" }, new[] { LabelWidth, 100 - LabelWidth }, () =>
            {
                BGEditorUtility.ChangeCheck(() =>
                {
                    foreach (var field in systemFields)
                    {
                        field.Ui(systemUi);
                    }
                }, SceneView.RepaintAll);
            }));

            BGEditorUtility.Assign(ref systemFields, () => new[]
            {
                (SystemField) new SystemFieldPosition(settings),
                new SystemFieldControls(settings),
                new SystemFieldControlsType(settings),
                new SystemFieldTransform(settings),
            });

            var fields    = Curve.Fields;
            var hasFields = fields != null && fields.Length > 0;

            if (hasFields && (customFields == null || customFields.Length != fields.Length) || !hasFields && customFields != null && customFields.Length != fields.Length)
            {
                customFields = new PointField[fields.Length];

                for (var i = 0; i < fields.Length; i++)
                {
                    customFields[i] = new PointField(fields[i], i, BGBinaryResources.BGDelete123);
                }
            }


            //warnings
            BGEditorUtility.HelpBox("All handles for positions are disabled.", MessageType.Warning, settings.HandlesSettings.Disabled);
            BGEditorUtility.HelpBox("All handles for controls are disabled.", MessageType.Warning, settings.ControlHandlesSettings.Disabled);

            //====================== Custom fields
            customUi.OnGui();

            //warnings
            BGEditorUtility.HelpBox(warning, MessageType.Warning, warning.Length > 0);

            //====================== System fields
            systemUi.OnGui();
            GUILayout.Space(4);
        }