DragonECS-Unity/src/Internal/Editor/RuntimeComponentsDrawer.cs

725 lines
29 KiB
C#
Raw Normal View History

2025-04-16 09:36:51 +08:00
#if UNITY_EDITOR
using DCFApixels.DragonECS.Unity.Internal;
using System;
using System.Collections.Generic;
using System.Reflection;
using Unity.Collections.LowLevel.Unsafe;
using UnityEditor;
using UnityEngine;
using Color = UnityEngine.Color;
using UnityComponent = UnityEngine.Component;
using UnityObject = UnityEngine.Object;
namespace DCFApixels.DragonECS.Unity.Editors.X
{
2025-05-14 20:19:40 +08:00
using static RuntimeComponentsDrawer.RuntimeComponentReflectionCache;
2025-04-16 09:36:51 +08:00
internal class RuntimeComponentsDrawer
{
private static readonly BindingFlags fieldFlags = BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic;
[RuntimeInitializeOnLoadMethod(RuntimeInitializeLoadType.SubsystemRegistration)]
private static void ResetRuntimeComponentReflectionCache()
{
RefEditorWrapper.ResetStaticState();
foreach (var item in _runtimeComponentReflectionCaches)
{
item.Value.ResetWrappers();
}
//_runtimeComponentReflectionCaches.Clear();
}
private const int RuntimeComponentsMaxDepth = 2;
2025-05-09 19:51:07 +08:00
private const int RuntimeComponentsDepthRoot = -1;
2025-04-16 09:36:51 +08:00
private static RuntimeComponentsDrawer[] _drawers;
2025-05-09 19:51:07 +08:00
private static int _runtimeComponentsDepth = RuntimeComponentsDepthRoot;
2025-04-16 09:36:51 +08:00
static RuntimeComponentsDrawer()
{
_drawers = new RuntimeComponentsDrawer[RuntimeComponentsMaxDepth + 1];
_drawers[0] = new RuntimeComponentsDrawer();
_drawers[1] = new RuntimeComponentsDrawer();
_drawers[2] = new RuntimeComponentsDrawer();
}
private List<IEcsPool> _componentPoolsBuffer = new List<IEcsPool>(64);
#region Properties
private static ComponentColorMode AutoColorMode
{
get { return UserSettingsPrefs.instance.ComponentColorMode; }
set { UserSettingsPrefs.instance.ComponentColorMode = value; }
}
private static bool IsShowHidden
{
get { return UserSettingsPrefs.instance.IsShowHidden; }
set { UserSettingsPrefs.instance.IsShowHidden = value; }
}
private static bool IsShowRuntimeComponents
{
get { return UserSettingsPrefs.instance.IsShowRuntimeComponents; }
set { UserSettingsPrefs.instance.IsShowRuntimeComponents = value; }
}
#endregion
#region reflection cache
internal class RuntimeComponentReflectionCache
{
public readonly Type Type;
public readonly bool IsUnmanaged;
2025-05-14 20:19:40 +08:00
public readonly DrawerType Drawer;
2025-04-16 09:36:51 +08:00
public readonly FieldInfoData[] Fields;
2025-05-14 20:19:40 +08:00
private RefEditorWrapper[] _wrappers = new RefEditorWrapper[RuntimeComponentsMaxDepth];
2025-04-16 09:36:51 +08:00
public RefEditorWrapper GetWrapper(int depth)
{
return _wrappers[depth];
}
public RuntimeComponentReflectionCache(Type type)
{
Type = type;
ResetWrappers();
IsUnmanaged = UnsafeUtility.IsUnmanaged(type);
2025-05-10 11:45:24 +08:00
2025-05-14 20:19:40 +08:00
bool isVoideType = type == typeof(void);
bool isUnityObjectType = typeof(UnityObject).IsAssignableFrom(type);
bool isLeaf = isUnityObjectType || type.IsPrimitive || type == typeof(string) || type.IsEnum;
Drawer = DrawerType.UNDEFINED;
2025-05-10 11:45:24 +08:00
2025-05-14 20:19:40 +08:00
if(type.IsArray || isVoideType)
{
Drawer = DrawerType.Ignored;
}
if (Drawer == DrawerType.UNDEFINED && isLeaf)
2025-05-10 11:45:24 +08:00
{
if (type.IsEnum)
{
2025-05-14 20:19:40 +08:00
Drawer = type.HasAttribute<FlagsAttribute>() ? DrawerType.EnumFlags : DrawerType.Enum;
}
else if (isUnityObjectType)
{
Drawer = DrawerType.UnityObject;
2025-05-10 11:45:24 +08:00
}
else if (type == typeof(bool))
{
2025-05-14 20:19:40 +08:00
Drawer = DrawerType.Bool;
2025-05-10 11:45:24 +08:00
}
else if (type == typeof(string))
{
2025-05-14 20:19:40 +08:00
Drawer = DrawerType.String;
2025-05-10 11:45:24 +08:00
}
else if (type == typeof(float))
{
2025-05-14 20:19:40 +08:00
Drawer = DrawerType.Float;
2025-05-10 11:45:24 +08:00
}
else if (type == typeof(double))
{
2025-05-14 20:19:40 +08:00
Drawer = DrawerType.Double;
2025-05-10 11:45:24 +08:00
}
else if (type == typeof(byte))
{
2025-05-14 20:19:40 +08:00
Drawer = DrawerType.Byte;
2025-05-10 11:45:24 +08:00
}
else if (type == typeof(sbyte))
{
2025-05-14 20:19:40 +08:00
Drawer = DrawerType.SByte;
2025-05-10 11:45:24 +08:00
}
else if (type == typeof(short))
{
2025-05-14 20:19:40 +08:00
Drawer = DrawerType.Short;
2025-05-10 11:45:24 +08:00
}
else if (type == typeof(ushort))
{
2025-05-14 20:19:40 +08:00
Drawer = DrawerType.UShort;
2025-05-10 11:45:24 +08:00
}
else if (type == typeof(int))
{
2025-05-14 20:19:40 +08:00
Drawer = DrawerType.Int;
2025-05-10 11:45:24 +08:00
}
else if (type == typeof(uint))
{
2025-05-14 20:19:40 +08:00
Drawer = DrawerType.UInt;
2025-05-10 11:45:24 +08:00
}
else if (type == typeof(long))
{
2025-05-14 20:19:40 +08:00
Drawer = DrawerType.Long;
2025-05-10 11:45:24 +08:00
}
else if (type == typeof(ulong))
{
2025-05-14 20:19:40 +08:00
Drawer = DrawerType.ULong;
2025-05-10 11:45:24 +08:00
}
}
2025-05-14 20:19:40 +08:00
if (Drawer == DrawerType.UNDEFINED)
{
Drawer = type.IsGenericType ? DrawerType.UnityNotSerializableComposite : DrawerType.UnitySerializableComposite;
}
2025-05-10 11:45:24 +08:00
2025-05-14 20:19:40 +08:00
if (isVoideType) { return; }
2025-04-16 09:36:51 +08:00
2025-05-14 20:19:40 +08:00
if (Drawer == DrawerType.UnityNotSerializableComposite)
2025-04-16 09:36:51 +08:00
{
var fieldInfos = type.GetFields(fieldFlags);
Fields = new FieldInfoData[fieldInfos.Length];
for (int i = 0; i < fieldInfos.Length; i++)
{
var fieldInfo = fieldInfos[i];
Fields[i] = new FieldInfoData(fieldInfo);
}
}
}
public void ResetWrappers()
{
_wrappers[0] = RefEditorWrapper.Take();
_wrappers[1] = RefEditorWrapper.Take();
}
public readonly struct FieldInfoData
{
public readonly FieldInfo FieldInfo;
public readonly Type FieldType;
public readonly string UnityFormatName;
public readonly bool IsUnityObjectField;
2025-04-21 00:10:57 +08:00
public readonly bool IsPassToUnitySerialize;
2025-04-16 09:36:51 +08:00
public readonly RuntimeComponentReflectionCache ValueTypeReflectionCache;
2025-05-14 20:19:40 +08:00
2025-04-16 09:36:51 +08:00
public FieldInfoData(FieldInfo fieldInfo)
{
FieldInfo = fieldInfo;
FieldType = fieldInfo.FieldType;
IsUnityObjectField = typeof(UnityObject).IsAssignableFrom(fieldInfo.FieldType);
UnityFormatName = UnityEditorUtility.TransformFieldName(fieldInfo.Name);
2025-04-21 00:10:57 +08:00
IsPassToUnitySerialize =
2025-04-16 09:36:51 +08:00
(fieldInfo.IsPublic || fieldInfo.HasAttribute<SerializeField>() || fieldInfo.HasAttribute<SerializeReference>()) &&
(fieldInfo.IsInitOnly || fieldInfo.HasAttribute<System.NonSerializedAttribute>()) == false;
ValueTypeReflectionCache = FieldType.IsValueType ? GetRuntimeComponentReflectionCache(FieldType) : null;
}
public FieldInfoData(FieldInfo fieldInfo, Type fieldType, string unityFormatName, bool isPassToSerialize = true)
{
FieldInfo = fieldInfo;
FieldType = fieldType;
UnityFormatName = unityFormatName;
IsUnityObjectField = typeof(UnityObject).IsAssignableFrom(fieldType);
2025-04-21 00:10:57 +08:00
IsPassToUnitySerialize = isPassToSerialize;
2025-04-16 09:36:51 +08:00
ValueTypeReflectionCache = FieldType.IsValueType ? GetRuntimeComponentReflectionCache(FieldType) : null;
}
public RuntimeComponentReflectionCache GetReflectionCache(Type type)
{
if (ValueTypeReflectionCache != null)
{
return ValueTypeReflectionCache;
}
return GetRuntimeComponentReflectionCache(type);
}
}
2025-05-14 20:21:35 +08:00
public enum DrawerType
{
UNDEFINED = 0,
Ignored,
// Composite
UnitySerializableComposite,
UnityNotSerializableComposite,
// Leaft types
UnityObject,
Enum,
EnumFlags,
Bool,
String,
Float,
Double,
Byte,
SByte,
Short,
UShort,
Int,
UInt,
Long,
ULong,
}
2025-04-16 09:36:51 +08:00
}
private static Dictionary<Type, RuntimeComponentReflectionCache> _runtimeComponentReflectionCaches = new Dictionary<Type, RuntimeComponentReflectionCache>();
private static RuntimeComponentReflectionCache GetRuntimeComponentReflectionCache(Type type)
{
if (_runtimeComponentReflectionCaches.TryGetValue(type, out RuntimeComponentReflectionCache result) == false)
{
result = new RuntimeComponentReflectionCache(type);
_runtimeComponentReflectionCaches.Add(type, result);
}
return result;
}
#endregion
#region draw world component
public static void DrawWorldComponents(EcsWorld world)
{
2025-05-09 19:51:07 +08:00
if (_runtimeComponentsDepth == RuntimeComponentsDepthRoot)
2025-04-16 09:36:51 +08:00
{
2025-05-09 19:51:07 +08:00
_drawers[0].DrawWorldComponents_Internal(world);
2025-04-16 09:36:51 +08:00
}
}
private void DrawWorldComponents_Internal(EcsWorld world)
{
bool isNull = world == null || world.IsDestroyed || world.ID == 0;
if (isNull) { return; }
using (EcsGUI.Layout.BeginVertical(UnityEditorUtility.GetTransperentBlackBackgrounStyle()))
{
IsShowRuntimeComponents = EditorGUILayout.BeginFoldoutHeaderGroup(IsShowRuntimeComponents, "RUNTIME COMPONENTS", EditorStyles.foldout);
EditorGUILayout.EndFoldoutHeaderGroup();
if (IsShowRuntimeComponents == false) { return; }
var worldID = world.ID;
var cmps = world.GetWorldComponents();
int index = -1;
int total = 9;
foreach (var cmp in cmps)
{
index++;
var meta = cmp.ComponentType.ToMeta();
if (meta.IsHidden == false || IsShowHidden)
{
Type componentType = cmp.ComponentType;
object data = cmp.GetRaw(worldID);
ExpandMatrix expandMatrix = ExpandMatrix.Take(componentType);
float padding = EditorGUIUtility.standardVerticalSpacing;
Rect optionButton = GUILayoutUtility.GetLastRect();
optionButton.yMin = optionButton.yMax;
optionButton.yMax += EcsGUI.HeadIconsRect.height;
optionButton.xMin = optionButton.xMax - 64;
optionButton.center += Vector2.up * padding * 2f;
//Canceling isExpanded
if (EcsGUI.ClickTest(optionButton))
{
ref bool isExpanded = ref expandMatrix.Down();
isExpanded = !isExpanded;
}
Color panelColor = EcsGUI.SelectPanelColor(meta, index, total);
using (EcsGUI.Layout.BeginVertical(panelColor.SetAlpha(EscEditorConsts.COMPONENT_DRAWER_ALPHA)))
{
EditorGUI.BeginChangeCheck();
//Edit script button
if (ScriptsCache.TryGetScriptAsset(meta, out MonoScript script))
{
optionButton = EcsGUI.HeadIconsRect.MoveTo(optionButton.center - (Vector2.right * optionButton.width));
EcsGUI.ScriptAssetButton(optionButton, script);
}
//Description icon
if (string.IsNullOrEmpty(meta.Description.Text) == false)
{
optionButton = EcsGUI.HeadIconsRect.MoveTo(optionButton.center - (Vector2.right * optionButton.width));
EcsGUI.DescriptionIcon(optionButton, meta.Description.Text);
}
RuntimeComponentReflectionCache.FieldInfoData componentInfoData = new RuntimeComponentReflectionCache.FieldInfoData(null, componentType, meta.Name);
2025-05-10 11:45:24 +08:00
if (DrawRuntimeData(ref componentInfoData, UnityEditorUtility.GetLabel(meta.Name), expandMatrix, data, out object resultData, 0))
2025-04-16 09:36:51 +08:00
{
cmp.SetRaw(worldID, resultData);
}
}
}
}
}
}
#endregion
#region draw entity component
public static void DrawRuntimeComponents(int entityID, EcsWorld world, bool isWithFoldout, bool isRoot)
{
if (isRoot)
{
2025-05-09 19:51:07 +08:00
_runtimeComponentsDepth = RuntimeComponentsDepthRoot;
2025-04-16 09:36:51 +08:00
}
2025-05-09 19:51:07 +08:00
_runtimeComponentsDepth++;
2025-04-16 09:36:51 +08:00
2025-05-09 22:18:23 +08:00
try
2025-05-09 19:51:07 +08:00
{
2025-05-09 22:18:23 +08:00
_drawers[_runtimeComponentsDepth].DrawRuntimeComponents(entityID, world, isWithFoldout);
}
finally
{
_runtimeComponentsDepth--;
if (_runtimeComponentsDepth < RuntimeComponentsDepthRoot)
{
_runtimeComponentsDepth = RuntimeComponentsDepthRoot;
}
2025-05-09 19:51:07 +08:00
}
2025-04-16 09:36:51 +08:00
}
private void DrawRuntimeComponents(int entityID, EcsWorld world, bool isWithFoldout)
{
using (EcsGUI.Layout.BeginVertical(UnityEditorUtility.GetTransperentBlackBackgrounStyle())) using (EcsGUI.SetIndentLevel(0))
{
if (_runtimeComponentsDepth >= RuntimeComponentsMaxDepth)
{
GUILayout.Label("Max depth for inspecting components at runtime");
return;
}
if (isWithFoldout)
{
IsShowRuntimeComponents = EditorGUILayout.BeginFoldoutHeaderGroup(IsShowRuntimeComponents, "RUNTIME COMPONENTS", EditorStyles.foldout);
EditorGUILayout.EndFoldoutHeaderGroup();
}
if (isWithFoldout == false || IsShowRuntimeComponents)
{
if (EcsGUI.Layout.AddComponentButtons(out Rect dropDownRect))
{
RuntimeComponentsUtility.GetAddComponentGenericMenu(world).Open(dropDownRect, entityID);
}
using (EcsGUI.SetBackgroundColor(GUI.color.SetAlpha(0.16f)))
{
GUILayout.Box("", UnityEditorUtility.GetWhiteStyle(), GUILayout.ExpandWidth(true));
}
IsShowHidden = EditorGUI.Toggle(GUILayoutUtility.GetLastRect(), "Show Hidden", IsShowHidden);
world.GetComponentPoolsFor(entityID, _componentPoolsBuffer);
for (int i = 0; i < _componentPoolsBuffer.Count; i++)
{
DrawRuntimeComponent(entityID, _componentPoolsBuffer[i], 9, i);
}
}
}
}
private void DrawRuntimeComponent(int entityID, IEcsPool pool, int total, int index)
{
var meta = pool.ComponentType.ToMeta();
if (meta.IsHidden == false || IsShowHidden)
{
Type componentType = pool.ComponentType;
object data = pool.GetRaw(entityID);
ExpandMatrix expandMatrix = ExpandMatrix.Take(componentType);
float padding = EditorGUIUtility.standardVerticalSpacing;
Rect optionButton = GUILayoutUtility.GetLastRect();
optionButton.yMin = optionButton.yMax;
optionButton.yMax += EcsGUI.HeadIconsRect.height;
optionButton.xMin = optionButton.xMax - 64;
optionButton.center += Vector2.up * padding * 2f;
//Canceling isExpanded
if (EcsGUI.ClickTest(optionButton))
{
ref bool isExpanded = ref expandMatrix.Down();
isExpanded = !isExpanded;
}
Color panelColor = EcsGUI.SelectPanelColor(meta, index, total);
using (EcsGUI.Layout.BeginVertical(panelColor.SetAlpha(EscEditorConsts.COMPONENT_DRAWER_ALPHA)))
{
EditorGUI.BeginChangeCheck();
//Close button
optionButton.xMin = optionButton.xMax - EcsGUI.HeadIconsRect.width;
if (EcsGUI.CloseButton(optionButton))
{
pool.Del(entityID);
return;
}
//Edit script button
if (ScriptsCache.TryGetScriptAsset(meta, out MonoScript script))
{
optionButton = EcsGUI.HeadIconsRect.MoveTo(optionButton.center - (Vector2.right * optionButton.width));
EcsGUI.ScriptAssetButton(optionButton, script);
}
//Description icon
if (string.IsNullOrEmpty(meta.Description.Text) == false)
{
optionButton = EcsGUI.HeadIconsRect.MoveTo(optionButton.center - (Vector2.right * optionButton.width));
EcsGUI.DescriptionIcon(optionButton, meta.Description.Text);
}
RuntimeComponentReflectionCache.FieldInfoData componentInfoData = new RuntimeComponentReflectionCache.FieldInfoData(null, componentType, meta.Name);
2025-05-10 11:45:24 +08:00
if (DrawRuntimeData(ref componentInfoData, UnityEditorUtility.GetLabel(meta.Name), expandMatrix, data, out object resultData, 0))
2025-04-16 09:36:51 +08:00
{
pool.SetRaw(entityID, resultData);
}
}
}
}
#endregion
#region draw data
2025-05-10 11:45:24 +08:00
private bool DrawRuntimeData(ref RuntimeComponentReflectionCache.FieldInfoData fieldInfoData, GUIContent label, ExpandMatrix expandMatrix, object data, out object outData, int depth)
2025-04-16 09:36:51 +08:00
{
2025-05-14 20:19:40 +08:00
const int DEPTH_MAX = 16;
EditorGUI.BeginChangeCheck();
2025-04-16 09:36:51 +08:00
outData = data;
2025-05-14 20:19:40 +08:00
object newData = data;
2025-04-16 09:36:51 +08:00
Type type = data == null ? typeof(void) : data.GetType();
RuntimeComponentReflectionCache cache = fieldInfoData.GetReflectionCache(type);
bool isUnityObjectField = fieldInfoData.IsUnityObjectField;
if (isUnityObjectField == false && data == null)
{
EditorGUILayout.TextField(label, "Null");
return false;
}
2025-05-10 11:45:24 +08:00
if (depth >= DEPTH_MAX || cache == null)
{
EditorGUILayout.TextField(label, "error");
return false;
}
2025-04-16 09:36:51 +08:00
ref bool isExpanded = ref expandMatrix.Down();
2025-05-14 20:19:40 +08:00
bool childElementChanged = false;
var eventType = Event.current.type;
2025-04-16 09:36:51 +08:00
2025-05-14 20:19:40 +08:00
var label2 = UnityEditorUtility.GetLabel2(cache.Type.FullName + " " + type.FullName);
var drawer = cache.Drawer;
if (isUnityObjectField)
2025-04-16 09:36:51 +08:00
{
2025-05-14 20:19:40 +08:00
drawer = DrawerType.UnityObject;
}
switch (drawer)
{
case DrawerType.UNDEFINED:
EditorGUILayout.LabelField(label, label2);
break;
case DrawerType.Ignored:
EditorGUILayout.LabelField(label, label2);
break;
case DrawerType.UnitySerializableComposite:
using (EcsGUI.CheckChanged())
{
RefEditorWrapper wrapper = cache.GetWrapper(_runtimeComponentsDepth);
wrapper.data = data;
wrapper.SO.Update();
wrapper.IsExpanded = isExpanded;
EditorGUILayout.PropertyField(wrapper.Property, label, true);
2025-04-16 09:36:51 +08:00
2025-05-14 20:19:40 +08:00
if (EcsGUI.Changed)
{
wrapper.SO.ApplyModifiedProperties();
newData = wrapper.Data;
childElementChanged = true;
}
isExpanded = wrapper.IsExpanded;
}
break;
case DrawerType.UnityNotSerializableComposite:
GUILayout.Space(EcsGUI.Spacing);
var foldoutStyle = EditorStyles.foldout;
Rect rect = GUILayoutUtility.GetRect(label, foldoutStyle);
//rect.xMin += EcsGUI.Indent;
isExpanded = EditorGUI.BeginFoldoutHeaderGroup(rect, isExpanded, label, foldoutStyle, null, null);
EditorGUILayout.EndFoldoutHeaderGroup();
if (isExpanded)
2025-04-16 09:36:51 +08:00
{
2025-05-14 20:19:40 +08:00
using (EcsGUI.UpIndentLevel())
2025-04-16 09:36:51 +08:00
{
2025-05-14 20:19:40 +08:00
for (int j = 0, jMax = cache.Fields.Length; j < jMax; j++)
2025-04-16 09:36:51 +08:00
{
2025-05-14 20:19:40 +08:00
var field = cache.Fields[j];
if (DrawRuntimeData(ref field, UnityEditorUtility.GetLabel(field.UnityFormatName), expandMatrix, field.FieldInfo.GetValue(data), out object fieldData, depth + 1))
{
field.FieldInfo.SetValue(data, fieldData);
newData = data;
childElementChanged = true;
}
2025-04-16 09:36:51 +08:00
}
}
}
2025-05-09 23:41:33 +08:00
2025-05-14 20:19:40 +08:00
break;
case DrawerType.UnityObject:
2025-04-16 09:36:51 +08:00
2025-05-14 20:19:40 +08:00
using (EcsGUI.CheckChanged())
2025-04-16 09:36:51 +08:00
{
2025-05-14 20:19:40 +08:00
var uobj = UnsafeUtility.As<object, UnityObject>(ref data);
bool isComponent = typeof(UnityComponent).IsAssignableFrom(fieldInfoData.FieldType);
var newuobj = EditorGUILayout.ObjectField(label, uobj, fieldInfoData.FieldType, true);
if (uobj != newuobj)
{
if (isComponent && newuobj is GameObject go)
{
newuobj = go.GetComponent(fieldInfoData.FieldType);
}
newData = newuobj;
childElementChanged = true;
}
}
break;
case DrawerType.Enum:
if (eventType != EventType.Layout)
{
var enumData = UnsafeUtility.As<object, Enum>(ref data);
newData = EditorGUILayout.EnumPopup(label, enumData);
2025-04-16 09:36:51 +08:00
}
else
{
2025-05-14 20:19:40 +08:00
EditorGUILayout.EnumPopup(label, default);
2025-04-16 09:36:51 +08:00
}
2025-05-14 20:19:40 +08:00
break;
case DrawerType.EnumFlags:
2025-04-16 09:36:51 +08:00
2025-05-14 20:19:40 +08:00
if (eventType != EventType.Layout)
{
var enumData = UnsafeUtility.As<object, Enum>(ref data);
newData = EditorGUILayout.EnumFlagsField(label, enumData);
2025-04-16 09:36:51 +08:00
}
2025-05-14 20:19:40 +08:00
else
2025-04-16 09:36:51 +08:00
{
2025-05-14 20:19:40 +08:00
EditorGUILayout.EnumFlagsField(label, default);
}
2025-05-10 11:45:24 +08:00
2025-05-14 20:19:40 +08:00
break;
case DrawerType.Bool:
if (eventType != EventType.Layout)
{
newData = EditorGUILayout.Toggle(label, (bool)data);
2025-04-16 09:36:51 +08:00
}
2025-05-14 20:19:40 +08:00
else
2025-04-16 09:36:51 +08:00
{
2025-05-14 20:19:40 +08:00
EditorGUILayout.Toggle(label, default);
2025-04-16 09:36:51 +08:00
}
2025-05-14 20:19:40 +08:00
break;
case DrawerType.String:
if (eventType != EventType.Layout)
2025-04-16 09:36:51 +08:00
{
2025-05-14 20:19:40 +08:00
newData = EditorGUILayout.TextField(label, (string)data);
2025-04-16 09:36:51 +08:00
}
2025-05-14 20:19:40 +08:00
else
{
EditorGUILayout.TextField(label, default);
}
break;
case DrawerType.Float:
if (eventType != EventType.Layout)
{
newData = EditorGUILayout.FloatField(label, (float)data);
}
else
{
EditorGUILayout.FloatField(label, default);
}
break;
case DrawerType.Double:
if (eventType != EventType.Layout)
{
newData = EditorGUILayout.DoubleField(label, (double)data);
}
else
{
EditorGUILayout.DoubleField(label, default);
}
break;
case DrawerType.Byte:
if (eventType != EventType.Layout)
{
newData = (byte)EditorGUILayout.IntField(label, (byte)data);
}
else
{
EditorGUILayout.IntField(label, default);
}
break;
case DrawerType.SByte:
if (eventType != EventType.Layout)
{
newData = (sbyte)EditorGUILayout.IntField(label, (sbyte)data);
}
else
{
EditorGUILayout.IntField(label, default);
}
break;
case DrawerType.Short:
if (eventType != EventType.Layout)
{
newData = (short)EditorGUILayout.IntField(label, (short)data);
}
else
{
EditorGUILayout.IntField(label, default);
}
break;
case DrawerType.UShort:
if (eventType != EventType.Layout)
{
newData = (ushort)EditorGUILayout.IntField(label, (ushort)data);
}
else
{
EditorGUILayout.IntField(label, default);
}
break;
case DrawerType.Int:
if (eventType != EventType.Layout)
{
newData = (int)EditorGUILayout.IntField(label, (int)data);
}
else
{
EditorGUILayout.IntField(label, default);
}
break;
case DrawerType.UInt:
if (eventType != EventType.Layout)
{
newData = (uint)EditorGUILayout.IntField(label, (int)(uint)data);
}
else
{
EditorGUILayout.IntField(label, default);
}
break;
case DrawerType.Long:
if (eventType != EventType.Layout)
{
newData = EditorGUILayout.LongField(label, (long)data);
}
else
{
EditorGUILayout.LongField(label, default);
}
break;
case DrawerType.ULong:
if (eventType != EventType.Layout)
{
newData = (ulong)EditorGUILayout.LongField(label, (long)(ulong)data);
}
else
{
EditorGUILayout.LongField(label, default);
}
break;
default:
EditorGUILayout.LabelField(label, label2);
break;
2025-04-16 09:36:51 +08:00
}
2025-05-14 20:19:40 +08:00
2025-04-16 09:36:51 +08:00
expandMatrix.Up();
2025-05-14 20:19:40 +08:00
if (childElementChanged || EditorGUI.EndChangeCheck())
{
outData = newData;
return true;
}
return false;
2025-04-16 09:36:51 +08:00
}
#endregion
}
}
#endif