This commit is contained in:
DCFApixels 2025-04-19 00:16:06 +08:00
parent ba4e103337
commit 67477ef90d
4 changed files with 20 additions and 22 deletions

View File

@ -163,7 +163,7 @@ namespace DCFApixels.DragonECS.Unity.Editors
if (_fieldProperty != null)
{
_fieldProperty.managedReferenceValue = cmptmp.Clone();
_fieldProperty.managedReferenceValue = cmptmp.Clone_Reflection();
_fieldProperty.serializedObject.ApplyModifiedProperties();
}
}

View File

@ -33,6 +33,20 @@ namespace DCFApixels.DragonECS.Unity.Internal
{
return self.IsSubclassOf(typeof(UnityObject));
}
private static MethodInfo memberwiseCloneMethdo = typeof(object).GetMethod("MemberwiseClone", BindingFlags.Instance | BindingFlags.NonPublic);
internal static object Clone_Reflection(this object obj)
{
if (obj is ICloneable cloneable)
{
return cloneable.Clone();
}
return memberwiseCloneMethdo.Invoke(obj, null);
}
internal static object Clone_Reflection<T>(this T obj)
{
return Clone_Reflection((object)obj);
}
}
}
#endif

View File

@ -50,7 +50,7 @@ namespace DCFApixels.DragonECS.Unity.Editors
private static void SelectComponent(ComponentTemplatesDropDown.Item item)
{
//EcsGUI.Changed = true;
currentProperty.managedReferenceValue = item.Obj.Clone();
currentProperty.managedReferenceValue = item.Obj.Clone_Reflection();
currentProperty.isExpanded = false;
currentProperty.serializedObject.ApplyModifiedProperties();
}

View File

@ -145,22 +145,6 @@ namespace DCFApixels.DragonECS
}
}
namespace DCFApixels.DragonECS.Unity.Internal
{
internal static class ComponentTemplateExtensions
{
private static MethodInfo memberwiseCloneMethdo = typeof(object).GetMethod("MemberwiseClone", BindingFlags.Instance | BindingFlags.NonPublic);
internal static IComponentTemplate Clone(this IComponentTemplate obj)
{
if(obj is ICloneable cloneable)
{
return (IComponentTemplate)cloneable.Clone();
}
return (IComponentTemplate)memberwiseCloneMethdo.Invoke(obj, null);
}
}
}
#if UNITY_EDITOR
namespace DCFApixels.DragonECS.Unity.Editors
{
@ -182,10 +166,10 @@ namespace DCFApixels.DragonECS.Unity.Editors
Type interfaceType = typeof(IComponentTemplate);
_types = UnityEditorUtility._serializableTypes.Where(type => interfaceType.IsAssignableFrom(type)).ToArray();
foreach (var type in _types)
{
EcsDebugUtility.GetTypeMeta(type);
}
//foreach (var type in _types)
//{
// EcsDebugUtility.GetTypeMeta(type);
//}
_dummies = new IComponentTemplate[_types.Length];
for (int i = 0; i < _types.Length; i++)