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.animationParameters     = this.serializedObject.FindProperty("animationParameters");
            this.renderBehaviourOnHidden = this.serializedObject.FindProperty("renderBehaviourOnHidden");

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

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

            this.useSafeZone = this.serializedObject.FindProperty("useSafeZone");
            this.safeZone    = this.serializedObject.FindProperty("safeZone");

            EditorHelpers.SetFirstSibling(this.targets);

            EditorApplication.update += this.Repaint;
        }
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);
        }
        public void OnEnable()
        {
            this.emulatePlatform        = this.serializedObject.FindProperty("emulatePlatform");
            this.emulateRuntimePlatform = this.serializedObject.FindProperty("emulateRuntimePlatform");
            this.registeredPrefabs      = this.serializedObject.FindProperty("registeredPrefabs");
            this.showRootOnStart        = this.serializedObject.FindProperty("showRootOnStart");
            this.rootScreen             = this.serializedObject.FindProperty("rootScreen");

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

            { // Modules
                this.breadcrumbs = this.serializedObject.FindProperty("breadcrumbs");
                this.events      = this.serializedObject.FindProperty("events");
                this.resources   = this.serializedObject.FindProperty("resources");
                this.pools       = this.serializedObject.FindProperty("pools");
                this.tweener     = this.serializedObject.FindProperty("tweener");
            }

            EditorHelpers.SetFirstSibling(this.targets);
        }
        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 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");

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

            var moduleItems = this.modules.FindPropertyRelative("modules");
            this.listModules = new UnityEditorInternal.ReorderableList(this.serializedObject, moduleItems, false, false, true, true);
            this.listModules.headerHeight           = 1f;
            this.listModules.elementHeightCallback += (index) => {
                var item = moduleItems.GetArrayElementAtIndex(index);
                var h    = 0f;
                h += EditorGUI.GetPropertyHeight(item.FindPropertyRelative("targets"));
                h += 2f;
                h += EditorGUI.GetPropertyHeight(item.FindPropertyRelative("module"));
                h += 2f;
                h += 20f;
                var parameters = item.FindPropertyRelative("parameters");
                if (parameters.hasVisibleChildren == true)
                {
                    var px = parameters.Copy();
                    px.NextVisible(true);
                    var depth = px.depth;
                    while (px.depth >= depth)
                    {
                        h += EditorGUI.GetPropertyHeight(px, true);
                        if (px.NextVisible(false) == false)
                        {
                            break;
                        }
                    }
                    h += 4f;
                }
                h += 4f;
                return(h);
            };
            this.listModules.drawElementCallback += (rect, index, active, focus) => {
                var item      = moduleItems.GetArrayElementAtIndex(index);
                var prevValue = item.FindPropertyRelative("module").FindPropertyRelative("guid").stringValue;
                rect.y     += 2f;
                rect.height = 18f;
                EditorGUI.BeginChangeCheck();
                //GUILayoutExt.DrawProperty(rect, item, 20f);
                EditorGUI.PropertyField(rect, item.FindPropertyRelative("targets"));
                rect.y += EditorGUI.GetPropertyHeight(item.FindPropertyRelative("targets"), true);
                rect.y += 2f;
                EditorGUI.PropertyField(rect, item.FindPropertyRelative("module"));
                rect.y += EditorGUI.GetPropertyHeight(item.FindPropertyRelative("module"), true);
                rect.y += 2f;
                EditorGUI.LabelField(rect, "Parameters", EditorStyles.centeredGreyMiniLabel);
                rect.y += 20f;

                var parameters = item.FindPropertyRelative("parameters");
                {
                    if (string.IsNullOrEmpty(parameters.managedReferenceFullTypename) == true)
                    {
                        parameters.managedReferenceValue = new WindowModule.Parameters();
                    }

                    if (parameters.hasVisibleChildren == true)
                    {
                        var px = parameters.Copy();
                        px.NextVisible(true);
                        var depth = px.depth;
                        while (px.depth >= depth)
                        {
                            var h = EditorGUI.GetPropertyHeight(px, true);
                            EditorGUI.PropertyField(rect, px, true);
                            rect.y += h;
                            rect.y += 2f;
                            if (px.NextVisible(false) == false)
                            {
                                break;
                            }
                        }
                    }

                    rect.y += 4f;

                    /*
                     * var p = parameters.Copy();
                     * if (p.CountInProperty() > 0) {
                     *  var px = parameters.Copy();
                     *  px.NextVisible(true);
                     *  var h = EditorGUI.GetPropertyHeight(px, true);
                     *  EditorGUI.PropertyField(rect, px, true);
                     *  rect.y += h;
                     *  rect.y += 2f;
                     * }*/
                }

                GUILayoutExt.DrawRect(new Rect(rect.x, rect.y - 3f, rect.width, 1f), new Color(1f, 1f, 1f, 0.1f));
                rect.y += 4f;
                if (EditorGUI.EndChangeCheck() == true)
                {
                    var newValue = item.FindPropertyRelative("module").FindPropertyRelative("guid").stringValue;
                    if (prevValue != newValue && string.IsNullOrEmpty(newValue) == false)
                    {
                        var guid             = newValue;
                        var assetPath        = AssetDatabase.GUIDToAssetPath(guid);
                        var module           = AssetDatabase.LoadAssetAtPath <WindowModule>(assetPath);
                        var sourceParameters = module.parameters;
                        parameters.managedReferenceValue = sourceParameters;
                    }
                }
            };

            EditorHelpers.SetFirstSibling(this.targets);
        }