Fix using enums as Scene Animation Event parameters

#3554
This commit is contained in:
Wojtek Figat
2025-09-22 10:22:32 +02:00
parent a151c78412
commit e9a7b1c8eb
3 changed files with 54 additions and 7 deletions

View File

@@ -212,6 +212,10 @@ namespace FlaxEditor.Utilities
if (value is FlaxEngine.Object)
return value;
// For custom types use interface
if (value is ICloneable clonable)
return clonable.Clone();
// For objects (eg. arrays) we need to clone them to prevent editing default/reference value within editor
if (value != null && (!value.GetType().IsValueType || !value.GetType().IsClass))
{
@@ -548,6 +552,26 @@ namespace FlaxEditor.Utilities
return arr;
}
internal static void StructureToByteArray(object value, int valueSize, IntPtr tempBuffer, byte[] dataBuffer)
{
var valueType = value.GetType();
if (valueType.IsEnum)
{
var ptr = FlaxEngine.Interop.NativeInterop.ValueTypeUnboxer.GetPointer(value, valueType);
FlaxEngine.Utils.MemoryCopy(tempBuffer, ptr, (ulong)valueSize);
}
else
Marshal.StructureToPtr(value, tempBuffer, true);
Marshal.Copy(tempBuffer, dataBuffer, 0, valueSize);
}
internal static object ByteArrayToStructure(IntPtr valuePtr, Type valueType, int valueSize)
{
if (valueType.IsEnum)
return FlaxEngine.Interop.NativeInterop.MarshalToManaged(valuePtr, valueType);
return Marshal.PtrToStructure(valuePtr, valueType);
}
internal static unsafe string ReadStr(this BinaryReader stream, int check)
{
int length = stream.ReadInt32();