protected override void DrawWindow() { watchesScroll = GUILayout.BeginScrollView(watchesScroll); foreach (var watch in watches.ToArray()) { if (watch == null) { continue; } GUILayout.BeginHorizontal(); try { var type = GetWatchType(watch); GUI.contentColor = Config.TypeColor; GUILayout.Label(type.ToString()); GUI.contentColor = Config.NameColor; GUILayout.Label(watch.ToString()); GUI.contentColor = Color.white; GUILayout.Label(" = "); GUI.enabled = false; var value = watch.Evaluate(); GUI.contentColor = Config.ValueColor; if (value == null || !TypeUtil.IsSpecialType(type)) { GUILayout.Label(value == null ? "null" : value.ToString()); } else { try { GUIControls.EditorValueField("watch." + watch, type, value); } catch { GUILayout.Label(value.ToString()); } } GUI.contentColor = Color.white; GUI.enabled = true; GUILayout.FlexibleSpace(); if (value != null) { var smartType = TypeUtil.OverrideSmartType(TypeUtil.DetectSmartType(watch.LastItemName, value.GetType()), watch.LastItemName, watch.SubChain(watch.Length - 1).Evaluate()); GUIButtons.SetupSmartShowButtons(value, smartType); // TODO: get from cache } if (GUILayout.Button("^")) { var sceneExplorer = FindObjectOfType <SceneExplorer>(); sceneExplorer.Show(watch.SubChain(watch.Length - 1)); } if (value != null) { GUIButtons.SetupJumpButton(value, watch); } if (GUILayout.Button("x", GUILayout.Width(24))) { RemoveWatch(watch); } } catch (Exception e) { Debug.LogException(e); } GUILayout.EndHorizontal(); } GUILayout.EndScrollView(); }
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); } } }
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); } } }
public static void OnSceneTreeReflectICollection(SceneExplorerState state, ReferenceChain refChain, object myProperty, TypeUtil.SmartType elementSmartType = TypeUtil.SmartType.Undefined) { if (!SceneExplorerCommon.SceneTreeCheckDepth(refChain)) { return; } if (!(myProperty is ICollection collection)) { return; } var oldRefChain = refChain; var collectionSize = collection.Count; if (collectionSize == 0) { GUILayout.BeginHorizontal(); GUI.contentColor = Color.yellow; GUILayout.Label("Collection is empty!"); GUI.contentColor = Color.white; GUILayout.FlexibleSpace(); GUILayout.EndHorizontal(); return; } var collectionItemType = collection.GetType().GetElementType(); var flagsField = collectionItemType?.GetField("m_flags"); var flagIsEnum = flagsField?.FieldType.IsEnum == true && Type.GetTypeCode(flagsField.FieldType) == TypeCode.Int32; GUICollectionNavigation.SetUpCollectionNavigation("Collection", state, refChain, oldRefChain, collectionSize, out var arrayStart, out var arrayEnd); uint count = 0; foreach (var value in collection) { if (count < arrayStart) { count++; continue; } refChain = oldRefChain.Add(count); GUILayout.BeginHorizontal(GUIWindow.HighlightStyle); SceneExplorerCommon.InsertIndent(refChain.Indentation); var isNullOrEmpty = value == null || flagIsEnum && Convert.ToInt32(flagsField.GetValue(value)) == 0; var type = value?.GetType() ?? collectionItemType; if (type != null) { if (!isNullOrEmpty) { GUIExpander.ExpanderControls(state, refChain, type); } GUI.contentColor = MainWindow.Instance.Config.TypeColor; GUILayout.Label(type.ToString() + " "); } GUI.contentColor = MainWindow.Instance.Config.NameColor; GUILayout.Label($"{oldRefChain.LastItemName}.[{count}]"); GUI.contentColor = Color.white; GUILayout.Label(" = "); GUI.contentColor = MainWindow.Instance.Config.ValueColor; GUILayout.Label(value == null ? "null" : isNullOrEmpty ? "empty" : value.ToString()); GUI.contentColor = Color.white; GUILayout.FlexibleSpace(); if (!isNullOrEmpty) { GUIButtons.SetupCommonButtons(refChain, value, count, elementSmartType); } if (value != null) { GUIButtons.SetupJumpButton(value, refChain); } GUILayout.EndHorizontal(); if (!isNullOrEmpty && !TypeUtil.IsSpecialType(type) && state.ExpandedObjects.Contains(refChain.UniqueId)) { GUIReflect.OnSceneTreeReflect(state, refChain, value, false); } count++; if (count > arrayEnd) { break; } } }
public static void 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); }