/// <summary> /// Displays a value within category /// </summary> /// <param name="_category">Category name</param> /// <param name="_displayName">Display name</param> /// <param name="_value">Display value</param> public static void Log(string _category, string _displayName, object _value) { #if UNITY_EDITOR ObserverEntry newEntry = new ObserverEntry(_displayName, _value); AddEntry(_category, newEntry); #endif }
/// <summary> /// Adds a button to update it with a given value /// </summary> /// <param name="_category">Category name</param> /// <param name="_displayName">Display name</param> /// <param name="_value">Initial value</param> /// <param name="_valueCallback">Callback</param> public static void Value(string _category, string _displayName, object _value, Action <object> _valueCallback) { #if UNITY_EDITOR ObserverEntry newEntry = new ObserverEntry(_displayName, _value, _valueCallback); AddEntry(_category, newEntry); #endif }
/// <summary> /// Adds an empty seperator /// </summary> /// <param name="_category">Category of the seperator</param> public static void Seperator(string _category) { #if UNITY_EDITOR ObserverEntry newEntry = new ObserverEntry(); AddEntry(_category, newEntry); #endif }
/// <summary> /// Adds a header /// </summary> /// <param name="_category">Category of the header</param> /// <param name="_displayName">Title</param> public static void Header(string _category, string _displayName) { #if UNITY_EDITOR ObserverEntry newEntry = new ObserverEntry(_displayName); AddEntry(_category, newEntry); #endif }
private static void AddEntry(string _category, ObserverEntry _entry) { #if UNITY_EDITOR KeyValuePair <ObserverCategory, List <ObserverEntry> > kvp = (from k in Entries.AsEnumerable() where k.Key.CategoryName == _category select k).FirstOrDefault(); // If we have category if (kvp.Key != null) { // Get Entry list from Corresponding category List <ObserverEntry> entryList = kvp.Value; // Try to find existing Entry ObserverEntry entry = entryList.FirstOrDefault(name => name.EntryName == _entry.EntryName); // Add new or update existing entry if (entry == null) { entryList.Add(_entry); } else { entry.Value = _entry.Value; } } else { Entries.Add(new ObserverCategory(_category), new List <ObserverEntry> { _entry }); } #endif }
private void ShowEntryValue(ObserverEntry entry) { EditorGUILayout.BeginHorizontal(); EditorGUILayout.LabelField(entry.EntryName, ObserverStyles.EntryValueTitleLabel); EditorGUILayout.LabelField(entry.Value.ToString(), ObserverStyles.EntryValueLabel); EditorGUILayout.EndHorizontal(); }
/// <summary> /// Adds a button to call action /// </summary> /// <param name="_category">Category name</param> /// <param name="_displayName">Display name</param> /// <param name="_callback">Callback</param> public static void Button(string _category, string _displayName, Action _callback) { #if UNITY_EDITOR // ObserverEntry newEntry = new ObserverEntry(_displayName, _callback, true); ObserverEntry newEntry = new ObserverEntry(_displayName, _callback); AddEntry(_category, newEntry); #endif }
private void ShowEntryButton(ObserverEntry entry) { if (GUILayout.Button(entry.EntryName, ObserverStyles.EntryActionButton)) { if (entry.Callback != null) { entry.Callback.Invoke(); } } }
private void ShowEntryValueButton(ObserverEntry entry) { EditorGUILayout.BeginHorizontal(); EditorGUILayout.LabelField(entry.EntryName, ObserverStyles.EntryValueLabel, GUILayout.Width(220)); bool isLocked = false; switch (entry.EntryValueType) { case ObserverEntryType.String: entry.CachedValue = EditorGUILayout.TextField((string)entry.CachedValue, ObserverStyles.EntryInputField); break; case ObserverEntryType.Boolean: entry.CachedValue = EditorGUILayout.ToggleLeft("", (bool)entry.CachedValue); break; case ObserverEntryType.Integer: entry.CachedValue = EditorGUILayout.IntField((int)entry.CachedValue, ObserverStyles.EntryInputField); break; case ObserverEntryType.Float: entry.CachedValue = EditorGUILayout.FloatField((float)entry.CachedValue, ObserverStyles.EntryInputField); break; case ObserverEntryType.Double: entry.CachedValue = EditorGUILayout.DoubleField((double)entry.CachedValue, ObserverStyles.EntryInputField); break; case ObserverEntryType.Vector2: entry.CachedValue = EditorGUILayout.Vector2Field("", (Vector2)entry.CachedValue); break; case ObserverEntryType.Vector3: entry.CachedValue = EditorGUILayout.Vector3Field("", (Vector3)entry.CachedValue); break; case ObserverEntryType.Color: entry.CachedValue = EditorGUILayout.ColorField("", (Color)entry.CachedValue); break; case ObserverEntryType.Enum: entry.CachedValue = EditorGUILayout.EnumPopup((System.Enum)entry.CachedValue); break; case ObserverEntryType.None: isLocked = true; EditorGUILayout.LabelField("Unsupported Type", ObserverStyles.EntryValueLabel); break; } EditorGUI.BeginDisabledGroup(isLocked); if (GUILayout.Button("Update", ObserverStyles.EntryActionButton)) { if (entry.ValueCallback != null) { entry.Value = entry.CachedValue; entry.ValueCallback.Invoke(entry.CachedValue); } } EditorGUI.EndDisabledGroup(); EditorGUILayout.EndHorizontal(); }
private void ShowEntrySeperator(ObserverEntry entry) { EditorGUILayout.LabelField(entry.EntryName, ObserverStyles.EntrySeperator); }