Julien Ignace
8 年前
当前提交
20413141
共有 25 个文件被更改,包括 713 次插入 和 594 次删除
-
2Assets/ScriptableRenderPipeline/Core/Camera/CameraSwitcher.cs
-
63Assets/ScriptableRenderPipeline/Core/Debugging/DebugMenu.cs
-
7Assets/ScriptableRenderPipeline/Core/Debugging/DebugMenuItemUI.cs
-
69Assets/ScriptableRenderPipeline/Core/Debugging/DebugMenuManager.cs
-
3Assets/ScriptableRenderPipeline/Core/Debugging/Editor/DebugMenuEditor.cs
-
14Assets/ScriptableRenderPipeline/HDRenderPipeline/Debug/DebugDisplay.cs
-
238Assets/ScriptableRenderPipeline/HDRenderPipeline/Editor/HDRenderPipelineInspector.cs
-
20Assets/ScriptableRenderPipeline/HDRenderPipeline/HDRenderPipeline.asset
-
325Assets/ScriptableRenderPipeline/Core/Debugging/DebugItemHandler.cs
-
143Assets/ScriptableRenderPipeline/Core/Debugging/DebugMenuState.cs
-
12Assets/ScriptableRenderPipeline/Core/Debugging/DebugMenuState.cs.meta
-
9Assets/ScriptableRenderPipeline/Core/Debugging/Serialization.meta
-
10Assets/ScriptableRenderPipeline/Core/Debugging/Serialization/DebugItemStateBool.cs
-
12Assets/ScriptableRenderPipeline/Core/Debugging/Serialization/DebugItemStateBool.cs.meta
-
10Assets/ScriptableRenderPipeline/Core/Debugging/Serialization/DebugItemStateColor.cs
-
12Assets/ScriptableRenderPipeline/Core/Debugging/Serialization/DebugItemStateColor.cs.meta
-
10Assets/ScriptableRenderPipeline/Core/Debugging/Serialization/DebugItemStateFloat.cs
-
12Assets/ScriptableRenderPipeline/Core/Debugging/Serialization/DebugItemStateFloat.cs.meta
-
10Assets/ScriptableRenderPipeline/Core/Debugging/Serialization/DebugItemStateInt.cs
-
12Assets/ScriptableRenderPipeline/Core/Debugging/Serialization/DebugItemStateInt.cs.meta
-
10Assets/ScriptableRenderPipeline/Core/Debugging/Serialization/DebugItemStateUInt.cs
-
12Assets/ScriptableRenderPipeline/Core/Debugging/Serialization/DebugItemStateUInt.cs.meta
-
292Assets/ScriptableRenderPipeline/Core/Debugging/DebugItemDrawer.cs
-
0/Assets/ScriptableRenderPipeline/Core/Debugging/DebugItemHandler.cs.meta
|
|||
using System.Collections; |
|||
using System.Collections.Generic; |
|||
using UnityEngine; |
|||
using System; |
|||
|
|||
#if UNITY_EDITOR
|
|||
using UnityEditor; |
|||
#endif
|
|||
|
|||
namespace UnityEngine.Experimental.Rendering |
|||
{ |
|||
public abstract class DebugItemHandler |
|||
{ |
|||
protected DebugMenuItem m_MenuItem = null; |
|||
|
|||
public void SetDebugMenuItem(DebugMenuItem item) |
|||
{ |
|||
m_MenuItem = item; |
|||
} |
|||
|
|||
// Method user needs to override for specific value clamping.
|
|||
public virtual void ClampValues(Func<object> getter, Action<object> setter) {} |
|||
// Method that will create UI items for runtime debug menu.
|
|||
public abstract DebugMenuItemUI BuildGUI(GameObject parent); |
|||
// Method users need to override for editor specific UI
|
|||
public abstract bool OnEditorGUI(); |
|||
// Method users need to override for specific serialization of custom types.
|
|||
public abstract DebugMenuItemState CreateDebugMenuItemState(); |
|||
} |
|||
|
|||
// This is the default debug item handler that handles all basic types.
|
|||
public class DefaultDebugItemHandler |
|||
: DebugItemHandler |
|||
{ |
|||
bool m_IsInitialized = false; |
|||
|
|||
// Label for simple GUI items
|
|||
protected GUIContent m_Label; |
|||
|
|||
// Values and strings for Enum items
|
|||
protected List<GUIContent> m_EnumStrings = null; |
|||
protected List<int> m_EnumValues = null; |
|||
|
|||
public void Initialize() |
|||
{ |
|||
if (m_IsInitialized) |
|||
return; |
|||
|
|||
m_Label = new GUIContent(m_MenuItem.name); |
|||
Type itemType = m_MenuItem.GetItemType(); |
|||
if(itemType.BaseType == typeof(System.Enum)) |
|||
{ |
|||
Array arr = Enum.GetValues(itemType); |
|||
m_EnumStrings = new List<GUIContent>(arr.Length); |
|||
m_EnumValues = new List<int>(arr.Length); |
|||
|
|||
foreach(var value in arr) |
|||
{ |
|||
m_EnumStrings.Add(new GUIContent(value.ToString())); |
|||
m_EnumValues.Add((int)value); |
|||
} |
|||
} |
|||
} |
|||
|
|||
public override DebugMenuItemState CreateDebugMenuItemState() |
|||
{ |
|||
DebugMenuItemState newItemState = null; |
|||
if (m_MenuItem.GetItemType() == typeof(bool)) |
|||
{ |
|||
newItemState = ScriptableObject.CreateInstance<DebugItemStateBool>(); |
|||
} |
|||
else if (m_MenuItem.GetItemType() == typeof(int)) |
|||
{ |
|||
newItemState = ScriptableObject.CreateInstance<DebugItemStateInt>(); |
|||
} |
|||
else if (m_MenuItem.GetItemType() == typeof(uint)) |
|||
{ |
|||
newItemState = ScriptableObject.CreateInstance<DebugItemStateUInt>(); |
|||
} |
|||
else if (m_MenuItem.GetItemType() == typeof(float)) |
|||
{ |
|||
newItemState = ScriptableObject.CreateInstance<DebugItemStateFloat>(); |
|||
} |
|||
else if (m_MenuItem.GetItemType() == typeof(Color)) |
|||
{ |
|||
newItemState = ScriptableObject.CreateInstance<DebugItemStateColor>(); |
|||
} |
|||
else if (m_MenuItem.GetItemType().BaseType == typeof(System.Enum)) |
|||
{ |
|||
newItemState = ScriptableObject.CreateInstance<DebugItemStateInt>(); // Need to be serialized as int. For some reason serialization of the Enum directly just fails...
|
|||
} |
|||
|
|||
return newItemState; |
|||
} |
|||
|
|||
public override DebugMenuItemUI BuildGUI(GameObject parent) |
|||
{ |
|||
Initialize(); |
|||
|
|||
DebugMenuItemUI newItemUI = null; |
|||
if (m_MenuItem.GetItemType() == typeof(bool)) |
|||
{ |
|||
newItemUI = new DebugMenuBoolItemUI(parent, m_MenuItem, m_Label.text); |
|||
} |
|||
else if (m_MenuItem.GetItemType() == typeof(int)) |
|||
{ |
|||
newItemUI = new DebugMenuIntItemUI(parent, m_MenuItem, m_Label.text); |
|||
} |
|||
else if (m_MenuItem.GetItemType() == typeof(uint)) |
|||
{ |
|||
newItemUI = new DebugMenuUIntItemUI(parent, m_MenuItem, m_Label.text); |
|||
} |
|||
else if (m_MenuItem.GetItemType() == typeof(float)) |
|||
{ |
|||
newItemUI = new DebugMenuFloatItemUI(parent, m_MenuItem, m_Label.text); |
|||
} |
|||
else if (m_MenuItem.GetItemType() == typeof(Color)) |
|||
{ |
|||
newItemUI = new DebugMenuColorItemUI(parent, m_MenuItem, m_Label.text); |
|||
} |
|||
else if (m_MenuItem.GetItemType().BaseType == typeof(System.Enum)) |
|||
{ |
|||
newItemUI = new DebugMenuEnumItemUI(parent, m_MenuItem, m_Label.text, m_EnumStrings.ToArray(), m_EnumValues.ToArray()); |
|||
} |
|||
|
|||
return newItemUI; |
|||
} |
|||
|
|||
#if UNITY_EDITOR
|
|||
bool DrawBoolItem() |
|||
{ |
|||
bool value = (bool)m_MenuItem.GetValue(); |
|||
|
|||
EditorGUI.BeginChangeCheck(); |
|||
value = EditorGUILayout.Toggle(m_Label, value); |
|||
if (EditorGUI.EndChangeCheck()) |
|||
{ |
|||
m_MenuItem.SetValue(value); |
|||
return true; |
|||
} |
|||
|
|||
return false; |
|||
} |
|||
|
|||
bool DrawIntItem() |
|||
{ |
|||
int value = (int)m_MenuItem.GetValue(); |
|||
EditorGUI.BeginChangeCheck(); |
|||
value = EditorGUILayout.IntField(m_Label, value); |
|||
if (EditorGUI.EndChangeCheck()) |
|||
{ |
|||
m_MenuItem.SetValue(value); |
|||
return true; |
|||
} |
|||
|
|||
return false; |
|||
} |
|||
|
|||
bool DrawUIntItem() |
|||
{ |
|||
int value = (int)(uint)m_MenuItem.GetValue(); |
|||
EditorGUI.BeginChangeCheck(); |
|||
value = EditorGUILayout.IntField(m_Label, value); |
|||
if (EditorGUI.EndChangeCheck()) |
|||
{ |
|||
value = System.Math.Max(0, value); |
|||
m_MenuItem.SetValue((uint)value); |
|||
return true; |
|||
} |
|||
|
|||
return false; |
|||
} |
|||
|
|||
bool DrawFloatItem() |
|||
{ |
|||
float value = (float)m_MenuItem.GetValue(); |
|||
EditorGUI.BeginChangeCheck(); |
|||
value = EditorGUILayout.FloatField(m_Label, value); |
|||
if (EditorGUI.EndChangeCheck()) |
|||
{ |
|||
m_MenuItem.SetValue(value); |
|||
return true; |
|||
} |
|||
|
|||
return false; |
|||
} |
|||
|
|||
bool DrawColorItem() |
|||
{ |
|||
EditorGUI.BeginChangeCheck(); |
|||
Color value = EditorGUILayout.ColorField(m_Label, (Color)m_MenuItem.GetValue()); |
|||
if (EditorGUI.EndChangeCheck()) |
|||
{ |
|||
m_MenuItem.SetValue(value); |
|||
return true; |
|||
} |
|||
|
|||
return false; |
|||
} |
|||
|
|||
bool DrawEnumItem() |
|||
{ |
|||
EditorGUI.BeginChangeCheck(); |
|||
int value = EditorGUILayout.IntPopup(m_Label, (int)m_MenuItem.GetValue(), m_EnumStrings.ToArray(), m_EnumValues.ToArray()); |
|||
if (EditorGUI.EndChangeCheck()) |
|||
{ |
|||
m_MenuItem.SetValue(value); |
|||
return true; |
|||
} |
|||
|
|||
return false; |
|||
} |
|||
|
|||
public override bool OnEditorGUI() |
|||
{ |
|||
Initialize(); |
|||
|
|||
if (m_MenuItem.readOnly) |
|||
{ |
|||
EditorGUILayout.LabelField(m_Label, new GUIContent(m_MenuItem.GetValue().ToString())); |
|||
return false; |
|||
} |
|||
|
|||
if (m_MenuItem.GetItemType() == typeof(bool)) |
|||
{ |
|||
return DrawBoolItem(); |
|||
} |
|||
else if (m_MenuItem.GetItemType() == typeof(int)) |
|||
{ |
|||
return DrawIntItem(); |
|||
} |
|||
else if(m_MenuItem.GetItemType() == typeof(uint)) |
|||
{ |
|||
return DrawUIntItem(); |
|||
} |
|||
else if (m_MenuItem.GetItemType() == typeof(float)) |
|||
{ |
|||
return DrawFloatItem(); |
|||
} |
|||
else if (m_MenuItem.GetItemType() == typeof(Color)) |
|||
{ |
|||
return DrawColorItem(); |
|||
} |
|||
else if (m_MenuItem.GetItemType().BaseType == typeof(System.Enum)) |
|||
{ |
|||
return DrawEnumItem(); |
|||
} |
|||
|
|||
return false; |
|||
} |
|||
#endif
|
|||
} |
|||
|
|||
public class DebugItemHandlerFloatMinMax |
|||
: DefaultDebugItemHandler |
|||
{ |
|||
float m_Min = 0.0f; |
|||
float m_Max = 1.0f; |
|||
public DebugItemHandlerFloatMinMax(float min, float max) |
|||
{ |
|||
m_Min = min; |
|||
m_Max = max; |
|||
} |
|||
|
|||
public override void ClampValues(Func<object> getter, Action<object> setter) |
|||
{ |
|||
setter(Mathf.Clamp((float)getter(), m_Min, m_Max)); |
|||
} |
|||
|
|||
#if UNITY_EDITOR
|
|||
public override bool OnEditorGUI() |
|||
{ |
|||
Initialize(); |
|||
|
|||
EditorGUI.BeginChangeCheck(); |
|||
float value = EditorGUILayout.Slider(m_MenuItem.name, (float)m_MenuItem.GetValue(), m_Min, m_Max); |
|||
if (EditorGUI.EndChangeCheck()) |
|||
{ |
|||
m_MenuItem.SetValue(value); |
|||
return true; |
|||
} |
|||
|
|||
return false; |
|||
} |
|||
#endif
|
|||
} |
|||
|
|||
public class DebugItemHandlerIntEnum |
|||
: DefaultDebugItemHandler |
|||
{ |
|||
GUIContent[] m_IntEnumStrings = null; |
|||
int[] m_IntEnumValues = null; |
|||
|
|||
public DebugItemHandlerIntEnum(GUIContent[] enumStrings, int[] enumValues) |
|||
{ |
|||
m_IntEnumStrings = enumStrings; |
|||
m_IntEnumValues = enumValues; |
|||
} |
|||
|
|||
public override DebugMenuItemUI BuildGUI(GameObject parent) |
|||
{ |
|||
Initialize(); |
|||
|
|||
return new DebugMenuEnumItemUI(parent, m_MenuItem, m_Label.text, m_IntEnumStrings, m_IntEnumValues); |
|||
} |
|||
|
|||
#if UNITY_EDITOR
|
|||
public override bool OnEditorGUI() |
|||
{ |
|||
Initialize(); |
|||
|
|||
UnityEditor.EditorGUI.BeginChangeCheck(); |
|||
int value = UnityEditor.EditorGUILayout.IntPopup(m_Label, (int)m_MenuItem.GetValue(), m_IntEnumStrings, m_IntEnumValues); |
|||
if (UnityEditor.EditorGUI.EndChangeCheck()) |
|||
{ |
|||
m_MenuItem.SetValue(value); |
|||
return true; |
|||
} |
|||
|
|||
return false; |
|||
} |
|||
#endif
|
|||
} |
|||
|
|||
} |
|
|||
using System.Collections; |
|||
using System.Collections.Generic; |
|||
using UnityEngine; |
|||
using System; |
|||
|
|||
namespace UnityEngine.Experimental.Rendering |
|||
{ |
|||
[Serializable] |
|||
public abstract class DebugMenuItemState |
|||
: ScriptableObject |
|||
{ |
|||
public DebugMenuItemState() |
|||
{ |
|||
|
|||
} |
|||
|
|||
public string menuName = ""; |
|||
public string itemName = ""; |
|||
|
|||
public abstract void UpdateValue(); |
|||
public abstract void SetValue(object value); |
|||
|
|||
public void Initialize(string itemName, string menuName) |
|||
{ |
|||
this.menuName = menuName; |
|||
this.itemName = itemName; |
|||
} |
|||
} |
|||
|
|||
public class DebugMenuItemState<T> : DebugMenuItemState |
|||
{ |
|||
public T value; |
|||
|
|||
public override void SetValue(object value) |
|||
{ |
|||
#if UNITY_EDITOR
|
|||
UnityEditor.Undo.RecordObject(this, "DebugMenu State Update"); |
|||
UnityEditor.EditorUtility.SetDirty(this); |
|||
#endif
|
|||
this.value = (T)value; |
|||
} |
|||
|
|||
public override void UpdateValue() |
|||
{ |
|||
DebugMenuManager dmm = DebugMenuManager.instance; |
|||
DebugMenu menu = dmm.GetDebugMenu(menuName); |
|||
if (menu != null) |
|||
{ |
|||
DebugMenuItem item = menu.GetDebugMenuItem(itemName); |
|||
if (item != null) |
|||
{ |
|||
item.SetValue(value, false); |
|||
} |
|||
} |
|||
|
|||
} |
|||
} |
|||
|
|||
public class DebugMenuState |
|||
: ScriptableObject |
|||
{ |
|||
[SerializeField] |
|||
List<DebugMenuItemState> m_ItemStateList = new List<DebugMenuItemState>(); |
|||
|
|||
public void OnEnable() |
|||
{ |
|||
#if UNITY_EDITOR
|
|||
UnityEditor.Undo.undoRedoPerformed += OnUndoRedoPerformed; |
|||
#endif
|
|||
|
|||
// We need to delay the actual update because at this point, some menus might not be created yet (depending on call order) so we can't update their values.
|
|||
DebugMenuManager.instance.RequireUpdateFromDebugItemState(); |
|||
} |
|||
|
|||
public void OnDisable() |
|||
{ |
|||
#if UNITY_EDITOR
|
|||
UnityEditor.Undo.undoRedoPerformed -= OnUndoRedoPerformed; |
|||
#endif
|
|||
// We check consistency in OnDisable instead of OnEnable because we compare the serialized state to the currently running debug menu so we need to make sure that all debug menu are properly created (which is not the case in OnEnable depending on call order)
|
|||
CheckConsistency(); |
|||
} |
|||
|
|||
|
|||
#if UNITY_EDITOR
|
|||
void OnUndoRedoPerformed() |
|||
{ |
|||
// Maybe check a hash or something? So that we don't do that at each redo...
|
|||
UpdateAllItems(); |
|||
UnityEditorInternal.InternalEditorUtility.RepaintAllViews(); |
|||
} |
|||
#endif
|
|||
|
|||
void CheckConsistency() |
|||
{ |
|||
// Remove all objects that may have been removed from the debug menu.
|
|||
DebugMenuManager dmm = DebugMenuManager.instance; |
|||
List<DebugMenuItemState> tempList = new List<DebugMenuItemState>(); |
|||
foreach(var itemState in m_ItemStateList) |
|||
{ |
|||
DebugMenuItem item = null; |
|||
DebugMenu menu = dmm.GetDebugMenu(itemState.menuName); |
|||
if(menu != null) |
|||
{ |
|||
item = menu.GetDebugMenuItem(itemState.itemName); |
|||
} |
|||
|
|||
// Item no longer exist, clean up its state from the asset.
|
|||
if (item == null) |
|||
{ |
|||
tempList.Add(itemState); |
|||
} |
|||
} |
|||
|
|||
foreach(var itemState in tempList) |
|||
{ |
|||
m_ItemStateList.Remove(itemState); |
|||
Object.DestroyImmediate(itemState, true); |
|||
} |
|||
} |
|||
|
|||
public void AddDebugItemState(DebugMenuItemState state) |
|||
{ |
|||
#if UNITY_EDITOR
|
|||
UnityEditor.AssetDatabase.AddObjectToAsset(state, this); |
|||
#endif
|
|||
m_ItemStateList.Add(state); |
|||
} |
|||
|
|||
public DebugMenuItemState FindDebugItemState(string itemName, string menuName) |
|||
{ |
|||
return m_ItemStateList.Find(x => x.itemName == itemName && x.menuName == menuName); |
|||
} |
|||
|
|||
public void UpdateAllItems() |
|||
{ |
|||
foreach (var itemState in m_ItemStateList) |
|||
{ |
|||
itemState.UpdateValue(); |
|||
} |
|||
} |
|||
} |
|||
} |
|
|||
fileFormatVersion: 2 |
|||
guid: d17031e345b144b4a887f66665be6a2b |
|||
timeCreated: 1495180913 |
|||
licenseType: Pro |
|||
MonoImporter: |
|||
serializedVersion: 2 |
|||
defaultReferences: [] |
|||
executionOrder: 0 |
|||
icon: {instanceID: 0} |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
fileFormatVersion: 2 |
|||
guid: a07168baba11f084daec1edd4032f153 |
|||
folderAsset: yes |
|||
timeCreated: 1495456975 |
|||
licenseType: Pro |
|||
DefaultImporter: |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
using System.Collections; |
|||
using System.Collections.Generic; |
|||
using UnityEngine; |
|||
|
|||
namespace UnityEngine.Experimental.Rendering |
|||
{ |
|||
public class DebugItemStateBool : DebugMenuItemState<bool> |
|||
{ |
|||
} |
|||
} |
|
|||
fileFormatVersion: 2 |
|||
guid: b7b2843778281fb4bbd2a62a3e165c15 |
|||
timeCreated: 1495456996 |
|||
licenseType: Pro |
|||
MonoImporter: |
|||
serializedVersion: 2 |
|||
defaultReferences: [] |
|||
executionOrder: 0 |
|||
icon: {instanceID: 0} |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
using System.Collections; |
|||
using System.Collections.Generic; |
|||
using UnityEngine; |
|||
|
|||
namespace UnityEngine.Experimental.Rendering |
|||
{ |
|||
public class DebugItemStateColor : DebugMenuItemState<Color> |
|||
{ |
|||
} |
|||
} |
|
|||
fileFormatVersion: 2 |
|||
guid: 6e7cea1e2f04a344db1d12f0f1c98f3e |
|||
timeCreated: 1495456996 |
|||
licenseType: Pro |
|||
MonoImporter: |
|||
serializedVersion: 2 |
|||
defaultReferences: [] |
|||
executionOrder: 0 |
|||
icon: {instanceID: 0} |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
using System.Collections; |
|||
using System.Collections.Generic; |
|||
using UnityEngine; |
|||
|
|||
namespace UnityEngine.Experimental.Rendering |
|||
{ |
|||
public class DebugItemStateFloat : DebugMenuItemState<float> |
|||
{ |
|||
} |
|||
} |
|
|||
fileFormatVersion: 2 |
|||
guid: dd5284e29e625f044be91737547ae28d |
|||
timeCreated: 1495456996 |
|||
licenseType: Pro |
|||
MonoImporter: |
|||
serializedVersion: 2 |
|||
defaultReferences: [] |
|||
executionOrder: 0 |
|||
icon: {instanceID: 0} |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
using System.Collections; |
|||
using System.Collections.Generic; |
|||
using UnityEngine; |
|||
|
|||
namespace UnityEngine.Experimental.Rendering |
|||
{ |
|||
public class DebugItemStateInt : DebugMenuItemState<int> |
|||
{ |
|||
} |
|||
} |
|
|||
fileFormatVersion: 2 |
|||
guid: 7b805c6a0dad19144b48c3fe01b2775d |
|||
timeCreated: 1495456996 |
|||
licenseType: Pro |
|||
MonoImporter: |
|||
serializedVersion: 2 |
|||
defaultReferences: [] |
|||
executionOrder: 0 |
|||
icon: {instanceID: 0} |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
using System.Collections; |
|||
using System.Collections.Generic; |
|||
using UnityEngine; |
|||
|
|||
namespace UnityEngine.Experimental.Rendering |
|||
{ |
|||
public class DebugItemStateUInt : DebugMenuItemState<uint> |
|||
{ |
|||
} |
|||
} |
|
|||
fileFormatVersion: 2 |
|||
guid: cdfed9a25a787094cbad07cb325b88e0 |
|||
timeCreated: 1495456996 |
|||
licenseType: Pro |
|||
MonoImporter: |
|||
serializedVersion: 2 |
|||
defaultReferences: [] |
|||
executionOrder: 0 |
|||
icon: {instanceID: 0} |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
using System.Collections; |
|||
using System.Collections.Generic; |
|||
using UnityEngine; |
|||
using System; |
|||
|
|||
#if UNITY_EDITOR
|
|||
using UnityEditor; |
|||
#endif
|
|||
|
|||
namespace UnityEngine.Experimental.Rendering |
|||
{ |
|||
public class DebugItemDrawer |
|||
{ |
|||
protected DebugMenuItem m_MenuItem = null; |
|||
|
|||
// Label for simple GUI items
|
|||
protected GUIContent m_Label; |
|||
protected List<GUIContent> m_EnumStrings = null; |
|||
protected List<int> m_EnumValues = null; |
|||
|
|||
public DebugItemDrawer() |
|||
{ |
|||
} |
|||
|
|||
public void SetDebugItem(DebugMenuItem item) |
|||
{ |
|||
m_MenuItem = item; |
|||
|
|||
m_Label = new GUIContent(m_MenuItem.name); |
|||
Type itemType = m_MenuItem.GetItemType(); |
|||
if(itemType.BaseType == typeof(System.Enum)) |
|||
{ |
|||
Array arr = Enum.GetValues(itemType); |
|||
m_EnumStrings = new List<GUIContent>(arr.Length); |
|||
m_EnumValues = new List<int>(arr.Length); |
|||
|
|||
foreach(var value in arr) |
|||
{ |
|||
m_EnumStrings.Add(new GUIContent(value.ToString())); |
|||
m_EnumValues.Add((int)value); |
|||
} |
|||
} |
|||
} |
|||
|
|||
public virtual void ClampValues(Func<object> getter, Action<object> setter) {} |
|||
public virtual DebugMenuItemUI BuildGUI(GameObject parent, DebugMenuItem menuItem) |
|||
{ |
|||
DebugMenuItemUI newItemUI = null; |
|||
if (menuItem.GetItemType() == typeof(bool)) |
|||
{ |
|||
newItemUI = new DebugMenuBoolItemUI(parent, menuItem, m_Label.text); |
|||
} |
|||
else if (menuItem.GetItemType() == typeof(int)) |
|||
{ |
|||
newItemUI = new DebugMenuIntItemUI(parent, menuItem, m_Label.text); |
|||
} |
|||
else if (menuItem.GetItemType() == typeof(uint)) |
|||
{ |
|||
newItemUI = new DebugMenuUIntItemUI(parent, menuItem, m_Label.text); |
|||
} |
|||
else if (menuItem.GetItemType() == typeof(float)) |
|||
{ |
|||
newItemUI = new DebugMenuFloatItemUI(parent, menuItem, m_Label.text); |
|||
} |
|||
else if (menuItem.GetItemType() == typeof(Color)) |
|||
{ |
|||
newItemUI = new DebugMenuColorItemUI(parent, menuItem, m_Label.text); |
|||
} |
|||
else if (m_MenuItem.GetItemType().BaseType == typeof(System.Enum)) |
|||
{ |
|||
newItemUI = new DebugMenuEnumItemUI(parent, menuItem, m_Label.text, m_EnumStrings.ToArray(), m_EnumValues.ToArray()); |
|||
} |
|||
|
|||
return newItemUI; |
|||
} |
|||
|
|||
#if UNITY_EDITOR
|
|||
bool DrawBoolItem() |
|||
{ |
|||
bool value = (bool)m_MenuItem.GetValue(); |
|||
if (m_MenuItem.readOnly) |
|||
{ |
|||
EditorGUILayout.LabelField(m_Label, new GUIContent(value.ToString())); |
|||
} |
|||
else |
|||
{ |
|||
EditorGUI.BeginChangeCheck(); |
|||
value = EditorGUILayout.Toggle(m_Label, value); |
|||
if (EditorGUI.EndChangeCheck()) |
|||
{ |
|||
m_MenuItem.SetValue(value); |
|||
return true; |
|||
} |
|||
} |
|||
|
|||
return false; |
|||
} |
|||
|
|||
bool DrawIntItem() |
|||
{ |
|||
int value = (int)m_MenuItem.GetValue(); |
|||
if (m_MenuItem.readOnly) |
|||
{ |
|||
EditorGUILayout.LabelField(m_Label, new GUIContent(value.ToString())); |
|||
} |
|||
else |
|||
{ |
|||
EditorGUI.BeginChangeCheck(); |
|||
value = EditorGUILayout.IntField(m_Label, value); |
|||
if (EditorGUI.EndChangeCheck()) |
|||
{ |
|||
m_MenuItem.SetValue(value); |
|||
return true; |
|||
} |
|||
} |
|||
|
|||
return false; |
|||
} |
|||
|
|||
bool DrawUIntItem() |
|||
{ |
|||
int value = (int)(uint)m_MenuItem.GetValue(); |
|||
if (m_MenuItem.readOnly) |
|||
{ |
|||
EditorGUILayout.LabelField(m_Label, new GUIContent(value.ToString())); |
|||
} |
|||
else |
|||
{ |
|||
EditorGUI.BeginChangeCheck(); |
|||
value = EditorGUILayout.IntField(m_Label, value); |
|||
if (EditorGUI.EndChangeCheck()) |
|||
{ |
|||
value = System.Math.Max(0, value); |
|||
m_MenuItem.SetValue((uint)value); |
|||
return true; |
|||
} |
|||
} |
|||
|
|||
return false; |
|||
} |
|||
|
|||
bool DrawFloatItem() |
|||
{ |
|||
float value = (float)m_MenuItem.GetValue(); |
|||
if(m_MenuItem.readOnly) |
|||
{ |
|||
EditorGUILayout.LabelField(m_Label, new GUIContent(value.ToString())); |
|||
} |
|||
else |
|||
{ |
|||
EditorGUI.BeginChangeCheck(); |
|||
value = EditorGUILayout.FloatField(m_Label, value); |
|||
if (EditorGUI.EndChangeCheck()) |
|||
{ |
|||
m_MenuItem.SetValue(value); |
|||
return true; |
|||
} |
|||
} |
|||
|
|||
return false; |
|||
} |
|||
|
|||
bool DrawColorItem() |
|||
{ |
|||
EditorGUI.BeginChangeCheck(); |
|||
Color value = EditorGUILayout.ColorField(m_Label, (Color)m_MenuItem.GetValue()); |
|||
if (EditorGUI.EndChangeCheck()) |
|||
{ |
|||
m_MenuItem.SetValue(value); |
|||
return true; |
|||
} |
|||
|
|||
return false; |
|||
} |
|||
|
|||
bool DrawEnumItem() |
|||
{ |
|||
EditorGUI.BeginChangeCheck(); |
|||
int value = EditorGUILayout.IntPopup(m_Label, (int)m_MenuItem.GetValue(), m_EnumStrings.ToArray(), m_EnumValues.ToArray()); |
|||
if (EditorGUI.EndChangeCheck()) |
|||
{ |
|||
m_MenuItem.SetValue(value); |
|||
return true; |
|||
} |
|||
|
|||
return false; |
|||
} |
|||
|
|||
public virtual bool OnEditorGUI() |
|||
{ |
|||
if (m_MenuItem.GetItemType() == typeof(bool)) |
|||
{ |
|||
return DrawBoolItem(); |
|||
} |
|||
else if (m_MenuItem.GetItemType() == typeof(int)) |
|||
{ |
|||
return DrawIntItem(); |
|||
} |
|||
else if(m_MenuItem.GetItemType() == typeof(uint)) |
|||
{ |
|||
return DrawUIntItem(); |
|||
} |
|||
else if (m_MenuItem.GetItemType() == typeof(float)) |
|||
{ |
|||
return DrawFloatItem(); |
|||
} |
|||
else if (m_MenuItem.GetItemType() == typeof(Color)) |
|||
{ |
|||
return DrawColorItem(); |
|||
} |
|||
else if (m_MenuItem.GetItemType().BaseType == typeof(System.Enum)) |
|||
{ |
|||
return DrawEnumItem(); |
|||
} |
|||
|
|||
return false; |
|||
} |
|||
#endif
|
|||
} |
|||
|
|||
public class DebugItemDrawFloatMinMax |
|||
: DebugItemDrawer |
|||
{ |
|||
float m_Min = 0.0f; |
|||
float m_Max = 1.0f; |
|||
public DebugItemDrawFloatMinMax(float min, float max) |
|||
{ |
|||
m_Min = min; |
|||
m_Max = max; |
|||
} |
|||
|
|||
public override void ClampValues(Func<object> getter, Action<object> setter) |
|||
{ |
|||
if (m_MenuItem == null) |
|||
return; |
|||
|
|||
if(m_MenuItem.GetItemType() == typeof(float)) |
|||
{ |
|||
setter(Mathf.Clamp((float)getter(), m_Min, m_Max)); |
|||
} |
|||
} |
|||
|
|||
#if UNITY_EDITOR
|
|||
public override bool OnEditorGUI() |
|||
{ |
|||
EditorGUI.BeginChangeCheck(); |
|||
float value = EditorGUILayout.Slider(m_MenuItem.name, (float)m_MenuItem.GetValue(), m_Min, m_Max); |
|||
if (EditorGUI.EndChangeCheck()) |
|||
{ |
|||
m_MenuItem.SetValue(value); |
|||
return true; |
|||
} |
|||
|
|||
return false; |
|||
} |
|||
#endif
|
|||
} |
|||
|
|||
public class DebugItemDrawerIntEnum |
|||
: DebugItemDrawer |
|||
{ |
|||
GUIContent[] m_EnumStrings = null; |
|||
int[] m_EnumValues = null; |
|||
|
|||
public DebugItemDrawerIntEnum(GUIContent[] enumStrings, int[] enumValues) |
|||
{ |
|||
m_EnumStrings = enumStrings; |
|||
m_EnumValues = enumValues; |
|||
} |
|||
|
|||
public override DebugMenuItemUI BuildGUI(GameObject parent, DebugMenuItem menuItem) |
|||
{ |
|||
return new DebugMenuEnumItemUI(parent, menuItem, m_Label.text, m_EnumStrings, m_EnumValues); |
|||
} |
|||
|
|||
#if UNITY_EDITOR
|
|||
public override bool OnEditorGUI() |
|||
{ |
|||
UnityEditor.EditorGUI.BeginChangeCheck(); |
|||
int value = UnityEditor.EditorGUILayout.IntPopup(m_Label, (int)m_MenuItem.GetValue(), m_EnumStrings, m_EnumValues); |
|||
if (UnityEditor.EditorGUI.EndChangeCheck()) |
|||
{ |
|||
m_MenuItem.SetValue(value); |
|||
return true; |
|||
} |
|||
|
|||
return false; |
|||
} |
|||
#endif
|
|||
} |
|||
|
|||
} |
撰写
预览
正在加载...
取消
保存
Reference in new issue