Ejemplo n.º 1
0
                internal CcNode(Tree tree, BGCc cc) : base(tree)
                {
                    Cc         = cc;
                    descriptor = cc.Descriptor;

                    var editor = UnityEditor.Editor.CreateEditor(cc);

                    if (!(editor is BGCcEditor))
                    {
                        throw new BGCc.CcException("Unable to init an Editor for " + cc.GetType() + ": editor does not extend from BGCcEditor.");
                    }

                    ccEditor = (BGCcEditor)editor;
                    ccEditor.ChangedParent += ChangedParent;
//                    UnityEditor.Editor.CreateCachedEditor(cc, null, ref ccEditor);

                    onSceneGuiMethod = ccEditor.GetType().GetMethod("OnSceneGUI", BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Instance);

                    enabledTexture    = BGEditorUtility.LoadTexture2D(BGEditorUtility.Image.BGTickYes123);
                    disabledTexture   = BGEditorUtility.LoadTexture2D(BGEditorUtility.Image.BGTickNo123);
                    helpTexture       = BGEditorUtility.LoadTexture2D(BGEditorUtility.Image.BGHelp123);
                    deleteTexture     = BGEditorUtility.LoadTexture2D(BGEditorUtility.Image.BGDelete123);
                    addTexture        = BGEditorUtility.LoadTexture2D(BGEditorUtility.Image.BGAdd123);
                    changeNameTexture = BGEditorUtility.LoadTexture2D(BGEditorUtility.Image.BGCcEditName123);

                    parentType = cc.GetParentClass();
                }
Ejemplo n.º 2
0
            public Tree(BGCurve curve, Type dependsOnType)
                : base(new Config(0, (int)(IconSize * .9f), (int)(IconSize * .5f), 2, 16))
            {
                Curve         = curve;
                DependsOnType = dependsOnType;

                //-------------  load all BGCc subclasses
                var typesList = GetAllSubTypes(typeof(BGCc));

                foreach (var node in from type in typesList
                         let descriptor = BGCc.GetDescriptor(type)
                                          let single = BGCc.IsSingle(type)
                                                       select new CcNode(this, descriptor != null ? new CcData(type, single, descriptor) : new CcData(type, single, type.Name)))
                {
                    try
                    {
                        node.CcData.ParentType = BGCc.GetParentClass(node.CcData.Type);
                    }
                    catch (Exception e)
                    {
                        Debug.LogException(e);
                        continue;
                    }
                    type2Node[node.CcData.Type] = node;
                }

                foreach (var node in type2Node.Values)
                {
                    if (!node.Processed)
                    {
                        node.ProcessStructure();
                    }
                }
            }
Ejemplo n.º 3
0
        internal static void Open(BGCc current)
        {
            BGCcChangeNameWindow.current = current;

            ccName = current.CcName;

            instance = BGEditorUtility.ShowPopupWindow <BGCcChangeNameWindow>(WindowSize);
        }
Ejemplo n.º 4
0
        internal static void Open(BGCc current, Component[] availableList, Action <BGCc> action)
        {
            BGCcChoseWindow.action        = action;
            BGCcChoseWindow.current       = current;
            BGCcChoseWindow.availableList = availableList;

            instance = BGEditorUtility.ShowPopupWindow <BGCcChoseWindow>(WindowSize);
        }
                internal CcNode(Tree tree, BGCc cc) : base(tree)
                {
                    Cc         = cc;
                    descriptor = cc.Descriptor;

                    var editor = UnityEditor.Editor.CreateEditor(cc);

                    if (!(editor is BGCcEditor))
                    {
                        throw new BGCc.CcException("Unable to init an Editor for " + cc.GetType() + ": editor does not extend from BGCcEditor.");
                    }

                    ccEditor = (BGCcEditor)editor;
                    ccEditor.ChangedParent += ChangedParent;
//                    UnityEditor.Editor.CreateCachedEditor(cc, null, ref ccEditor);

                    onSceneGuiMethod = ccEditor.GetType().GetMethod("OnSceneGUI", BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Instance);

                    parentType = cc.GetParentClass();
                }
Ejemplo n.º 6
0
        //=================================================================  Unity callbacks
        public virtual void OnEnable()
        {
            cc = (BGCc)target;

            if (cc == null)
            {
                return;
            }

            //get all required components
            parentClass = cc.GetParentClass();


            InternalOnEnable();

            cc.ChangedParams -= ChangedParams;
            cc.ChangedParams += ChangedParams;

            Undo.undoRedoPerformed -= InternalOnUndoRedo;
            Undo.undoRedoPerformed += InternalOnUndoRedo;
        }
Ejemplo n.º 7
0
        public BGCcTreeView(BGCurve curve, Type dependsOnType, bool ignoreExcludeFromMenuAttribute, Action <string> messageAction, Action <Type> typeWasChosenAction)
            : base(new Config(0, (int)(IconSize * .9f), (int)(IconSize * .5f), 2, 16))
        {
            Curve              = curve;
            DependsOnType      = dependsOnType;
            this.messageAction = messageAction;

            noImage = BGEditorUtility.LoadTexture2D(BGEditorUtility.Image.BGCcNoImage123);


            //-------------  load all BGCc subclasses
            var typesList = GetAllSubTypes(typeof(BGCc), ignoreExcludeFromMenuAttribute ? null : typeof(BGCc.CcExcludeFromMenu));

            foreach (var node in from type in typesList
                     let descriptor = BGCc.GetDescriptor(type)
                                      let single = BGCc.IsSingle(type)
                                                   select new CcNode(this, descriptor != null ? new CcData(type, single, descriptor) : new CcData(type, single, type.Name), typeWasChosenAction))
            {
                try
                {
                    node.CcData.ParentType = BGCc.GetParentClass(node.CcData.Type);
                }
                catch (Exception e)
                {
                    Debug.LogException(e);
                    continue;
                }
                type2Node[node.CcData.Type] = node;
            }

            foreach (var node in type2Node.Values)
            {
                if (!node.Processed)
                {
                    node.ProcessStructure();
                }
            }
        }
Ejemplo n.º 8
0
        //--------------------------------------- Cc
        public static bool GetShowHandles(BGCc cc)
        {
            return(cc.ShowHandles);
//            return Get<bool>(cc, "showHandles");
        }
Ejemplo n.º 9
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();
        }
Ejemplo n.º 10
0
            public CcNode Get(BGCc cc)
            {
                var nodes = type2NodeList[cc.GetType()];

                return(nodes.FirstOrDefault(node => node.Cc == cc));
            }
Ejemplo n.º 11
0
 //--------------------------------------- Cc
 public static bool GetShowHandles(BGCc cc)
 {
     return(Get <bool>(cc, "showHandles"));
 }