예제 #1
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();
        }
                private void HeaderUi(int level, bool hasError)
                {
                    var color = MyTree.GetColor(level, Collapsed, () => new Color(0, 0, 0, 0));

                    BGEditorUtility.SwapGuiBackgroundColor(color, () =>
                    {
                        BGEditorUtility.Horizontal(headerBoxStyle, () =>
                        {
                            BGEditorUtility.Indent(1, () =>
                            {
                                var content = new GUIContent(descriptor == null ? Cc.GetType().Name : descriptor.Name + " (" + BGEditorUtility.Trim(Cc.CcName, 10) + ")",
                                                             descriptor == null ? null : descriptor.Description);
                                var width = headerFoldoutStyle.CalcSize(content).x + 16;

                                BGEditorUtility.SwapLabelWidth((int)width, () =>
                                {
                                    //foldout (we dont use layout version cause it does not support clickin on labels)
                                    Collapsed = EditorGUI.Foldout(
                                        GUILayoutUtility.GetRect(width, 16f),
                                        Collapsed,
                                        content,
                                        true,
                                        Cc.enabled ? headerFoldoutStyle : headerFoldoutStyleDisabled);
                                });
                            });

                            GUILayout.FlexibleSpace();

                            // status(error or Ok)
                            EditorGUI.LabelField(GUILayoutUtility.GetRect(70, 16, EditorStyles.label), hasError ? "Error" : "Ok.", hasError ? errorStyle : okStyle);


                            //help url
                            if (!String.IsNullOrEmpty(Cc.HelpURL))
                            {
                                if (BGEditorUtility.ButtonWithIcon(BGBinaryResources.BGHelp123, "Open help in the browser"))
                                {
                                    Application.OpenURL(Cc.HelpURL);
                                }
                                EditorGUILayout.Separator();
                            }

                            //change visibility
                            if (BGEditorUtility.ButtonWithIcon(Cc.Hidden ? BGBinaryResources.BGHiddenOn123 : BGBinaryResources.BGHiddenOff123, "Hide/Show properties"))
                            {
                                Cc.Hidden = !Cc.Hidden;
                            }
                            EditorGUILayout.Separator();

                            //change name
                            if (BGEditorUtility.ButtonWithIcon(BGBinaryResources.BGCcEditName123, "Change the name"))
                            {
                                BGCcChangeNameWindow.Open(Cc);
                            }
                            EditorGUILayout.Separator();

                            //add a child
                            if (BGEditorUtility.ButtonWithIcon(BGBinaryResources.BGAdd123, "Add a component, which is dependant on this component"))
                            {
                                BGCcAddWindow.Open(MyTree.Curve, type =>
                                {
                                    //cache some data
                                    var gameObject    = Cc.Curve.gameObject;
                                    var oldComponents = gameObject.GetComponents <BGCc>();
                                    var currentCcType = Cc.GetType();

                                    //add
                                    var addedCc = AddComponent(MyTree.Curve, type);
                                    if (addedCc == null)
                                    {
                                        return;
                                    }

                                    //we need to process all the way up to the Cc and link Ccs to right (newly created) parents
                                    var parentClass    = addedCc.GetParentClass();
                                    var recursionLimit = 16;
                                    var cc             = addedCc;
                                    while (parentClass != null && recursionLimit-- > 0)
                                    {
                                        if (currentCcType == parentClass)
                                        {
                                            //we reached the current Cc
                                            cc.SetParent(Cc);
                                            break;
                                        }

                                        //going up
                                        var possibleParents = gameObject.GetComponents(parentClass);
                                        var parent          = possibleParents.Where(possibleParent => !oldComponents.Contains(possibleParent)).Cast <BGCc>().FirstOrDefault();

                                        if (parent == null)
                                        {
                                            break;
                                        }

                                        cc.SetParent(parent);
                                        cc          = parent;
                                        parentClass = cc.GetParentClass();
                                    }
                                }, Cc.GetType());
                            }
                            EditorGUILayout.Separator();


                            //enable/disable
                            if (BGEditorUtility.ButtonWithIcon(Cc.enabled ? BGBinaryResources.BGTickYes123 : BGBinaryResources.BGTickNo123, "Enable/disable a component"))
                            {
                                Enable(!Cc.enabled);
                            }
                            EditorGUILayout.Separator();

                            //delete
                            if (!BGEditorUtility.ButtonWithIcon(BGBinaryResources.BGDelete123, "Remove this component"))
                            {
                                return;
                            }


                            //remove
                            Delete();

                            EditorUtility.SetDirty(MyTree.Curve.gameObject);

                            //not sure how to make proper exit
                            throw new BGEditorUtility.ExitException();
                        });
                    });
                }
        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();
            });
        }
예제 #4
0
                private void HeaderUi(int level, bool hasError)
                {
                    var color = MyTree.GetColor(level, Collapsed, () => new Color(0, 0, 0, 0));

                    BGEditorUtility.SwapGuiBackgroundColor(color, () =>
                    {
                        BGEditorUtility.Horizontal(headerBoxStyle, () =>
                        {
                            BGEditorUtility.Indent(1, () =>
                            {
                                var content = new GUIContent(descriptor == null ? Cc.GetType().Name : descriptor.Name + " (" + BGEditorUtility.Trim(Cc.CcName, 10) + ")",
                                                             descriptor == null ? null : descriptor.Description);
                                var width = headerFoldoutStyle.CalcSize(content).x + 16;

                                BGEditorUtility.SwapLabelWidth((int)width, () =>
                                {
                                    //foldout (we dont use layout version cause it does not support clickin on labels)
                                    Collapsed = EditorGUI.Foldout(
                                        GUILayoutUtility.GetRect(width, 16f),
                                        Collapsed,
                                        content,
                                        true,
                                        Cc.enabled ? headerFoldoutStyle : headerFoldoutStyleDisabled);
                                });
                            });

                            GUILayout.FlexibleSpace();

                            // status(error or Ok)
                            EditorGUI.LabelField(GUILayoutUtility.GetRect(70, 16, EditorStyles.label), hasError ? "Error" : "Ok.", hasError ? errorStyle : okStyle);


                            //help url
                            if (!String.IsNullOrEmpty(Cc.HelpURL))
                            {
                                if (BGEditorUtility.ButtonWithIcon(helpTexture, "Open help in the browser"))
                                {
                                    Application.OpenURL(Cc.HelpURL);
                                }
                                EditorGUILayout.Separator();
                            }

                            //change name
                            if (BGEditorUtility.ButtonWithIcon(changeNameTexture, "Change the name"))
                            {
                                BGCcChangeNameWindow.Open(Cc);
                            }
                            EditorGUILayout.Separator();

                            //add child
                            if (BGEditorUtility.ButtonWithIcon(addTexture, "Add a component, which is dependant on this component"))
                            {
                                BGCcAddWindow.Open(MyTree.Curve, type =>
                                {
                                    var bgCc = AddComponent(MyTree.Curve, type);
                                    bgCc.SetParent(Cc);
                                }, Cc.GetType());
                            }
                            EditorGUILayout.Separator();


                            //enable/disable
                            if (BGEditorUtility.ButtonWithIcon(Cc.enabled ? enabledTexture : disabledTexture, "Enable/disable a component"))
                            {
                                Enable(!Cc.enabled);
                            }
                            EditorGUILayout.Separator();

                            //delete
                            if (!BGEditorUtility.ButtonWithIcon(deleteTexture, "Remove this component"))
                            {
                                return;
                            }


                            //remove
                            Delete();

                            EditorUtility.SetDirty(MyTree.Curve.gameObject);

                            //not sure how to make proper exit
                            throw new ExitException();
                        });
                    });
                }