Beispiel #1
0
        public static void OnSceneTreeReflectICollection(SceneExplorerState state, ReferenceChain refChain, object myProperty, TypeUtil.SmartType elementSmartType = TypeUtil.SmartType.Undefined)
        {
            if (!SceneExplorerCommon.SceneTreeCheckDepth(refChain))
            {
                return;
            }

            if (!(myProperty is ICollection collection))
            {
                return;
            }

            var oldRefChain    = refChain;
            var collectionSize = collection.Count;

            if (collectionSize == 0)
            {
                GUILayout.BeginHorizontal();
                GUI.contentColor = Color.yellow;
                GUILayout.Label("Collection is empty!");
                GUI.contentColor = Color.white;
                GUILayout.FlexibleSpace();
                GUILayout.EndHorizontal();
                return;
            }

            var collectionItemType = collection.GetType().GetElementType();
            var flagsField         = collectionItemType?.GetField("m_flags");
            var flagIsEnum         = flagsField?.FieldType.IsEnum == true && Type.GetTypeCode(flagsField.FieldType) == TypeCode.Int32;

            GUICollectionNavigation.SetUpCollectionNavigation("Collection", state, refChain, oldRefChain, collectionSize, out var arrayStart, out var arrayEnd);
            uint count = 0;

            foreach (var value in collection)
            {
                if (count < arrayStart)
                {
                    count++;
                    continue;
                }

                refChain = oldRefChain.Add(count);

                GUILayout.BeginHorizontal(GUIWindow.HighlightStyle);
                SceneExplorerCommon.InsertIndent(refChain.Indentation);

                var isNullOrEmpty = value == null || flagIsEnum && Convert.ToInt32(flagsField.GetValue(value)) == 0;

                var type = value?.GetType() ?? collectionItemType;
                if (type != null)
                {
                    if (!isNullOrEmpty)
                    {
                        GUIExpander.ExpanderControls(state, refChain, type);
                    }

                    GUI.contentColor = MainWindow.Instance.Config.TypeColor;

                    GUILayout.Label(type.ToString() + " ");
                }

                GUI.contentColor = MainWindow.Instance.Config.NameColor;

                GUILayout.Label($"{oldRefChain.LastItemName}.[{count}]");

                GUI.contentColor = Color.white;

                GUILayout.Label(" = ");

                GUI.contentColor = MainWindow.Instance.Config.ValueColor;
                GUILayout.Label(value == null ? "null" : isNullOrEmpty ? "empty" : value.ToString());

                GUI.contentColor = Color.white;

                GUILayout.FlexibleSpace();

                if (!isNullOrEmpty)
                {
                    GUIButtons.SetupCommonButtons(refChain, value, count, elementSmartType);
                }

                if (value != null)
                {
                    GUIButtons.SetupJumpButton(value, refChain);
                }

                GUILayout.EndHorizontal();

                if (!isNullOrEmpty && !TypeUtil.IsSpecialType(type) && state.ExpandedObjects.Contains(refChain.UniqueId))
                {
                    GUIReflect.OnSceneTreeReflect(state, refChain, value, false);
                }

                count++;
                if (count > arrayEnd)
                {
                    break;
                }
            }
        }
        public static void OnSceneTreeReflectICollection(SceneExplorerState state, ReferenceChain refChain, System.Object myProperty)
        {
            if (!SceneExplorerCommon.SceneTreeCheckDepth(refChain))
            {
                return;
            }

            var collection = myProperty as ICollection;

            if (collection == null)
            {
                return;
            }

            var oldRefChain    = refChain;
            var collectionSize = collection.Count;

            if (collectionSize == 0)
            {
                GUILayout.BeginHorizontal();
                GUI.contentColor = Color.yellow;
                GUILayout.Label("Collection is empty!");
                GUI.contentColor = Color.white;
                GUILayout.FlexibleSpace();
                GUILayout.EndHorizontal();
                return;
            }


            int arrayStart;
            int arrayEnd;

            GUICollectionNavigation.SetUpCollectionNavigation("Collection", state, refChain, oldRefChain, collectionSize, out arrayStart, out arrayEnd);
            int count = 0;

            foreach (var value in collection)
            {
                if (count < arrayStart)
                {
                    count++;
                    continue;
                }

                refChain = oldRefChain.Add(count);
                var type = value.GetType();

                GUILayout.BeginHorizontal();
                GUILayout.Space(ModTools.Instance.config.sceneExplorerTreeIdentSpacing * refChain.Ident);

                GUIExpander.ExpanderControls(state, refChain, type);

                GUI.contentColor = ModTools.Instance.config.typeColor;

                GUILayout.Label(type.ToString() + " ");

                GUI.contentColor = ModTools.Instance.config.nameColor;

                GUILayout.Label($"{oldRefChain.LastItemName}.[{count}]");

                GUI.contentColor = Color.white;

                GUILayout.Label(" = ");

                GUI.contentColor = ModTools.Instance.config.valueColor;
                GUILayout.Label(value == null ? "null" : value.ToString());

                GUI.contentColor = Color.white;

                GUILayout.FlexibleSpace();
                GUIButtons.SetupButtons(type, value, refChain);
                GUILayout.EndHorizontal();

                if (!TypeUtil.IsSpecialType(type) && state.expandedObjects.ContainsKey(refChain))
                {
                    if (value is GameObject)
                    {
                        var go = value as GameObject;
                        foreach (var component in go.GetComponents <Component>())
                        {
                            GUIComponent.OnSceneTreeComponent(state, refChain, component);
                        }
                    }
                    else if (value is Transform)
                    {
                        GUITransform.OnSceneTreeReflectUnityEngineTransform(refChain, (Transform)value);
                    }
                    else
                    {
                        GUIReflect.OnSceneTreeReflect(state, refChain, value);
                    }
                }

                count++;
                if (count > arrayEnd)
                {
                    break;
                }
            }
        }
Beispiel #3
0
        public static void OnSceneTreeReflectIList(SceneExplorerState state,
                                                   ReferenceChain refChain, System.Object myProperty)
        {
            if (!SceneExplorerCommon.SceneTreeCheckDepth(refChain))
            {
                return;
            }

            var list = myProperty as IList;

            if (list == null)
            {
                return;
            }

            var oldRefChain    = refChain;
            var collectionSize = list.Count;

            if (collectionSize == 0)
            {
                GUILayout.BeginHorizontal();
                GUI.contentColor = Color.yellow;
                GUILayout.Label("List is empty!");
                GUI.contentColor = Color.white;
                GUILayout.FlexibleSpace();
                GUILayout.EndHorizontal();
                return;
            }

            int arrayStart;
            int arrayEnd;

            GUICollectionNavigation.SetUpCollectionNavigation("List", state, refChain, oldRefChain, collectionSize, out arrayStart, out arrayEnd);
            for (int i = arrayStart; i <= arrayEnd; i++)
            {
                refChain = oldRefChain.Add(i);
                if (list[i] == null)
                {
                    continue;
                }

                GUILayout.BeginHorizontal();
                GUILayout.Space(ModTools.Instance.config.sceneExplorerTreeIdentSpacing * refChain.Ident);


                GUI.contentColor = Color.white;
                var type = list[i] == null ? null : list[i].GetType();
                GUIExpander.ExpanderControls(state, refChain, type);

                GUI.contentColor = ModTools.Instance.config.typeColor;

                GUILayout.Label($"{type} ");

                GUI.contentColor = ModTools.Instance.config.nameColor;

                GUILayout.Label($"{oldRefChain.LastItemName}.[{i}]");

                GUI.contentColor = Color.white;

                GUILayout.Label(" = ");

                GUI.contentColor = ModTools.Instance.config.valueColor;

                if (list[i] == null || !TypeUtil.IsSpecialType(list[i].GetType()))
                {
                    GUILayout.Label(list[i] == null ? "null" : list[i].ToString());
                }
                else
                {
                    try
                    {
                        var newValue = GUIControls.EditorValueField(refChain, refChain.ToString(), list[i].GetType(), list[i]);
                        if (newValue != list[i])
                        {
                            list[i] = newValue;
                        }
                    }
                    catch (Exception)
                    {
                        GUILayout.Label(list[i] == null ? "null" : list[i].ToString());
                    }
                }

                GUI.contentColor = Color.white;

                GUILayout.FlexibleSpace();
                GUIButtons.SetupButtons(type, list[i], refChain);
                GUILayout.EndHorizontal();

                if (!TypeUtil.IsSpecialType(type) && state.expandedObjects.ContainsKey(refChain))
                {
                    if (list[i] is GameObject)
                    {
                        var go = list[i] as GameObject;
                        foreach (var component in go.GetComponents <Component>())
                        {
                            GUIComponent.OnSceneTreeComponent(state, refChain, component);
                        }
                    }
                    else if (list[i] is Transform)
                    {
                        GUITransform.OnSceneTreeReflectUnityEngineTransform(refChain, (Transform)list[i]);
                    }
                    else
                    {
                        GUIReflect.OnSceneTreeReflect(state, refChain, list[i]);
                    }
                }
            }
        }