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); } } }
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); } } }
private void DrawConsole() { userNotifications = UserNotifications.GetNotifications(); consoleArea.Begin(); consoleScrollPosition = GUILayout.BeginScrollView(consoleScrollPosition); foreach (var item in userNotifications) { GUILayout.BeginHorizontal(GUI.skin.box); GUI.contentColor = Color.cyan; GUILayout.Label(item.Value); GUI.contentColor = Color.white; if (GUILayout.Button("Hide")) { UserNotifications.HideNotification(item.Key); } GUILayout.EndHorizontal(); } ConsoleMessage[] messages = null; lock (historyLock) { messages = history.ToArray(); } foreach (var item in messages) { GUILayout.BeginHorizontal(GUI.skin.box); var msg = Config.ConsoleFormatString.Replace("{{type}}", item.Type.ToString()) .Replace("{{caller}}", item.Caller) .Replace("{{message}}", item.Message); switch (item.Type) { case LogType.Log: GUI.contentColor = Config.ConsoleMessageColor; break; case LogType.Warning: GUI.contentColor = Config.ConsoleWarningColor; break; case LogType.Error: GUI.contentColor = Config.ConsoleErrorColor; break; case LogType.Assert: case LogType.Exception: GUI.contentColor = Config.ConsoleExceptionColor; break; } GUILayout.Label(msg); GUILayout.FlexibleSpace(); if (item.Count > 1) { GUI.contentColor = orangeColor; if (item.Count > 1024) { GUI.contentColor = Color.red; } GUILayout.Label(item.Count.ToString(), GUI.skin.box); } else { GUILayout.Label(string.Empty); } GUI.contentColor = Color.white; var stackTrace = item.Trace; if (stackTrace != null) { GUIStackTrace.StackTraceButton(stackTrace); } GUILayout.EndHorizontal(); } GUILayout.EndScrollView(); consoleArea.End(); }