Пример #1
0
        public override void OnInspectorGUI()
        {
            this.serializedObject.Update();

            GUILayoutExt.DrawComponentHeader(this.serializedObject, "M", () => {
                GUILayoutExt.DrawComponentHeaderItem("State", GUILayoutExt.GetPropertyToString(this.objectState));
            }, new Color(1f, 0.6f, 1f, 0.4f));

            GUILayout.Space(5f);

            var scroll = this.tabScrollPosition;

            this.selectedTab = GUILayoutExt.DrawTabs(
                this.selectedTab,
                ref scroll,
                new GUITab("Basic", () => {
                GUILayoutExt.DrawHeader("Main");
                EditorGUILayout.PropertyField(this.hiddenByDefault);
                EditorGUILayout.PropertyField(this.animationParameters);
                EditorGUILayout.PropertyField(this.subObjects);

                GUILayoutExt.DrawHeader("Performance Options");
                EditorGUILayout.PropertyField(this.createPool);
            }),
                new GUITab("Advanced", () => {
                GUILayoutExt.DrawHeader("Render Behaviour");
                EditorGUILayout.PropertyField(this.renderBehaviourOnHidden);

                GUILayoutExt.DrawHeader("Animation");
                EditorGUILayout.PropertyField(this.animationParameters);

                GUILayoutExt.DrawHeader("Graph");
                EditorGUILayout.PropertyField(this.allowRegisterInRoot);
                EditorGUILayout.PropertyField(this.autoRegisterSubObjects);
                EditorGUILayout.PropertyField(this.hiddenByDefault);
                EditorGUILayout.PropertyField(this.subObjects);

                GUILayoutExt.DrawHeader("Performance Options");
                EditorGUILayout.PropertyField(this.createPool);
            })
                );
            this.tabScrollPosition = scroll;

            GUILayout.Space(10f);

            var iter = this.serializedObject.GetIterator();

            iter.NextVisible(true);
            do
            {
                if (EditorHelpers.IsFieldOfTypeBeneath(this.serializedObject.targetObject.GetType(), typeof(WindowModule), iter.propertyPath) == true)
                {
                    EditorGUILayout.PropertyField(iter);
                }
            } while (iter.NextVisible(false) == true);

            this.serializedObject.ApplyModifiedProperties();
        }
        public override void OnInspectorGUI()
        {
            this.serializedObject.Update();

            GUILayoutExt.DrawComponentHeader(this.serializedObject, "S", () => {
                GUILayoutExt.DrawComponentHeaderItem("State", GUILayoutExt.GetPropertyToString(this.objectState));
                GUILayoutExt.DrawComponentHeaderItem("Focus", GUILayoutExt.GetPropertyToString(this.focusState));

                GUILayout.FlexibleSpace();
            }, new Color(0f, 0.6f, 0f, 0.4f));

            GUILayout.Space(5f);

            var scroll = this.tabScrollPosition;

            this.selectedTab = GUILayoutExt.DrawTabs(
                this.selectedTab,
                ref scroll,
                new GUITab("Preferences", () => {
                GUILayoutExt.DrawProperty(this.preferences);
                EditorGUILayout.PropertyField(this.createPool);
            }),
                new GUITab("Modules (" + this.listModules.count.ToString() + ")", () => {
                this.listModules.DoLayoutList();
            }),
                new GUITab("Layouts", () => {
                EditorGUILayout.PropertyField(this.layouts);
            }),
                new GUITab("Audio", () => {
                GUILayoutExt.DrawHeader("Events");
                var enterChildren = true;
                var prop          = this.audioEvents.Copy();
                var depth         = prop.depth + 1;
                while (prop.NextVisible(enterChildren) == true && prop.depth >= depth)
                {
                    EditorGUILayout.PropertyField(prop, true);
                    enterChildren = false;
                }
            })
                );
            this.tabScrollPosition = scroll;

            GUILayout.Space(10f);

            var iter = this.serializedObject.GetIterator();

            iter.NextVisible(true);
            do
            {
                if (EditorHelpers.IsFieldOfTypeBeneath(this.serializedObject.targetObject.GetType(), typeof(UnityEngine.UI.Windows.WindowTypes.LayoutWindowType), iter.propertyPath) == true)
                {
                    EditorGUILayout.PropertyField(iter);
                }
            } while (iter.NextVisible(false) == true);

            this.serializedObject.ApplyModifiedProperties();
        }
        public override void OnInspectorGUI()
        {
            this.serializedObject.Update();

            GUILayoutExt.DrawComponentHeader(this.serializedObject, "L", () => {
                GUILayoutExt.DrawComponentHeaderItem("State", GUILayoutExt.GetPropertyToString(this.objectState));
            }, new Color(1f, 0.6f, 0f, 0.4f));

            GUILayout.Space(5f);

            var scroll = this.tabScrollPosition;

            this.selectedTab = GUILayoutExt.DrawTabs(
                this.selectedTab,
                ref scroll,
                new GUITab("Basic", () => {
                GUILayoutExt.DrawHeader("Main");
                EditorGUILayout.PropertyField(this.hiddenByDefault);
                EditorGUILayout.PropertyField(this.animationParameters);
                EditorGUILayout.PropertyField(this.subObjects);

                GUILayoutExt.DrawHeader("Performance Options");
                EditorGUILayout.PropertyField(this.createPool);
            }),
                new GUITab("Advanced", () => {
                GUILayoutExt.DrawHeader("Render Behaviour");
                EditorGUILayout.PropertyField(this.renderBehaviourOnHidden);

                GUILayoutExt.DrawHeader("Animation");
                EditorGUILayout.PropertyField(this.animationParameters);

                GUILayoutExt.DrawHeader("Graph");
                EditorGUILayout.PropertyField(this.allowRegisterInRoot);
                EditorGUILayout.PropertyField(this.autoRegisterSubObjects);
                EditorGUILayout.PropertyField(this.hiddenByDefault);
                EditorGUILayout.PropertyField(this.subObjects);

                GUILayoutExt.DrawHeader("Performance Options");
                EditorGUILayout.PropertyField(this.createPool);
            })
                );
            this.tabScrollPosition = scroll;

            GUILayout.Space(10f);

            EditorGUILayout.PropertyField(this.useSafeZone);
            if (this.useSafeZone.boolValue == true)
            {
                GUILayoutExt.Box(2f, 2f, () => {
                    EditorGUILayout.PropertyField(this.safeZone);
                    if (this.safeZone.objectReferenceValue == null && this.targets.Length == 1)
                    {
                        GUILayout.BeginHorizontal();
                        GUILayout.FlexibleSpace();
                        if (GUILayout.Button("Generate", GUILayout.Width(80f), GUILayout.Height(30f)) == true)
                        {
                            var obj = this.target as Component;
                            if (PrefabUtility.IsPartOfAnyPrefab(obj) == true)
                            {
                                var path = AssetDatabase.GetAssetPath(obj.gameObject);
                                using (var edit = new EditPrefabAssetScope(path)) {
                                    EditorHelpers.AddSafeZone(edit.prefabRoot.transform);
                                }
                            }
                            else
                            {
                                var root = obj.gameObject;
                                EditorHelpers.AddSafeZone(root.transform);
                            }
                        }
                        GUILayout.FlexibleSpace();
                        GUILayout.EndHorizontal();
                    }
                });
            }

            GUILayout.Space(10f);

            var iter = this.serializedObject.GetIterator();

            iter.NextVisible(true);
            do
            {
                if (EditorHelpers.IsFieldOfTypeBeneath(this.serializedObject.targetObject.GetType(), typeof(WindowLayout), iter.propertyPath) == true)
                {
                    EditorGUILayout.PropertyField(iter);
                }
            } while (iter.NextVisible(false) == true);

            this.serializedObject.ApplyModifiedProperties();
        }
        public virtual void OnEnable()
        {
            try {
                #pragma warning disable
                var _ = this.serializedObject;
                #pragma warning restore
            } catch (System.Exception) {
                return;
            }

            this.createPool = this.serializedObject.FindProperty("createPool");

            this.objectState             = this.serializedObject.FindProperty("objectState");
            this.animationParameters     = this.serializedObject.FindProperty("animationParameters");
            this.renderBehaviourOnHidden = this.serializedObject.FindProperty("renderBehaviourOnHidden");

            this.subObjects       = this.serializedObject.FindProperty("subObjects");
            this.componentModules = this.serializedObject.FindProperty("componentModules");

            this.allowRegisterInRoot    = this.serializedObject.FindProperty("allowRegisterInRoot");
            this.autoRegisterSubObjects = this.serializedObject.FindProperty("autoRegisterSubObjects");
            this.hiddenByDefault        = this.serializedObject.FindProperty("hiddenByDefault");

            if (this.listModules == null)
            {
                var componentsProp = this.componentModules.FindPropertyRelative("modules");
                //if (componentsProp.arraySize != 0) {

                this.serializedObject.Update();
                this.componentModules.FindPropertyRelative("windowComponent").objectReferenceValue = this.componentModules.serializedObject.targetObject;
                this.serializedObject.ApplyModifiedProperties();
                this.listModules = new UnityEditorInternal.ReorderableList(componentsProp.serializedObject, componentsProp, true, true, true, true);
                this.listModules.elementHeight = 40f;
                this.listModules.onAddCallback = (rList) => {
                    if (rList.serializedProperty != null)
                    {
                        ++rList.serializedProperty.arraySize;
                        rList.index = rList.serializedProperty.arraySize - 1;
                        var idx  = rList.index;
                        var prop = componentsProp.GetArrayElementAtIndex(idx);
                        prop.objectReferenceValue = null;
                    }
                };
                this.listModules.onRemoveCallback = (rList) => {
                    var idx  = this.listModules.index;
                    var prop = componentsProp.GetArrayElementAtIndex(idx);
                    if (prop.objectReferenceValue != null)
                    {
                        Object.DestroyImmediate(prop.objectReferenceValue, true);
                    }
                    componentsProp.DeleteArrayElementAtIndex(idx);
                };
                this.listModules.drawElementBackgroundCallback = (rect, index, active, focused) => {
                    if (focused == true || active == true)
                    {
                        GUILayoutExt.DrawRect(rect, new Color(0.1f, 0.4f, 0.7f, 1f));
                    }
                    else
                    {
                        GUILayoutExt.DrawRect(rect, new Color(1f, 1f, 1f, index % 2 == 0 ? 0.05f : 0f));
                    }
                };
                this.listModules.elementHeightCallback = (index) => {
                    var prop = componentsProp.GetArrayElementAtIndex(index);
                    if (prop.objectReferenceValue != null)
                    {
                        var height   = 0f;
                        var so       = new SerializedObject(prop.objectReferenceValue);
                        var iterator = so.GetIterator();
                        iterator.NextVisible(true);

                        while (true)
                        {
                            if (EditorHelpers.IsFieldOfTypeBeneath(prop.objectReferenceValue.GetType(), typeof(WindowComponentModule), iterator.propertyPath) == true)
                            {
                                height += EditorGUI.GetPropertyHeight(iterator, new GUIContent(iterator.displayName), false);
                            }

                            if (!iterator.NextVisible(iterator.isExpanded))
                            {
                                break;
                            }
                        }

                        return(40f + height);
                    }

                    return(40f);
                };
                this.listModules.drawElementCallback = (rect, index, active, focused) => {
                    var padding = 10f;
                    rect.x     += padding;
                    rect.y     += padding;
                    rect.width -= padding * 2f;
                    rect.height = 18f;
                    EditorGUI.PropertyField(rect, componentsProp.GetArrayElementAtIndex(index), new GUIContent("Module"));
                    rect.y += 18f;
                    rect.y += padding;

                    var prop = componentsProp.GetArrayElementAtIndex(index);
                    if (prop.objectReferenceValue != null)
                    {
                        var so = new SerializedObject(prop.objectReferenceValue);
                        so.Update();

                        so.FindProperty("windowComponent").objectReferenceValue = this.serializedObject.targetObject;

                        var iterator = so.GetIterator();
                        iterator.NextVisible(true);

                        EditorGUI.indentLevel += 1;
                        int indent = EditorGUI.indentLevel;
                        while (true)
                        {
                            if (EditorHelpers.IsFieldOfTypeBeneath(prop.objectReferenceValue.GetType(), typeof(WindowComponentModule), iterator.propertyPath) == true)
                            {
                                rect.height = EditorGUI.GetPropertyHeight(iterator, new GUIContent(iterator.displayName), false);

                                //totalHeight += rect.height;
                                EditorGUI.indentLevel = indent + iterator.depth;
                                EditorGUI.PropertyField(rect, iterator);
                                rect.y += rect.height;
                            }

                            if (!iterator.NextVisible(iterator.isExpanded))
                            {
                                break;
                            }
                        }

                        EditorGUI.indentLevel  = indent;
                        EditorGUI.indentLevel -= 1;

                        /*
                         * var iter = so.GetIterator();
                         * while (iter.NextVisible(true) == true) {
                         *
                         *  if (iter.hasVisibleChildren == true) {
                         *
                         *      iter.isExpanded = EditorGUI.Foldout(rect, iter.isExpanded, iter.displayName);
                         *
                         *      if (iter.isExpanded == false) continue;
                         *
                         *  }
                         *
                         *  if (EditorHelpers.IsFieldOfTypeBeneath(prop.objectReferenceValue.GetType(), typeof(WindowComponentModule), iter.propertyPath) == true) {
                         *
                         *      rect.height = EditorGUI.GetPropertyHeight(iter);
                         *      EditorGUI.PropertyField(rect, iter);
                         *      rect.y += rect.height;
                         *
                         *  }
                         *
                         * }*/

                        so.ApplyModifiedProperties();
                    }
                };
                this.listModules.drawHeaderCallback = (rect) => { GUI.Label(rect, "Modules"); };

                //}
            }

            EditorHelpers.SetFirstSibling(this.targets);
        }
        public override void OnInspectorGUI()
        {
            this.serializedObject.Update();

            GUILayoutExt.DrawComponentHeader(this.serializedObject, "C", () => {
                GUILayoutExt.DrawComponentHeaderItem("State", GUILayoutExt.GetPropertyToString(this.objectState));
            });

            GUILayout.Space(5f);

            var scroll = this.tabScrollPosition;

            this.selectedTab = GUILayoutExt.DrawTabs(
                this.selectedTab,
                ref scroll,
                new GUITab("Basic", () => {
                GUILayoutExt.DrawHeader("Main");
                GUILayoutExt.PropertyField(this.hiddenByDefault, (reg) => reg.hiddenByDefault == true ? reg.hiddenByDefaultDescription : string.Empty);
                EditorGUILayout.PropertyField(this.subObjects);

                GUILayoutExt.DrawHeader("Animations");
                EditorGUILayout.PropertyField(this.animationParameters);

                GUILayoutExt.DrawHeader("Performance Options");
                EditorGUILayout.PropertyField(this.createPool);

                this.DrawCanvas();
            }),
                new GUITab("Advanced", () => {
                GUILayoutExt.DrawHeader("Render Behaviour");
                EditorGUILayout.PropertyField(this.renderBehaviourOnHidden);

                GUILayoutExt.DrawHeader("Animations");
                EditorGUILayout.PropertyField(this.animationParameters);

                GUILayoutExt.DrawHeader("Graph");
                GUILayoutExt.PropertyField(this.allowRegisterInRoot, (reg) => reg.allowRegisterInRoot == true ? reg.allowRegisterInRootDescription : string.Empty);
                EditorGUILayout.PropertyField(this.autoRegisterSubObjects);
                GUILayoutExt.PropertyField(this.hiddenByDefault, (reg) => reg.hiddenByDefault == true ? reg.hiddenByDefaultDescription : string.Empty);
                EditorGUILayout.PropertyField(this.subObjects);

                GUILayoutExt.DrawHeader("Performance Options");
                EditorGUILayout.PropertyField(this.createPool);

                this.DrawCanvas();
            }),
                this.listModules == null ? GUITab.none : new GUITab("Modules (" + this.listModules.count + ")", () => {
                this.listModules.DoLayoutList();
            }),
                new GUITab("Audio", () => {
                GUILayoutExt.DrawHeader("Events");
                var enterChildren = true;
                var prop          = this.audioEvents.Copy();
                var depth         = prop.depth + 1;
                while (prop.NextVisible(enterChildren) == true && prop.depth >= depth)
                {
                    EditorGUILayout.PropertyField(prop, true);
                    enterChildren = false;
                }
            })
                );
            this.tabScrollPosition = scroll;

            GUILayout.Space(10f);

            var iter = this.serializedObject.GetIterator();

            iter.NextVisible(true);
            do
            {
                if (EditorHelpers.IsFieldOfTypeBeneath(this.serializedObject.targetObject.GetType(), typeof(WindowComponent), iter.propertyPath) == true)
                {
                    EditorGUILayout.PropertyField(iter);
                }
            } while (iter.NextVisible(false) == true);

            this.serializedObject.ApplyModifiedProperties();
        }