Beispiel #1
0
        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);
            })
                );
            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 OnGUI(Rect position, SerializedProperty property, GUIContent label)
        {
            var attr = (SearchAssetsByTypePopupAttribute)this.attribute;

            var target = (string.IsNullOrEmpty(attr.innerField) == true ? property : property.FindPropertyRelative(attr.innerField));

            EditorGUI.LabelField(position, label);
            position.x     += EditorGUIUtility.labelWidth;
            position.width -= EditorGUIUtility.labelWidth;
            if (EditorGUI.DropdownButton(position, new GUIContent(target.objectReferenceValue != null ? EditorHelpers.StringToCaption(target.objectReferenceValue.name) : attr.noneOption), FocusType.Passive) == true)
            {
                var rect   = position;
                var vector = GUIUtility.GUIToScreenPoint(new Vector2(rect.x, rect.y));
                rect.x = vector.x;
                rect.y = vector.y;

                var popup = new Popup()
                {
                    title = attr.menuName, autoClose = true, screenRect = new Rect(rect.x, rect.y + rect.height, rect.width, 200f)
                };
                var objects = AssetDatabase.FindAssets("t:" + (attr.filterType != null ? attr.filterType.Name : "Object"), attr.filterDir == null ? null : new [] { attr.filterDir });
                if (string.IsNullOrEmpty(attr.noneOption) == false)
                {
                    popup.Item(attr.noneOption, null, searchable: false, action: (item) => {
                        property.serializedObject.Update();
                        target.objectReferenceValue = null;
                        property.serializedObject.ApplyModifiedProperties();
                    }, order: -1);
                }

                for (int i = 0; i < objects.Length; ++i)
                {
                    var path  = AssetDatabase.GUIDToAssetPath(objects[i]);
                    var asset = AssetDatabase.LoadAssetAtPath <Object>(path);
                    popup.Item(EditorHelpers.StringToCaption(asset.name), () => {
                        property.serializedObject.Update();
                        target.objectReferenceValue = asset;
                        property.serializedObject.ApplyModifiedProperties();
                    });
                }
                popup.Show();
            }
        }
        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);
        }
Beispiel #4
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.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");

            EditorHelpers.SetFirstSibling(this.targets);
        }
        public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
        {
            var attr       = (SearchComponentsByTypePopupAttribute)this.attribute;
            var searchType = attr.baseType;

            if (attr.allowClassOverrides == true && property.serializedObject.targetObject is ISearchComponentByTypeEditor searchComponentByTypeEditor)
            {
                searchType = searchComponentByTypeEditor.GetSearchType();
            }

            IList searchArray = null;
            var   singleOnly  = false;

            if (attr.allowClassOverrides == true && property.serializedObject.targetObject is ISearchComponentByTypeSingleEditor searchComponentByTypeSingleEditor)
            {
                searchArray = searchComponentByTypeSingleEditor.GetSearchTypeArray();
                singleOnly  = true;
            }

            var target      = (string.IsNullOrEmpty(attr.innerField) == true ? property : property.FindPropertyRelative(attr.innerField));
            var displayName = string.Empty;

            if (target.objectReferenceValue != null)
            {
                var compDisplayAttrs = target.objectReferenceValue.GetType().GetCustomAttributes(typeof(UnityEngine.UI.Windows.ComponentModuleDisplayNameAttribute), true);
                if (compDisplayAttrs.Length > 0)
                {
                    var compDisplayAttr = (UnityEngine.UI.Windows.ComponentModuleDisplayNameAttribute)compDisplayAttrs[0];
                    displayName = compDisplayAttr.name;
                }
                else
                {
                    displayName = EditorHelpers.StringToCaption(target.objectReferenceValue.GetType().Name);
                }
            }

            EditorGUI.LabelField(position, label);
            position.x     += EditorGUIUtility.labelWidth;
            position.width -= EditorGUIUtility.labelWidth;
            if (EditorGUI.DropdownButton(position, new GUIContent(target.objectReferenceValue != null ? displayName : attr.noneOption), FocusType.Passive) == true)
            {
                var rect   = position;
                var vector = GUIUtility.GUIToScreenPoint(new Vector2(rect.x, rect.y));
                rect.x = vector.x;
                rect.y = vector.y;

                var popup = new Popup()
                {
                    title = attr.menuName, autoClose = true, screenRect = new Rect(rect.x, rect.y + rect.height, rect.width, 200f)
                };
                if (string.IsNullOrEmpty(attr.noneOption) == false)
                {
                    popup.Item(attr.noneOption, null, searchable: false, action: (item) => {
                        property.serializedObject.Update();
                        if (property.objectReferenceValue != null)
                        {
                            Object.DestroyImmediate(property.objectReferenceValue, true);
                            property.objectReferenceValue = null;
                        }

                        property.serializedObject.ApplyModifiedProperties();
                    }, order: -1);
                }

                var allTypes = searchType.Assembly.GetTypes();
                foreach (var type in allTypes)
                {
                    if (type.IsSubclassOf(searchType) == true)
                    {
                        var itemType = type;
                        if (singleOnly == true)
                        {
                            var found = false;
                            foreach (var item in searchArray)
                            {
                                if (item == null)
                                {
                                    continue;
                                }
                                if (item.GetType() == itemType)
                                {
                                    found = true;
                                    break;
                                }
                            }

                            if (found == true)
                            {
                                continue;
                            }
                        }

                        var compDisplayAttrs = type.GetCustomAttributes(typeof(UnityEngine.UI.Windows.ComponentModuleDisplayNameAttribute), true);
                        if (compDisplayAttrs.Length > 0)
                        {
                            var compDisplayAttr = (UnityEngine.UI.Windows.ComponentModuleDisplayNameAttribute)compDisplayAttrs[0];
                            displayName = compDisplayAttr.name;
                        }
                        else
                        {
                            displayName = EditorHelpers.StringToCaption(type.Name);
                        }

                        popup.Item(displayName, () => {
                            property.serializedObject.Update();
                            var go = (property.serializedObject.targetObject as Component).gameObject;
                            if (property.objectReferenceValue != null)
                            {
                                Object.DestroyImmediate(property.objectReferenceValue, true);
                                property.objectReferenceValue = null;
                            }
                            property.objectReferenceValue = go.AddComponent(itemType);
                            property.serializedObject.ApplyModifiedProperties();
                        });
                    }
                }

                popup.Show();
            }
        }
Beispiel #6
0
 public static System.Reflection.FieldInfo GetFieldViaPath(System.Type type, string path)
 {
     return(EditorHelpers.GetFieldViaPath(type, path, out _));
 }
        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 override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
        {
            var aspectFromProp = property.FindPropertyRelative("aspectFrom");
            var aspectToProp   = property.FindPropertyRelative("aspectTo");
            var aspectFrom     = aspectFromProp.vector2Value;
            var aspectTo       = aspectToProp.vector2Value;

            var offset      = EditorGUI.indentLevel * 24f;
            var defPosition = position;
            var aspectRect  = new Rect(position.x + offset, position.y, EditorGUIUtility.labelWidth, position.height);

            var fillColor   = new Color(0.5f, 0.3f, 0.3f, 0.2f);
            var borderColor = fillColor;

            borderColor.a = 0.5f;

            position.x     += EditorGUIUtility.labelWidth;
            position.width -= EditorGUIUtility.labelWidth;

            GUILayoutExt.DrawRect(position, fillColor);
            GUILayoutExt.DrawBoxNotFilled(position, 1f, borderColor);

            var padding = 4f;
            var size    = position.height - padding * 2f;
            var rect    = new Rect(position.x + position.width * 0.5f - size * 0.5f, position.y + padding, size, size);

            GUILayoutExt.DrawRect(rect, fillColor);

            var fromRect = new Rect(0f, 0f, aspectFrom.x, aspectFrom.y);
            var toRect   = new Rect(0f, 0f, aspectTo.x, aspectTo.y);

            fromRect = EditorHelpers.FitRect(fromRect, rect);
            toRect   = EditorHelpers.FitRect(toRect, rect);
            GUILayoutExt.DrawBoxNotFilled(fromRect, 2f, new Color(0.4f, 0.4f, 1f, 0.6f));
            GUILayoutExt.DrawBoxNotFilled(toRect, 2f, new Color(1f, 0.4f, 1f, 0.6f));

            {
                GUILayout.BeginArea(aspectRect);
                //GUILayoutExt.Box(4f, 4f, () => {

                GUILayout.BeginHorizontal();
                {
                    GUILayout.Space(defPosition.x + 10f);

                    GUILayout.BeginVertical();
                    {
                        GUILayout.Label("From");
                        GUILayout.BeginHorizontal();
                        aspectFrom.x = EditorGUILayout.FloatField(aspectFrom.x);
                        GUILayout.Label(":", GUILayout.Width(10f));
                        aspectFrom.y = EditorGUILayout.FloatField(aspectFrom.y);
                        aspectFromProp.vector2Value = aspectFrom;
                        GUILayout.EndHorizontal();

                        //}, GUIStyle.none);
                        //GUILayoutExt.Box(4f, 4f, () => {

                        GUILayout.Label("To");
                        GUILayout.BeginHorizontal();
                        aspectTo.x = EditorGUILayout.FloatField(aspectTo.x);
                        GUILayout.Label(":", GUILayout.Width(10f));
                        aspectTo.y = EditorGUILayout.FloatField(aspectTo.y);
                        aspectToProp.vector2Value = aspectTo;
                        GUILayout.EndHorizontal();
                    }
                    GUILayout.EndVertical();
                }
                GUILayout.EndHorizontal();

                //}, GUIStyle.none);
                GUILayout.EndArea();
            }
        }
        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.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");
                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.listModules == null ? GUITab.none : new GUITab("Modules (" + this.listModules.count + ")", () => {
                this.listModules.DoLayoutList();
            })
                );
            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();
        }
Beispiel #11
0
        public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
        {
            //EditorGUI.PropertyField(position, property, label);

            var attr = this.attr;
            var go   = (property.serializedObject.targetObject as Component).gameObject;

            if (go == null)
            {
                return;
            }

            var pth = AssetDatabase.GetAssetPath(go);

            if (string.IsNullOrEmpty(pth) == true)
            {
                return;
            }

            var assetPath = System.IO.Path.GetDirectoryName(pth);

            assetPath      = assetPath.Replace("/Screens", "/Layouts");
            attr.filterDir = assetPath;

            var target = property;

            EditorGUI.LabelField(position, label);
            position.x     += EditorGUIUtility.labelWidth;
            position.width -= EditorGUIUtility.labelWidth;

            if (EditorGUI.DropdownButton(position, new GUIContent(target.objectReferenceValue != null ? EditorHelpers.StringToCaption(target.objectReferenceValue.name) : attr.noneOption), FocusType.Passive) == true)
            {
                var rect   = position;
                var vector = GUIUtility.GUIToScreenPoint(new Vector2(rect.x, rect.y));
                rect.x = vector.x;
                rect.y = vector.y;

                var popup = new Popup()
                {
                    title = attr.menuName, autoClose = true, screenRect = new Rect(rect.x, rect.y + rect.height, rect.width, 200f)
                };
                var objects = AssetDatabase.FindAssets("t:" + (attr.filterType != null ? attr.filterType : "Object"), attr.filterDir == null ? null : new [] { attr.filterDir });

                var allObjects = Resources.LoadAll <GameObject>("").Where(x => x.GetComponent <WindowLayout>() != null && x.GetComponent <TemplateMarker>() != null).ToArray();
                for (int i = 0; i < allObjects.Length; ++i)
                {
                    var idx = i;
                    popup.Item("Clone Template/" + allObjects[i].name, null, searchable: true, action: (item) => {
                        var p       = AssetDatabase.GetAssetPath(allObjects[idx]);
                        var newPath = AssetDatabase.GenerateUniqueAssetPath(assetPath + "/" + allObjects[idx].name + ".prefab");
                        AssetDatabase.CopyAsset(p, newPath);
                        AssetDatabase.ImportAsset(newPath, ImportAssetOptions.ForceUpdate);
                        var newGo = AssetDatabase.LoadAssetAtPath <GameObject>(newPath);
                        Object.DestroyImmediate(newGo.GetComponent <TemplateMarker>(), true);

                        property.serializedObject.Update();
                        target.objectReferenceValue = newGo.GetComponent <WindowLayout>();
                        property.serializedObject.ApplyModifiedProperties();
                    }, order: -1);
                }

                if (string.IsNullOrEmpty(attr.noneOption) == false)
                {
                    popup.Item(attr.noneOption, null, searchable: false, action: (item) => {
                        property.serializedObject.Update();
                        target.objectReferenceValue = null;
                        property.serializedObject.ApplyModifiedProperties();
                    }, order: -1);
                }

                for (int i = 0; i < objects.Length; ++i)
                {
                    var path  = AssetDatabase.GUIDToAssetPath(objects[i]);
                    var asset = AssetDatabase.LoadAssetAtPath <GameObject>(path);
                    if (asset.GetComponent <WindowLayout>() == null)
                    {
                        continue;
                    }

                    popup.Item(EditorHelpers.StringToCaption(asset.name), () => {
                        property.serializedObject.Update();
                        target.objectReferenceValue = asset.GetComponent <WindowLayout>();
                        property.serializedObject.ApplyModifiedProperties();
                    });
                }
                popup.Show();
            }
        }
Beispiel #12
0
        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.subObjects);

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

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

                GUILayoutExt.DrawHeader("Animations");
                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);

            if (this.targets.Length == 1)
            {
                GUILayoutExt.DrawSafeAreaFields(this.target, this.useSafeZone, this.safeZone);
            }

            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();
        }
Beispiel #13
0
        public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
        {
            var evenStyle = new GUIStyle(GUIStyle.none);

            evenStyle.normal.background = Texture2D.whiteTexture;
            var tagStyle = new GUIStyle(EditorStyles.label);

            tagStyle.alignment = TextAnchor.MiddleRight;
            var innerLayoutStyle = new GUIStyle(EditorStyles.miniLabel);

            innerLayoutStyle.alignment     = TextAnchor.UpperLeft;
            innerLayoutStyle.stretchHeight = false;

            var items = property.FindPropertyRelative("items");

            if (items.arraySize == 0)
            {
                GUILayout.BeginHorizontal();
                GUILayout.FlexibleSpace();
                if (GUILayout.Button("Add Layout", GUILayout.Height(30f), GUILayout.Width(120f)) == true)
                {
                    ++items.arraySize;
                    this.selectedTab = 0;
                }
                GUILayout.FlexibleSpace();
                GUILayout.EndHorizontal();
                GUILayout.Space(20f);
                return;
            }

            var arr = new GUITab[items.arraySize + 1];

            this.selectedTab = Mathf.Clamp(this.selectedTab, 0, arr.Length - 2);
            var i = 0;

            for (i = 0; i < items.arraySize; ++i)
            {
                var idx     = i;
                var prop    = items.GetArrayElementAtIndex(i);
                var objRef  = prop.FindPropertyRelative("windowLayout").objectReferenceValue;
                var caption = (objRef != null ? EditorHelpers.StringToCaption(objRef.name) : "Layout (Empty)");
                arr[i] = new GUITab(caption, () => {
                    GUILayout.BeginHorizontal();
                    {
                        GUILayout.FlexibleSpace();
                        if (GUILayout.Button("Remove", GUILayout.Width(60f)) == true)
                        {
                            if (EditorUtility.DisplayDialog("Delete Layout Reference", "Are you sure?", "Yes", "No") == true)
                            {
                                items.DeleteArrayElementAtIndex(idx);
                                return;
                            }
                        }
                    }
                    GUILayout.EndHorizontal();

                    if (idx > 0)
                    {
                        GUILayout.Space(6f);

                        EditorGUI.BeginChangeCheck();
                        var targets = prop.FindPropertyRelative("targets");
                        EditorGUILayout.PropertyField(targets);
                        if (EditorGUI.EndChangeCheck() == true)
                        {
                            EditorHelpers.SetDirtyAndValidate(property);
                        }
                    }
                    else
                    {
                        EditorGUILayout.HelpBox("This is default layout. Target Filter couldn't been attach here.", MessageType.Info);
                    }

                    GUILayout.Space(6f);

                    EditorGUI.BeginChangeCheck();
                    var windowLayout = prop.FindPropertyRelative("windowLayout");
                    EditorGUILayout.PropertyField(windowLayout);
                    if (EditorGUI.EndChangeCheck() == true)
                    {
                        EditorHelpers.SetDirtyAndValidate(property);
                    }

                    var layout = windowLayout.objectReferenceValue as WindowLayout;
                    if (layout == null)
                    {
                        return;
                    }

                    EditorGUI.BeginChangeCheck();
                    var layoutPreferences = prop.FindPropertyRelative("layoutPreferences");
                    EditorGUILayout.PropertyField(layoutPreferences);
                    if (layoutPreferences.objectReferenceValue == null)
                    {
                        EditorGUILayout.HelpBox("Layout Preferences are CanvasScaler override parameters. It's highly recommended to use override here.", MessageType.Info);
                    }

                    if (layoutPreferences.objectReferenceValue is WindowLayoutPreferences windowLayoutPreferences)
                    {
                        windowLayoutPreferences.Apply(layout.canvasScaler);

                        try {
                            EditorGUI.BeginDisabledGroup(true);
                            var editorCanvasScaler = Editor.CreateEditor(layout.canvasScaler);
                            editorCanvasScaler.OnInspectorGUI();
                            EditorGUI.EndDisabledGroup();
                        } catch (System.Exception) {}
                    }

                    if (EditorGUI.EndChangeCheck() == true)
                    {
                        EditorHelpers.SetDirtyAndValidate(property);
                    }

                    GUILayout.Space(2f);
                    GUILayoutExt.Separator();
                    GUILayout.Space(2f);

                    if (this.list == null)
                    {
                        var componentsProp      = prop.FindPropertyRelative("components");
                        this.list               = new UnityEditorInternal.ReorderableList(property.serializedObject, componentsProp, true, true, false, false);
                        this.list.elementHeight = 40f;
                        this.list.onAddCallback = (rList) => {
                            if (rList.serializedProperty != null)
                            {
                                ++rList.serializedProperty.arraySize;
                                rList.index = rList.serializedProperty.arraySize - 1;
                            }
                        };
                        this.list.drawElementBackgroundCallback = (rect, index, active, focused) => {
                            if (focused == 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.list.drawElementCallback = (rect, index, active, focused) => {
                            //EditorGUI.PropertyField(rect, componentsProp.GetArrayElementAtIndex(index));

                            EditorGUI.BeginChangeCheck();
                            {
                                var captionRect = new Rect(rect.x, rect.y, rect.width, 18f);
                                var tagRect     = captionRect;
                                var layoutRect  = new Rect(tagRect.x + 140f, tagRect.y, tagRect.width, tagRect.height);
                                var objectRect  = new Rect(captionRect.x, captionRect.y + 18f, captionRect.width, captionRect.height);

                                var compProp  = componentsProp.GetArrayElementAtIndex(index);
                                var component = compProp.FindPropertyRelative("component");

                                var localRagId        = compProp.FindPropertyRelative("localTag").intValue;
                                var windowLayoutInner = (WindowLayout)compProp.FindPropertyRelative("windowLayout").objectReferenceValue;
                                string layoutName     = string.Empty;
                                if (windowLayoutInner != null)
                                {
                                    var tagId         = compProp.FindPropertyRelative("tag").intValue;
                                    var layoutElement = windowLayoutInner.GetLayoutElementByTagId(tagId);
                                    if (layoutElement != null)
                                    {
                                        layoutName = layoutElement.name;
                                    }
                                }

                                using (GUILayoutExt.GUIColor(new Color(1f, 1f, 1f, 0.4f))) {
                                    if (windowLayoutInner != null && windowLayoutInner != layout)
                                    {
                                        GUI.Label(layoutRect, "(" + EditorHelpers.StringToCaption(windowLayoutInner.name) + ")", innerLayoutStyle);
                                    }
                                }

                                GUI.Label(captionRect, EditorHelpers.StringToCaption(layoutName), EditorStyles.boldLabel);
                                GUI.Label(tagRect, "Tag: " + localRagId.ToString(), tagStyle);
                                EditorGUI.PropertyField(objectRect, component, new GUIContent(string.Empty));
                            }

                            if (EditorGUI.EndChangeCheck() == true)
                            {
                                EditorHelpers.SetDirtyAndValidate(property);
                            }
                        };
                        this.list.drawHeaderCallback = (rect) => {
                            GUI.Label(rect, "Components");
                            var buttonRect   = rect;
                            var width        = 80f;
                            buttonRect.x     = rect.width - width;
                            buttonRect.width = width;
                            if (GUI.Button(buttonRect, "Refresh") == true)
                            {
                                (componentsProp.serializedObject.targetObject as WindowObject).ValidateEditor();
                            }
                        };
                    }

                    this.list.DoLayoutList();

                    /*
                     * EditorGUI.BeginChangeCheck();
                     * var components = prop.FindPropertyRelative("components");
                     * for (int j = 0; j < components.arraySize; ++j) {
                     *
                     *  var compProp = components.GetArrayElementAtIndex(j);
                     *  var component = compProp.FindPropertyRelative("component");
                     *
                     *  var c = GUI.color;
                     *  GUI.color = new Color(1f, 1f, 1f, 0.1f);
                     *  GUILayout.BeginVertical(j % 2 == 0 ? evenStyle : oddStyle);
                     *  GUI.color = c;
                     *  {
                     *
                     *      GUILayout.Space(4f);
                     *      GUILayout.BeginHorizontal();
                     *      {
                     *          var localRagId = compProp.FindPropertyRelative("localTag").intValue;
                     *          var windowLayoutInner = (WindowLayout)compProp.FindPropertyRelative("windowLayout").objectReferenceValue;
                     *          string layoutName = string.Empty;
                     *          if (windowLayoutInner != null) {
                     *
                     *              var tagId = compProp.FindPropertyRelative("tag").intValue;
                     *              var layoutElement = windowLayoutInner.GetLayoutElementByTagId(tagId);
                     *              if (layoutElement != null) layoutName = layoutElement.name;
                     *
                     *          }
                     *          GUILayout.Label(EditorHelpers.StringToCaption(layoutName), EditorStyles.boldLabel, GUILayout.ExpandWidth(false));
                     *          using (GUILayoutExt.GUIColor(new Color(1f, 1f, 1f, 0.4f))) {
                     *              if (windowLayoutInner != null && windowLayoutInner != layout) GUILayout.Label("(" + EditorHelpers.StringToCaption(windowLayoutInner.name) + ")", innerLayoutStyle, GUILayout.ExpandWidth(false));
                     *          }
                     *
                     *          GUILayout.FlexibleSpace();
                     *          GUILayout.Label("Tag: " + localRagId.ToString(), tagStyle, GUILayout.ExpandWidth(false));
                     *      }
                     *      GUILayout.EndHorizontal();
                     *      EditorGUILayout.PropertyField(component);
                     *
                     *      GUILayout.Space(4f);
                     *      GUILayoutExt.Separator();
                     *
                     *  }
                     *  GUILayout.EndVertical();
                     *
                     * }
                     * if (EditorGUI.EndChangeCheck() == true) {
                     *
                     *  EditorHelpers.SetDirtyAndValidate(property);
                     *
                     * }*/
                });
            }

            arr[i] = new GUITab("+", () => {
            }, 40f);

            var scroll = this.tabScrollPosition;
            var newTab = GUILayoutExt.DrawTabs(
                this.selectedTab,
                ref scroll,
                arr
                );

            this.tabScrollPosition = scroll;

            if (newTab != this.selectedTab)
            {
                if (newTab == i)
                {
                    // Add item
                    ++items.arraySize;
                    this.selectedTab = i;
                }
                else
                {
                    this.selectedTab = newTab;
                }
            }
        }
        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);
        }