protected override void InternalOnInspectorGUI()
        {
            if (!listenersAdded)
            {
                InternalOnEnable();
            }

            paramsChanged = false;
            BGEditorUtility.ChangeCheck(() =>
            {
                BGEditorUtility.VerticalBox(() =>
                {
                    EditorGUILayout.PropertyField(serializedObject.FindProperty("splitMode"));

                    switch (Splitter.SplitMode)
                    {
                    case BGCcSplitterPolyline.SplitModeEnum.PartsTotal:
                        EditorGUILayout.PropertyField(serializedObject.FindProperty("partsTotal"));
                        break;

                    case BGCcSplitterPolyline.SplitModeEnum.PartsPerSection:
                        EditorGUILayout.PropertyField(serializedObject.FindProperty("partsPerSection"));
                        break;
                    }
                });

                EditorGUILayout.PropertyField(serializedObject.FindProperty("doNotOptimizeStraightLines"));

                AdditionalParams();
            }, () => paramsChanged = true);
        }
Exemplo n.º 2
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();
            });
        }
Exemplo n.º 4
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);
        }