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();
        }
Beispiel #2
0
        public 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.focusState  = this.serializedObject.FindProperty("focusState");

            this.preferences = this.serializedObject.FindProperty("preferences");
            this.modules     = this.serializedObject.FindProperty("modules");
            this.layouts     = this.serializedObject.FindProperty("layouts");

            var moduleItems = this.modules.FindPropertyRelative("modules");
            this.listModules = new UnityEditorInternal.ReorderableList(this.serializedObject, moduleItems, false, false, true, true);
            const float elementHeight = 64f;
            this.listModules.headerHeight         = 1f;
            this.listModules.elementHeight        = elementHeight;
            this.listModules.drawElementCallback += (rect, index, active, focus) => {
                var item      = moduleItems.GetArrayElementAtIndex(index);
                var prevValue = item.FindPropertyRelative("module").FindPropertyRelative("guid");
                rect.y     += 2f;
                rect.height = 18f;
                EditorGUI.BeginChangeCheck();
                GUILayoutExt.DrawProperty(rect, item, 20f);
                GUILayoutExt.DrawRect(new Rect(rect.x, rect.y + elementHeight - 3f, rect.width, 1f), new Color(1f, 1f, 1f, 0.1f));
                if (EditorGUI.EndChangeCheck() == true)
                {
                    var newValue = item.FindPropertyRelative("module").FindPropertyRelative("guid");
                    if (prevValue != newValue && string.IsNullOrEmpty(newValue.stringValue) == false)
                    {
                        var guid      = newValue.stringValue;
                        var assetPath = AssetDatabase.GUIDToAssetPath(guid);
                        var obj       = AssetDatabase.LoadAssetAtPath <WindowModule>(assetPath);

                        var module = obj;
                        item.FindPropertyRelative("order").intValue = module.defaultOrder;
                    }
                }
                //EditorGUI.PropertyField(rect, item);
            };

            EditorHelpers.SetFirstSibling(this.targets);
        }