Exemplo n.º 1
0
        public static void SetUpCollectionNavigation(
            string collectionLabel,
            SceneExplorerState state,
            ReferenceChain refChain,
            ReferenceChain oldRefChain,
            int collectionSize,
            out uint arrayStart,
            out uint arrayEnd)
        {
            GUILayout.BeginHorizontal();
            SceneExplorerCommon.InsertIndent(refChain.Indentation);

            GUILayout.Label($"{collectionLabel} size: {collectionSize}");

            if (!state.SelectedArrayStartIndices.TryGetValue(refChain.UniqueId, out arrayStart))
            {
                state.SelectedArrayStartIndices.Add(refChain.UniqueId, 0);
            }

            if (!state.SelectedArrayEndIndices.TryGetValue(refChain.UniqueId, out arrayEnd))
            {
                state.SelectedArrayEndIndices.Add(refChain.UniqueId, 32);
                arrayEnd = 32;
            }

            arrayStart = GUIControls.NumericValueField($"{oldRefChain}.arrayStart", "Start index", arrayStart);
            arrayEnd   = GUIControls.NumericValueField($"{oldRefChain}.arrayEnd", "End index", arrayEnd);
            GUILayout.Label("(32 items max)");
            var pageSize = (uint)Mathf.Clamp(arrayEnd - arrayStart + 1, 1, Mathf.Min(32, collectionSize - arrayStart, arrayEnd + 1));

            if (GUILayout.Button("◄", GUILayout.ExpandWidth(false)))
            {
                arrayStart -= pageSize;
                arrayEnd   -= pageSize;
            }

            if (GUILayout.Button("►", GUILayout.ExpandWidth(false)))
            {
                arrayStart += pageSize;
                arrayEnd   += pageSize;
            }

            arrayStart = (uint)Mathf.Clamp(arrayStart, 0, collectionSize - pageSize);
            arrayEnd   = (uint)Mathf.Max(0, Mathf.Clamp(arrayEnd, pageSize - 1, collectionSize - 1));
            if (arrayStart > arrayEnd)
            {
                arrayEnd = arrayStart;
            }

            if (arrayEnd - arrayStart > 32)
            {
                arrayEnd = arrayStart + 32;
                arrayEnd = (uint)Mathf.Max(0, Mathf.Clamp(arrayEnd, 32, collectionSize - 1));
            }

            state.SelectedArrayStartIndices[refChain.UniqueId] = arrayStart;
            state.SelectedArrayEndIndices[refChain.UniqueId]   = arrayEnd;
            GUILayout.FlexibleSpace();
            GUILayout.EndHorizontal();
        }
        public static void SetUpCollectionNavigation(string collectionLabel, SceneExplorerState state, ReferenceChain refChain, ReferenceChain oldRefChain, int collectionSize, out int arrayStart,
                                                     out int arrayEnd)
        {
            GUILayout.BeginHorizontal();
            GUILayout.Space(ModTools.Instance.config.sceneExplorerTreeIdentSpacing * refChain.Ident);
            GUILayout.Label($"{collectionLabel} size: {collectionSize}");

            if (!state.selectedArrayStartIndices.ContainsKey(refChain))
            {
                state.selectedArrayStartIndices.Add(refChain, 0);
            }

            if (!state.selectedArrayEndIndices.ContainsKey(refChain))
            {
                state.selectedArrayEndIndices.Add(refChain, 32);
            }

            arrayStart = state.selectedArrayStartIndices[refChain];
            arrayEnd   = state.selectedArrayEndIndices[refChain];
            GUIControls.IntField($"{oldRefChain}.arrayStart", "Start index", ref arrayStart, 0.0f, true, true);
            GUIControls.IntField($"{oldRefChain}.arrayEnd", "End index", ref arrayEnd, 0.0f, true, true);
            GUILayout.Label("(32 items max)");
            var pageSize = Mathf.Clamp(arrayEnd - arrayStart + 1, 1, Mathf.Min(32, collectionSize - arrayStart, arrayEnd + 1));

            if (GUILayout.Button("◄", GUILayout.ExpandWidth(false)))
            {
                arrayStart -= pageSize;
                arrayEnd   -= pageSize;
            }
            if (GUILayout.Button("►", GUILayout.ExpandWidth(false)))
            {
                arrayStart += pageSize;
                arrayEnd   += pageSize;
            }
            arrayStart = Mathf.Clamp(arrayStart, 0, collectionSize - pageSize);
            arrayEnd   = Mathf.Clamp(arrayEnd, pageSize - 1, collectionSize - 1);
            if (arrayStart > arrayEnd)
            {
                arrayEnd = arrayStart;
            }

            if (arrayEnd - arrayStart > 32)
            {
                arrayEnd = arrayStart + 32;
                arrayEnd = Mathf.Clamp(arrayEnd, 32, collectionSize - 1);
            }
            state.selectedArrayStartIndices[refChain] = arrayStart;
            state.selectedArrayEndIndices[refChain]   = arrayEnd;
            GUILayout.FlexibleSpace();
            GUILayout.EndHorizontal();
        }
Exemplo n.º 3
0
        public static void OnSceneTreeComponent(SceneExplorerState state, ReferenceChain refChain, Component component)
        {
            if (!SceneExplorerCommon.SceneTreeCheckDepth(refChain))
            {
                return;
            }

            if (component == null)
            {
                SceneExplorerCommon.OnSceneTreeMessage(refChain, "null");
                return;
            }

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

            if (Util.ComponentIsEnabled(component))
            {
                GUI.contentColor = ModTools.Instance.config.enabledComponentColor;
            }
            else
            {
                GUI.contentColor = ModTools.Instance.config.disabledComponentColor;
            }

            if (state.currentRefChain == null || !state.currentRefChain.Equals(refChain.Add(component)))
            {
                if (GUILayout.Button(">", GUILayout.ExpandWidth(false)))
                {
                    state.currentRefChain             = refChain.Add(component);
                    state.currentRefChain.IdentOffset = -(refChain.Length + 1);
                }
            }
            else
            {
                GUI.contentColor = ModTools.Instance.config.selectedComponentColor;
                if (GUILayout.Button("<", GUILayout.ExpandWidth(false)))
                {
                    state.currentRefChain = null;
                }
            }

            GUILayout.Label(component.GetType().ToString());

            GUI.contentColor = Color.white;
            GUILayout.EndHorizontal();
        }
Exemplo n.º 4
0
        public SceneExplorer()
            : base(TitleBase, new Rect(128, 440, 800, 500))
        {
            headerArea = new GUIArea(this)
                         .ChangeSizeRelative(height: 0)
                         .OffsetBy(vertical: WindowTopMargin);

            sceneTreeArea = new GUIArea(this)
                            .ChangeSizeRelative(width: 0)
                            .ChangeSizeBy(width: SceneTreeWidth);

            componentArea = new GUIArea(this)
                            .OffsetBy(horizontal: SceneTreeWidth)
                            .ChangeSizeBy(width: -SceneTreeWidth);

            state = new SceneExplorerState();

            RecalculateAreas();
        }
Exemplo n.º 5
0
        public static void OnSceneTreeComponent(SceneExplorerState state, ReferenceChain refChain, Component component)
        {
            if (!SceneExplorerCommon.SceneTreeCheckDepth(refChain))
            {
                return;
            }

            if (component == null)
            {
                SceneExplorerCommon.OnSceneTreeMessage(refChain, "null");
                return;
            }

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

            GUI.contentColor = GameObjectUtil.ComponentIsEnabled(component)
                ? MainWindow.Instance.Config.EnabledComponentColor
                : MainWindow.Instance.Config.DisabledComponentColor;

            if (state.CurrentRefChain?.IsSameChain(refChain) != true)
            {
                if (GUILayout.Button(">", GUILayout.ExpandWidth(false)))
                {
                    var sceneExplorer = Object.FindObjectOfType <SceneExplorer>();
                    sceneExplorer.Show(refChain, false);
                }
            }
            else
            {
                GUI.contentColor = MainWindow.Instance.Config.SelectedComponentColor;
                state.PreventCircularReferences.Add(component.gameObject);
                if (GUILayout.Button("<", GUILayout.ExpandWidth(false)))
                {
                    state.CurrentRefChain = null;
                }
            }

            GUILayout.Label(component.GetType().ToString());

            GUI.contentColor = Color.white;
            GUILayout.EndHorizontal();
        }
Exemplo n.º 6
0
        public static void ExpanderControls(SceneExplorerState state, ReferenceChain refChain, Type type, object o = null)
        {
            GUI.contentColor = Color.white;
            if (TypeUtil.IsSpecialType(type) || o != null && TypeUtil.IsEnumerable(o))
            {
                return;
            }

            if (state.ExpandedObjects.Contains(refChain.UniqueId))
            {
                if (GUILayout.Button("-", GUILayout.ExpandWidth(false)))
                {
                    state.ExpandedObjects.Remove(refChain.UniqueId);
                }
            }
            else if (GUILayout.Button("+", GUILayout.ExpandWidth(false)))
            {
                state.ExpandedObjects.Add(refChain.UniqueId);
            }
        }
Exemplo n.º 7
0
        public static void OnSceneReflectUnityEngineMaterial(SceneExplorerState state, ReferenceChain refChain, Material material)
        {
            if (!SceneExplorerCommon.SceneTreeCheckDepth(refChain))
            {
                return;
            }

            if (material == null)
            {
                SceneExplorerCommon.OnSceneTreeMessage(refChain, "null");
                return;
            }

            ReferenceChain oldRefChain = refChain;

            foreach (var prop in textureProps)
            {
                if (!material.HasProperty(prop))
                {
                    continue;
                }

                var value = material.GetTexture(prop);
                if (value == null)
                {
                    continue;
                }

                refChain = oldRefChain.Add(prop);

                var type = value.GetType();

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

                GUIExpander.ExpanderControls(state, refChain, type);

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

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

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

                GUILayout.Label(prop);

                GUI.contentColor = Color.white;

                GUILayout.Label(" = ");

                GUI.contentColor = ModTools.Instance.config.valueColor;
                GUILayout.Label(value.ToString());
                GUI.contentColor = Color.white;

                GUILayout.FlexibleSpace();
                GUIButtons.SetupButtons(type, value, refChain);
                object paste;
                var    doPaste = GUIButtons.SetupPasteButon(type, out paste);
                GUILayout.EndHorizontal();

                if (!TypeUtil.IsSpecialType(type) && state.expandedObjects.ContainsKey(refChain))
                {
                    GUIReflect.OnSceneTreeReflect(state, refChain, value);
                }

                if (doPaste)
                {
                    material.SetTexture(prop, (Texture)paste);
                }
            }

            foreach (string prop in colorProps)
            {
                if (!material.HasProperty(prop))
                {
                    continue;
                }

                Color value = material.GetColor(prop);
                refChain = oldRefChain.Add(prop);

                var type = value.GetType();

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

                GUIExpander.ExpanderControls(state, refChain, type);

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

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

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

                GUILayout.Label(prop);

                GUI.contentColor = Color.white;

                GUILayout.Label(" = ");
                var f = value;

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

                var propertyCopy = prop;
                GUIControls.ColorField(refChain.ToString(), "", ref f, 0.0f, null, true, true, color => { material.SetColor(propertyCopy, color); });
                if (f != value)
                {
                    material.SetColor(prop, f);
                }

                GUI.contentColor = Color.white;
                GUILayout.FlexibleSpace();
                GUIButtons.SetupButtons(type, value, refChain);
                object paste;
                var    doPaste = GUIButtons.SetupPasteButon(type, out paste);
                GUILayout.EndHorizontal();

                if (!TypeUtil.IsSpecialType(type) && state.expandedObjects.ContainsKey(refChain))
                {
                    GUIReflect.OnSceneTreeReflect(state, refChain, value);
                }
                if (doPaste)
                {
                    material.SetColor(prop, (Color)paste);
                }
            }

            GUIReflect.OnSceneTreeReflect(state, refChain, material, true);
        }
Exemplo n.º 8
0
        public static void OnSceneTreeReflectIEnumerable(SceneExplorerState state, ReferenceChain refChain, object myProperty, TypeUtil.SmartType elementSmartType = TypeUtil.SmartType.Undefined)
        {
            if (!SceneExplorerCommon.SceneTreeCheckDepth(refChain))
            {
                return;
            }

            if (!(myProperty is IEnumerable enumerable))
            {
                return;
            }

            uint count       = 0;
            var  oldRefChain = refChain;

            foreach (var value in enumerable)
            {
                refChain = oldRefChain.Add(count);

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

                var type = value?.GetType();
                if (type != null)
                {
                    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" : value.ToString());

                GUI.contentColor = Color.white;

                GUILayout.FlexibleSpace();
                GUILayout.EndHorizontal();

                if (type != null && !TypeUtil.IsSpecialType(type) && state.ExpandedObjects.Contains(refChain.UniqueId))
                {
                    GUIReflect.OnSceneTreeReflect(state, refChain, value, false, elementSmartType, string.Empty);
                }

                count++;
                if (count >= 128)
                {
                    SceneExplorerCommon.OnSceneTreeMessage(refChain, "Enumerable too large to display");
                    break;
                }
            }
        }
Exemplo n.º 9
0
        public static void OnSceneTreeReflect(SceneExplorerState state, ReferenceChain refChain, System.Object obj, bool rawReflection = false)
        {
            if (!SceneExplorerCommon.SceneTreeCheckDepth(refChain))
            {
                return;
            }

            if (obj == null)
            {
                SceneExplorerCommon.OnSceneTreeMessage(refChain, "null");
                return;
            }

            Type type = obj.GetType();

            if (!rawReflection)
            {
                if (state.preventCircularReferences.ContainsKey(obj.GetHashCode()))
                {
                    SceneExplorerCommon.OnSceneTreeMessage(refChain, "Circular reference detected");
                    return;
                }

                state.preventCircularReferences.Add(obj.GetHashCode(), true);

                if (type == typeof(UnityEngine.Transform))
                {
                    GUITransform.OnSceneTreeReflectUnityEngineTransform(refChain, (UnityEngine.Transform)obj);
                    return;
                }

                if (TypeUtil.IsList(obj))
                {
                    GUIList.OnSceneTreeReflectIList(state, refChain, obj);
                    return;
                }

                if (TypeUtil.IsCollection(obj))
                {
                    GUICollection.OnSceneTreeReflectICollection(state, refChain, obj);
                    return;
                }

                if (TypeUtil.IsEnumerable(obj))
                {
                    GUIEnumerable.OnSceneTreeReflectIEnumerable(state, refChain, obj);
                    return;
                }

                if (type == typeof(Material))
                {
                    GUIMaterial.OnSceneReflectUnityEngineMaterial(state, refChain, (UnityEngine.Material)obj);
                    return;
                }
                if (type == typeof(Mesh))
                {
                    if (!((Mesh)obj).isReadable)
                    {
                        SceneExplorerCommon.OnSceneTreeMessage(refChain, "Mesh is not readable");
                        return;
                    }
                }
            }

            var members = TypeUtil.GetAllMembers(type, ModTools.Instance.config.sceneExplorerShowInheritedMembers);

            if (ModTools.Instance.config.sceneExplorerSortAlphabetically)
            {
                Array.Sort(members, (info, info1) => string.Compare(info.Name, info1.Name, StringComparison.Ordinal));
            }

            foreach (MemberInfo member in members)
            {
                if (member.MemberType == MemberTypes.Field && ModTools.Instance.config.sceneExplorerShowFields)
                {
                    var field = (FieldInfo)member;

                    try
                    {
                        GUIField.OnSceneTreeReflectField(state, refChain.Add(field), obj, field);
                    }
                    catch (Exception ex)
                    {
                        SceneExplorerCommon.OnSceneTreeMessage(refChain, $"Exception when fetching field \"{field.Name}\" - {ex.Message}\n{ex.StackTrace}");
                    }
                }
                else if (member.MemberType == MemberTypes.Property && ModTools.Instance.config.sceneExplorerShowProperties)
                {
                    var property = (PropertyInfo)member;

                    try
                    {
                        GUIProperty.OnSceneTreeReflectProperty(state, refChain.Add(property), obj, property);
                    }
                    catch (Exception ex)
                    {
                        SceneExplorerCommon.OnSceneTreeMessage(refChain, $"Exception when fetching property \"{property.Name}\" - {ex.Message}\n{ex.StackTrace}");
                    }
                }
                else if (member.MemberType == MemberTypes.Method && ModTools.Instance.config.sceneExplorerShowMethods)
                {
                    var method = (MethodInfo)member;

                    try
                    {
                        GUIMethod.OnSceneTreeReflectMethod(refChain.Add(method), obj, method);
                    }
                    catch (Exception ex)
                    {
                        SceneExplorerCommon.OnSceneTreeMessage(refChain, $"Exception when fetching method \"{method.Name}\" - {ex.Message}");
                    }
                }
            }
        }
Exemplo n.º 10
0
        public static void OnSceneTreeReflectProperty(SceneExplorerState state, ReferenceChain refChain, object obj, PropertyInfo property, TypeUtil.SmartType smartType = TypeUtil.SmartType.Undefined, int nameHighlightFrom = -1, int nameHighlightLength = 0)
        {
            if (!SceneExplorerCommon.SceneTreeCheckDepth(refChain))
            {
                return;
            }

            if (obj == null || property == null)
            {
                SceneExplorerCommon.OnSceneTreeMessage(refChain, "null");
                return;
            }

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

            object value = null;

            Exception exceptionOnGetting = null;

            if (property.CanRead && MainWindow.Instance.Config.EvaluateProperties || state.EvaluatedProperties.Contains(refChain.UniqueId))
            {
                try
                {
                    value = property.GetValue(obj, null);
                }
                catch (Exception e)
                {
                    exceptionOnGetting = e;
                }

                if (value != null && exceptionOnGetting == null)
                {
                    GUIExpander.ExpanderControls(state, refChain, property.PropertyType, obj);
                }
            }

            GUI.contentColor = Color.white;

            if (!property.CanWrite)
            {
                GUI.enabled = false;
            }

            if (MainWindow.Instance.Config.ShowModifiers)
            {
                GUI.contentColor = MainWindow.Instance.Config.MemberTypeColor;
                GUILayout.Label("property ");

                if (!property.CanWrite)
                {
                    GUI.contentColor = MainWindow.Instance.Config.KeywordColor;
                    GUILayout.Label("const ");
                }
            }

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

            GUILayout.Label(property.PropertyType.ToString() + " ");

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

            GUIMemberName.MemberName(property, nameHighlightFrom, nameHighlightLength);

            GUI.contentColor = Color.white;
            GUILayout.Label(" = ");
            GUI.contentColor = MainWindow.Instance.Config.ValueColor;
            if (exceptionOnGetting != null)
            {
                GUI.contentColor = Color.red;
                GUILayout.Label("Exception happened when getting property value");
                GUI.contentColor = Color.white;
                GUI.enabled      = true;
                if (exceptionOnGetting.InnerException != null)
                {
                    GUIStackTrace.StackTraceButton(new StackTrace(exceptionOnGetting.InnerException, true), exceptionOnGetting.InnerException.Message);
                }

                GUILayout.FlexibleSpace();
                GUILayout.EndHorizontal();
                return;
            }

            if (!MainWindow.Instance.Config.EvaluateProperties && !state.EvaluatedProperties.Contains(refChain.UniqueId))
            {
                GUI.enabled = true;

                if (GUILayout.Button("Evaluate"))
                {
                    state.EvaluatedProperties.Add(refChain.UniqueId);
                }
            }
            else if (value == null || !TypeUtil.IsSpecialType(property.PropertyType))
            {
                if (property.CanRead)
                {
                    GUILayout.Label(value == null ? "null" : value.ToString());
                }
                else
                {
                    GUILayout.Label("(no get method)");
                }

                GUI.contentColor = Color.white;
            }
            else
            {
                try
                {
                    var newValue = GUIControls.EditorValueField(refChain.UniqueId, property.PropertyType, value);
                    if (newValue != value)
                    {
                        property.SetValue(obj, newValue, null);
                    }
                }
                catch (Exception)
                {
                    if (property.CanRead)
                    {
                        GUILayout.Label(value == null ? "null" : value.ToString());
                    }
                    else
                    {
                        GUILayout.Label("(no get method)");
                    }

                    GUI.contentColor = Color.white;
                }
            }

            GUI.enabled      = true;
            GUI.contentColor = Color.white;

            GUILayout.FlexibleSpace();

            GUIButtons.SetupCommonButtons(refChain, value, valueIndex: 0, smartType);
            object paste   = null;
            var    doPaste = property.CanWrite;

            if (doPaste)
            {
                doPaste = GUIButtons.SetupPasteButon(property.PropertyType, value, out paste);
            }

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

            GUILayout.EndHorizontal();

            if (value != null && state.ExpandedObjects.Contains(refChain.UniqueId))
            {
                GUIReflect.OnSceneTreeReflect(state, refChain, value, false);
            }

            if (doPaste)
            {
                try
                {
                    property.SetValue(obj, paste, null);
                }
                catch (Exception e)
                {
                    Logger.Warning(e.Message);
                }
            }
        }
Exemplo n.º 11
0
        public static void OnSceneTreeRecursive(GameObject modToolsGo, SceneExplorerState state, ReferenceChain refChain, GameObject obj)
        {
            if (obj == modToolsGo && !ModTools.DEBUG_MODTOOLS)
            {
                return;
            }

            if (!SceneExplorerCommon.SceneTreeCheckDepth(refChain))
            {
                return;
            }

            if (obj == null)
            {
                SceneExplorerCommon.OnSceneTreeMessage(refChain, "null");
                return;
            }

            if (obj.name == "_ModToolsInternal" && !ModTools.DEBUG_MODTOOLS)
            {
                return;
            }

            if (state.expandedGameObjects.ContainsKey(refChain))
            {
                try
                {
                    GUILayout.BeginHorizontal();
                    GUILayout.Space(ModTools.Instance.config.sceneExplorerTreeIdentSpacing * refChain.Ident);

                    if (GUILayout.Button("-", GUILayout.ExpandWidth(false)))
                    {
                        state.expandedGameObjects.Remove(refChain);
                    }

                    GUI.contentColor = ModTools.Instance.config.gameObjectColor;
                    GUILayout.Label(obj.name);
                    GUI.contentColor = Color.white;

                    GUILayout.EndHorizontal();

                    var components = obj.GetComponents(typeof(Component));

                    if (ModTools.Instance.config.sceneExplorerSortAlphabetically)
                    {
                        Array.Sort(components, (component, component1) => component.GetType().ToString().CompareTo(component1.GetType().ToString()));
                    }

                    foreach (var component in components)
                    {
                        GUIComponent.OnSceneTreeComponent(state, refChain.Add(component), component);
                    }

                    for (int i = 0; i < obj.transform.childCount; i++)
                    {
                        OnSceneTreeRecursive(modToolsGo, state, refChain.Add(obj.transform.GetChild(i)), obj.transform.GetChild(i).gameObject);
                    }
                }
                catch (Exception)
                {
                    state.expandedGameObjects.Remove(refChain);
                    throw;
                }
            }
            else
            {
                GUILayout.BeginHorizontal();
                GUILayout.Space(ModTools.Instance.config.sceneExplorerTreeIdentSpacing * refChain.Ident);

                if (GUILayout.Button("+", GUILayout.ExpandWidth(false)))
                {
                    state.expandedGameObjects.Add(refChain, true);
                }

                GUI.contentColor = ModTools.Instance.config.gameObjectColor;
                GUILayout.Label(obj.name);
                GUI.contentColor = Color.white;
                GUILayout.EndHorizontal();
            }
        }
Exemplo n.º 12
0
        public static void OnSceneTreeReflectProperty(SceneExplorerState state, ReferenceChain refChain, System.Object obj, PropertyInfo property)
        {
            if (!SceneExplorerCommon.SceneTreeCheckDepth(refChain))
            {
                return;
            }

            if (obj == null || property == null)
            {
                SceneExplorerCommon.OnSceneTreeMessage(refChain, "null");
                return;
            }

            var hash = refChain.GetHashCode().ToString();

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

            bool   propertyWasEvaluated = false;
            object value = null;

            Exception exceptionOnGetting = null;

            if (property.CanRead && ModTools.Instance.config.sceneExplorerEvaluatePropertiesAutomatically || state.evaluatedProperties.ContainsKey(refChain))
            {
                try
                {
                    value = property.GetValue(obj, null);
                    propertyWasEvaluated = true;
                }
                catch (Exception e)
                {
                    exceptionOnGetting = e;
                }

                if (value != null && exceptionOnGetting == null)
                {
                    GUIExpander.ExpanderControls(state, refChain, property.PropertyType, obj);
                }
            }

            GUI.contentColor = Color.white;

            if (!property.CanWrite)
            {
                GUI.enabled = false;
            }

            if (ModTools.Instance.config.sceneExplorerShowModifiers)
            {
                GUI.contentColor = ModTools.Instance.config.memberTypeColor;
                GUILayout.Label("property ");

                if (!property.CanWrite)
                {
                    GUI.contentColor = ModTools.Instance.config.keywordColor;
                    GUILayout.Label("const ");
                }
            }

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

            GUILayout.Label(property.PropertyType.ToString() + " ");

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

            GUILayout.Label(property.Name);

            GUI.contentColor = Color.white;
            GUILayout.Label(" = ");
            GUI.contentColor = ModTools.Instance.config.valueColor;

            if (!ModTools.Instance.config.sceneExplorerEvaluatePropertiesAutomatically && !state.evaluatedProperties.ContainsKey(refChain))
            {
                GUI.enabled = true;

                if (GUILayout.Button("Evaluate"))
                {
                    state.evaluatedProperties.Add(refChain, true);
                }
            }
            else
            {
                if (!propertyWasEvaluated && property.CanRead)
                {
                    try
                    {
                        value = property.GetValue(obj, null);
                        propertyWasEvaluated = true;
                    }
                    catch (Exception e)
                    {
                        exceptionOnGetting = e;
                    }
                }
                if (exceptionOnGetting != null)
                {
                    GUI.contentColor = Color.red;
                    GUILayout.Label("Exception happened when getting property value");
                    GUI.contentColor = Color.white;
                    GUI.enabled      = true;
                    GUIStackTrace.StackTraceButton(new StackTrace(exceptionOnGetting, true));

                    GUILayout.FlexibleSpace();
                    GUILayout.EndHorizontal();
                    return;
                }


                if (value == null || !TypeUtil.IsSpecialType(property.PropertyType))
                {
                    if (property.CanRead)
                    {
                        GUILayout.Label(value == null ? "null" : value.ToString());
                    }
                    else
                    {
                        GUILayout.Label("(no get method)");
                    }

                    GUI.contentColor = Color.white;
                }
                else
                {
                    try
                    {
                        var newValue = GUIControls.EditorValueField(refChain, hash, property.PropertyType, value);
                        if (newValue != value)
                        {
                            property.SetValue(obj, newValue, null);
                        }
                    }
                    catch (Exception)
                    {
                        if (property.CanRead)
                        {
                            GUILayout.Label(value == null ? "null" : value.ToString());
                        }
                        else
                        {
                            GUILayout.Label("(no get method)");
                        }

                        GUI.contentColor = Color.white;
                    }
                }
            }

            GUI.enabled      = true;
            GUI.contentColor = Color.white;

            GUILayout.FlexibleSpace();

            if (GUILayout.Button("Watch"))
            {
                ModTools.Instance.watches.AddWatch(refChain);
            }
            GUIButtons.SetupButtons(property.PropertyType, value, refChain);
            object paste   = null;
            var    doPaste = property.CanWrite;

            if (doPaste)
            {
                doPaste = GUIButtons.SetupPasteButon(property.PropertyType, out paste);
            }
            GUILayout.EndHorizontal();

            if (value != null && 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);
                }
            }
            if (doPaste)
            {
                try
                {
                    property.SetValue(obj, paste, null);
                }
                catch (Exception e)
                {
                    Log.Warning(e.Message);
                }
            }
        }
Exemplo n.º 13
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;
                }
            }
        }
Exemplo n.º 14
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]);
                    }
                }
            }
        }
Exemplo n.º 15
0
        public static void OnSceneReflectUnityEngineMaterial(SceneExplorerState state, ReferenceChain refChain, Material material)
        {
            if (!SceneExplorerCommon.SceneTreeCheckDepth(refChain))
            {
                return;
            }

            if (material == null)
            {
                SceneExplorerCommon.OnSceneTreeMessage(refChain, "null");
                return;
            }

            ReferenceChain oldRefChain = refChain;

            foreach (var prop in textureProps)
            {
                if (!material.HasProperty(prop))
                {
                    continue;
                }

                var value = material.GetTexture(prop);
                if (value == null)
                {
                    continue;
                }

                refChain = oldRefChain.Add(prop);

                var type = value.GetType();

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

                GUIExpander.ExpanderControls(state, refChain, type);

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

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

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

                GUILayout.Label(prop);

                GUI.contentColor = Color.white;

                GUILayout.Label(" = ");

                GUI.contentColor = ModTools.Instance.config.valueColor;
                GUILayout.Label(value.ToString());
                GUI.contentColor = Color.white;

                GUILayout.FlexibleSpace();
                GUIButtons.SetupButtons(type, value, refChain);
                object paste;
                var    doPaste = GUIButtons.SetupPasteButon(type, out paste);
                GUILayout.EndHorizontal();

                if (!TypeUtil.IsSpecialType(type) && state.expandedObjects.ContainsKey(refChain))
                {
                    GUIReflect.OnSceneTreeReflect(state, refChain, value);
                }

                if (doPaste)
                {
                    material.SetTexture(prop, (Texture)paste);
                }
            }

            foreach (string prop in colorProps)
            {
                if (!material.HasProperty(prop))
                {
                    continue;
                }

                Color value = material.GetColor(prop);
                refChain = oldRefChain.Add(prop);

                var type = value.GetType();

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

                GUIExpander.ExpanderControls(state, refChain, type);

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

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

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

                GUILayout.Label(prop);

                GUI.contentColor = Color.white;

                GUILayout.Label(" = ");
                var f = value;

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

                var propertyCopy = prop;
                GUIControls.ColorField(refChain.ToString(), "", ref f, 0.0f, null, true, true, color => { material.SetColor(propertyCopy, color); });
                if (f != value)
                {
                    material.SetColor(prop, f);
                }

                GUI.contentColor = Color.white;
                GUILayout.FlexibleSpace();
                GUIButtons.SetupButtons(type, value, refChain);
                object paste;
                var    doPaste = GUIButtons.SetupPasteButon(type, out paste);
                GUILayout.EndHorizontal();

                if (!TypeUtil.IsSpecialType(type) && state.expandedObjects.ContainsKey(refChain))
                {
                    GUIReflect.OnSceneTreeReflect(state, refChain, value);
                }
                if (doPaste)
                {
                    material.SetColor(prop, (Color)paste);
                }
            }
//            GUILayout.BeginHorizontal();
//            GUILayout.Space(ModTools.Instance.config.sceneExplorerTreeIdentSpacing * (refChain.Ident + 1));
//            GUI.contentColor = ModTools.Instance.config.typeColor;
//
//            GUILayout.Label("Shader:");
//
//            GUI.contentColor = ModTools.Instance.config.nameColor;
//
//            var shaders = Resources.FindObjectsOfTypeAll<Shader>();
//            Array.Sort(shaders, (a, b) => string.Compare(a.name, b.name, StringComparison.Ordinal));
//            var availableShaders = shaders.Select(s => s.name).ToArray();
//            var currentShader = material.shader;
//            var selectedShader = Array.IndexOf(shaders, currentShader);
//
//            var newSelectedShader = GUIComboBox.Box(selectedShader, availableShaders, "SceneExplorerShadersComboBox");
//            if (newSelectedShader != selectedShader)
//            {
//                material.shader = shaders[newSelectedShader];
//            }
//            GUILayout.FlexibleSpace();
//            GUILayout.EndHorizontal();

            GUIReflect.OnSceneTreeReflect(state, refChain, material, true);
        }
Exemplo n.º 16
0
        public static void OnSceneTreeReflectField(SceneExplorerState state, ReferenceChain refChain, object obj, FieldInfo field)
        {
            var hash = refChain.GetHashCode().ToString();

            if (!SceneExplorerCommon.SceneTreeCheckDepth(refChain))
            {
                return;
            }

            if (obj == null || field == null)
            {
                SceneExplorerCommon.OnSceneTreeMessage(refChain, "null");
                return;
            }

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

            GUI.contentColor = Color.white;

            object value = null;

            try
            {
                value = field.GetValue(obj);
            }
            catch (Exception e)
            {
                UnityEngine.Debug.LogException(e);
            }

            if (value != null)
            {
                GUIExpander.ExpanderControls(state, refChain, field.FieldType);
            }

            if (field.IsInitOnly)
            {
                GUI.enabled = false;
            }

            if (ModTools.Instance.config.sceneExplorerShowModifiers)
            {
                GUI.contentColor = ModTools.Instance.config.modifierColor;

                if (field.IsPublic)
                {
                    GUILayout.Label("public ");
                }
                else if (field.IsPrivate)
                {
                    GUILayout.Label("private ");
                }

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

                GUILayout.Label("field ");

                if (field.IsStatic)
                {
                    GUI.contentColor = ModTools.Instance.config.keywordColor;
                    GUILayout.Label("static ");
                }

                if (field.IsInitOnly)
                {
                    GUI.contentColor = ModTools.Instance.config.keywordColor;
                    GUILayout.Label("const ");
                }
            }

            GUI.contentColor = ModTools.Instance.config.typeColor;
            GUILayout.Label(field.FieldType + " ");

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

            GUILayout.Label(field.Name);

            GUI.contentColor = Color.white;
            GUI.contentColor = Color.white;
            GUILayout.Label(" = ");
            GUI.contentColor = ModTools.Instance.config.valueColor;

            if (value == null || !TypeUtil.IsSpecialType(field.FieldType))
            {
                GUILayout.Label(value?.ToString() ?? "null");
            }
            else
            {
                try
                {
                    var newValue = GUIControls.EditorValueField(refChain, hash, field.FieldType, value);
                    if (newValue != value)
                    {
                        field.SetValue(obj, newValue);
                    }
                }
                catch (Exception)
                {
                    GUILayout.Label(value.ToString());
                }
            }

            GUI.enabled      = true;
            GUI.contentColor = Color.white;

            GUILayout.FlexibleSpace();
            if (GUILayout.Button("Watch"))
            {
                ModTools.Instance.watches.AddWatch(refChain);
            }
            GUIButtons.SetupButtons(field.FieldType, value, refChain);
            object paste   = null;
            var    doPaste = !field.IsLiteral && !field.IsInitOnly;

            if (doPaste)
            {
                doPaste = GUIButtons.SetupPasteButon(field.FieldType, out paste);
            }
            GUILayout.EndHorizontal();
            if (value != null && !TypeUtil.IsSpecialType(field.FieldType) && 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);
                }
            }
            if (doPaste)
            {
                try
                {
                    field.SetValue(obj, paste);
                }
                catch (Exception e)
                {
                    Log.Warning(e.Message);
                }
            }
        }
Exemplo n.º 17
0
        public static void OnSceneTreeReflectIEnumerable(SceneExplorerState state, ReferenceChain refChain, object myProperty)
        {
            if (!SceneExplorerCommon.SceneTreeCheckDepth(refChain))
            {
                return;
            }

            var enumerable = myProperty as IEnumerable;

            if (enumerable == null)
            {
                return;
            }

            int count       = 0;
            var oldRefChain = refChain;

            foreach (var value in enumerable)
            {
                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();
                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 >= 1024)
                {
                    SceneExplorerCommon.OnSceneTreeMessage(refChain, "Array too large to display");
                    break;
                }
            }
        }
Exemplo n.º 18
0
        public static void OnSceneTreeRecursive(GameObject modToolsGo, SceneExplorerState state, ReferenceChain refChain, GameObject obj)
        {
#if !DEBUG
            if (obj == modToolsGo)
            {
                return;
            }
#endif

            if (!SceneExplorerCommon.SceneTreeCheckDepth(refChain))
            {
                return;
            }

            if (obj == null)
            {
                SceneExplorerCommon.OnSceneTreeMessage(refChain, "null");
                return;
            }

            if (state.ExpandedGameObjects.Contains(refChain.UniqueId))
            {
                try
                {
                    GUILayout.BeginHorizontal();
                    SceneExplorerCommon.InsertIndent(refChain.Indentation);

                    if (GUILayout.Button("-", GUILayout.ExpandWidth(false)))
                    {
                        state.ExpandedGameObjects.Remove(refChain.UniqueId);
                    }

                    var currentlySelected = state.CurrentRefChain?.IsSameChain(refChain) == true;
                    GUI.contentColor = currentlySelected
                        ? MainWindow.Instance.Config.SelectedComponentColor
                        : obj.activeInHierarchy ? MainWindow.Instance.Config.GameObjectColor : MainWindow.Instance.Config.DisabledComponentColor;

                    GUILayout.Label(obj.name);
                    GUI.contentColor = Color.white;

                    if (currentlySelected)
                    {
                        if (GUILayout.Button("<", GUILayout.ExpandWidth(false)))
                        {
                            state.CurrentRefChain = null;
                        }
                    }
                    else
                    {
                        if (GUILayout.Button(">", GUILayout.ExpandWidth(false)))
                        {
                            var sceneExplorer = Object.FindObjectOfType <SceneExplorer>();
                            sceneExplorer.Show(refChain, false);
                        }
                    }

                    GUILayout.EndHorizontal();

                    var gameObjects = new GameObject[obj.transform.childCount];
                    for (var i = 0; i < obj.transform.childCount; i++)
                    {
                        gameObjects[i] = obj.transform.GetChild(i).gameObject;
                    }

                    if (MainWindow.Instance.Config.SortItemsAlphabetically)
                    {
                        Array.Sort(gameObjects, (x, y) => string.CompareOrdinal(x?.name, y?.name));
                    }

                    foreach (var gameObject in gameObjects)
                    {
                        OnSceneTreeRecursive(modToolsGo, state, refChain.Add(gameObject), gameObject);
                    }

                    var components = obj.GetComponents(typeof(Component));

                    if (MainWindow.Instance.Config.SortItemsAlphabetically)
                    {
                        Array.Sort(components, (x, y) => string.CompareOrdinal(x.GetType().ToString(), y.GetType().ToString()));
                    }

                    foreach (var component in components)
                    {
                        GUIComponent.OnSceneTreeComponent(state, refChain.Add(component), component);
                    }
                }
                catch (Exception)
                {
                    state.ExpandedGameObjects.Remove(refChain.UniqueId);
                    throw;
                }
            }
            else
            {
                GUILayout.BeginHorizontal();
                SceneExplorerCommon.InsertIndent(refChain.Indentation);

                if (GUILayout.Button("+", GUILayout.ExpandWidth(false)))
                {
                    state.ExpandedGameObjects.Add(refChain.UniqueId);
                }

                var currentlySelected = state.CurrentRefChain?.IsSameChain(refChain) == true;
                GUI.contentColor = currentlySelected
                    ? MainWindow.Instance.Config.SelectedComponentColor
                    : obj.activeInHierarchy ? MainWindow.Instance.Config.GameObjectColor : MainWindow.Instance.Config.DisabledComponentColor;
                GUILayout.Label(obj.name);
                GUI.contentColor = Color.white;
                GUILayout.EndHorizontal();
            }
        }
Exemplo n.º 19
0
        public static void OnSceneTreeReflectField(SceneExplorerState state, ReferenceChain refChain, object obj, FieldInfo field, TypeUtil.SmartType smartType = TypeUtil.SmartType.Undefined, int nameHighlightFrom = -1, int nameHighlightLength = 0)
        {
            if (!SceneExplorerCommon.SceneTreeCheckDepth(refChain))
            {
                return;
            }

            if (obj == null || field == null)
            {
                SceneExplorerCommon.OnSceneTreeMessage(refChain, "null");
                return;
            }

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

            GUI.contentColor = Color.white;

            object value = null;

            try
            {
                value = field.GetValue(obj);
            }
            catch (Exception e)
            {
                Debug.LogException(e);
            }

            if (value != null)
            {
                GUIExpander.ExpanderControls(state, refChain, field.FieldType);
            }

            if (field.IsInitOnly)
            {
                GUI.enabled = false;
            }

            if (MainWindow.Instance.Config.ShowModifiers)
            {
                GUI.contentColor = MainWindow.Instance.Config.ModifierColor;

                if (field.IsPublic)
                {
                    GUILayout.Label("public ");
                }
                else if (field.IsPrivate)
                {
                    GUILayout.Label("private ");
                }

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

                GUILayout.Label("field ");

                if (field.IsStatic)
                {
                    GUI.contentColor = MainWindow.Instance.Config.KeywordColor;
                    GUILayout.Label("static ");
                }

                if (field.IsInitOnly)
                {
                    GUI.contentColor = MainWindow.Instance.Config.KeywordColor;
                    GUILayout.Label("const ");
                }
            }

            GUI.contentColor = MainWindow.Instance.Config.TypeColor;
            GUILayout.Label(field.FieldType + " ");

            GUIMemberName.MemberName(field, nameHighlightFrom, nameHighlightLength);

            GUI.contentColor = Color.white;
            GUILayout.Label(" = ");
            GUI.contentColor = MainWindow.Instance.Config.ValueColor;

            if (value == null || !TypeUtil.IsSpecialType(field.FieldType))
            {
                GUILayout.Label(value?.ToString() ?? "null");
            }
            else
            {
                try
                {
                    var newValue = GUIControls.EditorValueField(refChain.UniqueId, field.FieldType, value);
                    if (!newValue.Equals(value))
                    {
                        field.SetValue(obj, newValue);
                    }
                }
                catch (Exception)
                {
                    GUILayout.Label(value.ToString());
                }
            }

            GUI.enabled      = true;
            GUI.contentColor = Color.white;

            GUILayout.FlexibleSpace();

            GUIButtons.SetupCommonButtons(refChain, value, valueIndex: 0, smartType);
            object paste   = null;
            var    doPaste = !field.IsLiteral && !field.IsInitOnly;

            if (doPaste)
            {
                doPaste = GUIButtons.SetupPasteButon(field.FieldType, value, out paste);
            }

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

            GUILayout.EndHorizontal();
            if (value != null && !TypeUtil.IsSpecialType(field.FieldType) && state.ExpandedObjects.Contains(refChain.UniqueId))
            {
                GUIReflect.OnSceneTreeReflect(state, refChain, value, false, smartType);
            }

            if (doPaste)
            {
                try
                {
                    field.SetValue(obj, paste);
                }
                catch (Exception e)
                {
                    Logger.Warning(e.Message);
                }
            }
        }
Exemplo n.º 20
0
 protected override void HandleException(Exception ex)
 {
     Debug.LogException(ex);
     state = new SceneExplorerState();
     RefreshSceneRoots();
 }
Exemplo n.º 21
0
        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;
                }
            }
        }
Exemplo n.º 22
0
        public static void OnSceneTreeReflect(SceneExplorerState state, ReferenceChain refChain, object obj, bool rawReflection, TypeUtil.SmartType smartType = TypeUtil.SmartType.Undefined, string filter = "")
        {
            if (!SceneExplorerCommon.SceneTreeCheckDepth(refChain))
            {
                return;
            }

            if (obj == null)
            {
                SceneExplorerCommon.OnSceneTreeMessage(refChain, "null");
                return;
            }

            var type = obj.GetType();

            if (!rawReflection)
            {
                if (!type.IsValueType && state.PreventCircularReferences.Contains(obj))
                {
                    try
                    {
                        GUI.contentColor = Color.yellow;
                        SceneExplorerCommon.OnSceneTreeMessage(refChain, "Circular reference detected");
                    }
                    finally
                    {
                        GUI.contentColor = Color.white;
                    }

                    return;
                }

                state.PreventCircularReferences.Add(obj);

                if (type == typeof(Transform))
                {
                    GUITransform.OnSceneTreeReflectUnityEngineTransform(refChain, (Transform)obj);
                    return;
                }

                if (TypeUtil.IsList(obj))
                {
                    GUIList.OnSceneTreeReflectIList(state, refChain, obj, smartType);
                    return;
                }

                if (TypeUtil.IsCollection(obj))
                {
                    GUICollection.OnSceneTreeReflectICollection(state, refChain, obj, smartType);
                    return;
                }

                if (TypeUtil.IsEnumerable(obj))
                {
                    GUIEnumerable.OnSceneTreeReflectIEnumerable(state, refChain, obj, smartType);
                    return;
                }

                if (type == typeof(Material))
                {
                    GUIMaterial.OnSceneReflectUnityEngineMaterial(state, refChain, (Material)obj);
                    return;
                }

                if (type == typeof(Mesh) && !((Mesh)obj).isReadable)
                {
                    SceneExplorerCommon.OnSceneTreeMessage(refChain, "Mesh is not readable");
                    return;
                }
            }

            var members = TypeUtil.GetAllMembers(type, MainWindow.Instance.Config.ShowInheritedMembers);

            if (MainWindow.Instance.Config.SortItemsAlphabetically)
            {
                Array.Sort(members, (x, y) => string.CompareOrdinal(x.ReflectionInfo.Name, y.ReflectionInfo.Name));
            }

            var matchingMembers = 0;

            foreach (var member in members)
            {
                var filterMatchFrom = -1;
                if (!filter.IsNullOrEmpty() && (filterMatchFrom = member.ReflectionInfo.Name.IndexOf(filter, StringComparison.OrdinalIgnoreCase)) < 0)
                {
                    continue;
                }

                matchingMembers++;
                switch (member.ReflectionInfo.MemberType)
                {
                case MemberTypes.Field when MainWindow.Instance.Config.ShowFields:
                {
                    var field = (FieldInfo)member.ReflectionInfo;

                    if (field.IsLiteral && !field.IsInitOnly && !MainWindow.Instance.Config.ShowConsts)
                    {
                        continue;
                    }

                    try
                    {
                        GUIField.OnSceneTreeReflectField(state, refChain.Add(field), obj, field, TypeUtil.OverrideSmartType(member.DetectedType, field.Name, obj), filterMatchFrom, filter.Length);
                    }
                    catch (Exception ex)
                    {
                        SceneExplorerCommon.OnSceneTreeMessage(refChain, $"Exception when fetching field \"{field.Name}\" - {ex.Message}\n{ex.StackTrace}");
                    }

                    break;
                }

                case MemberTypes.Property when MainWindow.Instance.Config.ShowProperties:
                {
                    var property = (PropertyInfo)member.ReflectionInfo;
                    if (property.GetIndexParameters().Length > 0)
                    {
                        continue;     // TODO: add support for indexers
                    }

                    try
                    {
                        GUIProperty.OnSceneTreeReflectProperty(state, refChain.Add(property), obj, property, TypeUtil.OverrideSmartType(member.DetectedType, property.Name, obj), filterMatchFrom, filter.Length);
                    }
                    catch (Exception ex)
                    {
                        SceneExplorerCommon.OnSceneTreeMessage(refChain, $"Exception when fetching property \"{property.Name}\" - {ex.Message}\n{ex.StackTrace}");
                    }

                    break;
                }

                case MemberTypes.Method when MainWindow.Instance.Config.ShowMethods:
                {
                    var method = (MethodInfo)member.ReflectionInfo;

                    try
                    {
                        GUIMethod.OnSceneTreeReflectMethod(refChain.Add(method), obj, method, filterMatchFrom, filter.Length);
                    }
                    catch (Exception ex)
                    {
                        SceneExplorerCommon.OnSceneTreeMessage(refChain, $"Exception when fetching method \"{method.Name}\" - {ex.Message}");
                    }

                    break;
                }
                }
            }

            if (filter.IsNullOrEmpty() || members.Length <= 0 || matchingMembers != 0)
            {
                return;
            }

            GUI.contentColor = Color.yellow;
            SceneExplorerCommon.OnSceneTreeMessage(refChain, "No members matching the search term found!");
            GUI.contentColor = Color.white;
        }
Exemplo n.º 23
0
        public static void OnSceneReflectUnityEngineMaterial(
            SceneExplorerState state, ReferenceChain refChain, Material material)
        {
            Debug.Log($"OnSceneReflectUnityEngineMaterial(): " + System.Environment.StackTrace);

            if (!SceneExplorerCommon.SceneTreeCheckDepth(refChain))
            {
                return;
            }

            if (material == null)
            {
                SceneExplorerCommon.OnSceneTreeMessage(refChain, "null");
                return;
            }

            GUILayout.BeginHorizontal();
            GUI.contentColor = Color.white;
            GUILayout.Label("Special Properties:");
            GUILayout.EndHorizontal();

            foreach (var prop in ShaderUtil.GetTextureProperties())
            {
                if (!material.HasProperty(prop))
                {
                    continue;
                }

                var value = material.GetTexture(prop);
                if (value == null)
                {
                    continue;
                }

                var newRefChain = refChain.Add(prop);

                var type = value.GetType();

                GUILayout.BeginHorizontal(GUIWindow.HighlightStyle);
                SceneExplorerCommon.InsertIndent(newRefChain.Indentation + 1);

                GUIExpander.ExpanderControls(state, newRefChain, type);

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

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

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

                GUILayout.Label(prop);

                GUI.contentColor = Color.white;

                GUILayout.Label(" = ");

                GUI.contentColor = MainWindow.Instance.Config.ValueColor;
                GUILayout.Label(value.ToString());
                GUI.contentColor = Color.white;

                GUILayout.FlexibleSpace();
                GUIButtons.SetupCommonButtons(newRefChain, value, valueIndex: 0);
                var doPaste = GUIButtons.SetupPasteButon(type, value, out var paste);
                if (value != null)
                {
                    GUIButtons.SetupJumpButton(value, newRefChain);
                }

                GUILayout.EndHorizontal();

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

                if (doPaste)
                {
                    material.SetTexture(prop, (Texture)paste);
                }
            }

            foreach (var prop in ShaderUtil.GetColorProperties())
            {
                if (!material.HasProperty(prop))
                {
                    continue;
                }

                var value       = material.GetColor(prop);
                var newRefChain = refChain.Add(prop);

                var type = value.GetType();

                GUILayout.BeginHorizontal();
                SceneExplorerCommon.InsertIndent(newRefChain.Indentation + 1);

                GUIExpander.ExpanderControls(state, newRefChain, type);

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

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

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

                GUILayout.Label(prop);

                GUI.contentColor = Color.white;

                GUILayout.Label(" = ");

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

                var newColor = GUIControls.CustomValueField(newRefChain.UniqueId, string.Empty, GUIControls.PresentColor, value);
                if (newColor != value)
                {
                    material.SetColor(prop, newColor);
                }

                GUI.contentColor = Color.white;
                GUILayout.FlexibleSpace();
                GUIButtons.SetupCommonButtons(newRefChain, value, valueIndex: 0);
                var doPaste = GUIButtons.SetupPasteButon(type, value, out var paste);

                GUIButtons.SetupJumpButton(value, newRefChain);

                GUILayout.EndHorizontal();

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

                if (doPaste)
                {
                    material.SetColor(prop, (Color)paste);
                }
            }

            foreach (var prop in ShaderUtil.GetFloatProperties())
            {
                if (!material.HasProperty(prop))
                {
                    continue;
                }

                var value       = material.GetFloat(prop);
                var newRefChain = refChain.Add(prop);

                var type = value.GetType();

                GUILayout.BeginHorizontal();
                SceneExplorerCommon.InsertIndent(newRefChain.Indentation + 1);

                GUIExpander.ExpanderControls(state, newRefChain, type);

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

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

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

                GUILayout.Label(prop);

                GUI.contentColor = Color.white;

                GUILayout.Label(" = ");

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

                var newValue = GUIControls.NumericValueField(newRefChain.UniqueId, string.Empty, value);
                if (newValue != value)
                {
                    material.SetFloat(prop, newValue);
                }

                GUI.contentColor = Color.white;
                GUILayout.FlexibleSpace();
                GUIButtons.SetupCommonButtons(newRefChain, value, 0);
                var doPaste = GUIButtons.SetupPasteButon(type, value, out var paste);
                GUIButtons.SetupJumpButton(value, newRefChain);

                GUILayout.EndHorizontal();

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

                if (doPaste)
                {
                    material.SetColor(prop, (Color)paste);
                }
            }

            foreach (var prop in ShaderUtil.GetVectorProperties())
            {
                if (!material.HasProperty(prop))
                {
                    continue;
                }

                var value       = material.GetVector(prop);
                var newRefChain = refChain.Add(prop);

                var type = value.GetType();

                GUILayout.BeginHorizontal();
                SceneExplorerCommon.InsertIndent(newRefChain.Indentation + 1);

                GUIExpander.ExpanderControls(state, newRefChain, type);

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

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

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

                GUILayout.Label(prop);

                GUI.contentColor = Color.white;

                GUILayout.Label(" = ");

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

                var newValue = GUIControls.PresentVector4(newRefChain.UniqueId, value);
                if (newValue != value)
                {
                    material.SetVector(prop, newValue);
                }

                GUI.contentColor = Color.white;
                GUILayout.FlexibleSpace();
                GUIButtons.SetupCommonButtons(newRefChain, value, valueIndex: 0);
                var doPaste = GUIButtons.SetupPasteButon(type, value, out var paste);

                GUIButtons.SetupJumpButton(value, newRefChain);

                GUILayout.EndHorizontal();

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

                if (doPaste)
                {
                    material.SetColor(prop, (Color)paste);
                }
            }

            var shaderKeywords = material.shaderKeywords;

            if (shaderKeywords != null && shaderKeywords.Length > 0)
            {
                var valueTyoe = shaderKeywords.GetType();

                GUILayout.BeginHorizontal();
                SceneExplorerCommon.InsertIndent(refChain.Indentation + 2);

                GUI.contentColor = MainWindow.Instance.Config.TypeColor;
                GUILayout.Label(valueTyoe.ToString() + " ");

                GUI.contentColor = MainWindow.Instance.Config.NameColor;
                GUILayout.Label("Shader keywords ");

                GUI.contentColor = Color.white;
                GUILayout.Label(" = ");

                GUI.contentColor = MainWindow.Instance.Config.ValueColor;
                GUILayout.Label(string.Join(", ", shaderKeywords));

                GUILayout.FlexibleSpace();
                GUILayout.EndHorizontal();
            }

            GUIReflect.OnSceneTreeReflect(state, refChain, material, true);
        }