Update RuntimeComponentsDrawer.cs

This commit is contained in:
DCFApixels 2025-04-21 00:10:57 +08:00
parent fdbdb94b0c
commit 84401b875d

View File

@ -82,7 +82,14 @@ namespace DCFApixels.DragonECS.Unity.Editors.X
ResetWrappers(); ResetWrappers();
IsUnmanaged = UnsafeUtility.IsUnmanaged(type); IsUnmanaged = UnsafeUtility.IsUnmanaged(type);
IsUnityObjectType = typeof(UnityObject).IsAssignableFrom(type); IsUnityObjectType = typeof(UnityObject).IsAssignableFrom(type);
IsUnitySerializable = IsUnityObjectType || (!type.IsGenericType && type.IsSerializable); IsUnitySerializable =
IsUnityObjectType ||
//typeof(Array).IsAssignableFrom(type) ||
//(type.IsGenericType && type.GetGenericTypeDefinition() == typeof(List<>)) ||
//type.IsPrimitive ||
//type == typeof(string) ||
//type.IsEnum ||
(!type.IsGenericType && type.IsSerializable && type.HasAttribute<System.SerializableAttribute>());
if (type == typeof(void)) { return; } if (type == typeof(void)) { return; }
@ -108,7 +115,7 @@ namespace DCFApixels.DragonECS.Unity.Editors.X
public readonly Type FieldType; public readonly Type FieldType;
public readonly string UnityFormatName; public readonly string UnityFormatName;
public readonly bool IsUnityObjectField; public readonly bool IsUnityObjectField;
public readonly bool IsPassToSerialize; public readonly bool IsPassToUnitySerialize;
public readonly RuntimeComponentReflectionCache ValueTypeReflectionCache; public readonly RuntimeComponentReflectionCache ValueTypeReflectionCache;
public FieldInfoData(FieldInfo fieldInfo) public FieldInfoData(FieldInfo fieldInfo)
{ {
@ -116,7 +123,7 @@ namespace DCFApixels.DragonECS.Unity.Editors.X
FieldType = fieldInfo.FieldType; FieldType = fieldInfo.FieldType;
IsUnityObjectField = typeof(UnityObject).IsAssignableFrom(fieldInfo.FieldType); IsUnityObjectField = typeof(UnityObject).IsAssignableFrom(fieldInfo.FieldType);
UnityFormatName = UnityEditorUtility.TransformFieldName(fieldInfo.Name); UnityFormatName = UnityEditorUtility.TransformFieldName(fieldInfo.Name);
IsPassToSerialize = IsPassToUnitySerialize =
(fieldInfo.IsPublic || fieldInfo.HasAttribute<SerializeField>() || fieldInfo.HasAttribute<SerializeReference>()) && (fieldInfo.IsPublic || fieldInfo.HasAttribute<SerializeField>() || fieldInfo.HasAttribute<SerializeReference>()) &&
(fieldInfo.IsInitOnly || fieldInfo.HasAttribute<System.NonSerializedAttribute>()) == false; (fieldInfo.IsInitOnly || fieldInfo.HasAttribute<System.NonSerializedAttribute>()) == false;
ValueTypeReflectionCache = FieldType.IsValueType ? GetRuntimeComponentReflectionCache(FieldType) : null; ValueTypeReflectionCache = FieldType.IsValueType ? GetRuntimeComponentReflectionCache(FieldType) : null;
@ -127,7 +134,7 @@ namespace DCFApixels.DragonECS.Unity.Editors.X
FieldType = fieldType; FieldType = fieldType;
UnityFormatName = unityFormatName; UnityFormatName = unityFormatName;
IsUnityObjectField = typeof(UnityObject).IsAssignableFrom(fieldType); IsUnityObjectField = typeof(UnityObject).IsAssignableFrom(fieldType);
IsPassToSerialize = isPassToSerialize; IsPassToUnitySerialize = isPassToSerialize;
ValueTypeReflectionCache = FieldType.IsValueType ? GetRuntimeComponentReflectionCache(FieldType) : null; ValueTypeReflectionCache = FieldType.IsValueType ? GetRuntimeComponentReflectionCache(FieldType) : null;
} }
public RuntimeComponentReflectionCache GetReflectionCache(Type type) public RuntimeComponentReflectionCache GetReflectionCache(Type type)
@ -373,6 +380,8 @@ namespace DCFApixels.DragonECS.Unity.Editors.X
if (isExpanded) if (isExpanded)
{ {
using (EcsGUI.UpIndentLevel()) using (EcsGUI.UpIndentLevel())
{
if (cache != null)
{ {
for (int j = 0, jMax = cache.Fields.Length; j < jMax; j++) for (int j = 0, jMax = cache.Fields.Length; j < jMax; j++)
{ {
@ -385,6 +394,8 @@ namespace DCFApixels.DragonECS.Unity.Editors.X
} }
} }
} }
}
} }
} }
else else
@ -427,9 +438,16 @@ namespace DCFApixels.DragonECS.Unity.Editors.X
wrapper.IsExpanded = isExpanded; wrapper.IsExpanded = isExpanded;
try try
{
if (fieldInfoData.IsPassToUnitySerialize)
{ {
EditorGUILayout.PropertyField(wrapper.Property, label, true); EditorGUILayout.PropertyField(wrapper.Property, label, true);
} }
else
{
EditorGUILayout.LabelField(label, " ");
}
}
catch (ArgumentException) catch (ArgumentException)
{ {
if (Event.current.type != EventType.Repaint) if (Event.current.type != EventType.Repaint)