Files
sbox-public/engine/Sandbox.Engine/Resources/Animation/AnimationGraph.Native.cs
s&box team 71f266059a Open source release
This commit imports the C# engine code and game files, excluding C++ source code.

[Source-Commit: ceb3d758046e50faa6258bc3b658a30c97743268]
2025-11-24 09:05:18 +00:00

46 lines
1.0 KiB
C#

using System.Runtime.InteropServices;
namespace NativeEngine;
internal enum AnimParamType : byte
{
Unknown = 0,
Bool,
Enum,
Int,
Float,
Vector,
Rotation,
};
[StructLayout( LayoutKind.Explicit, Pack = 1, Size = 17 )]
internal struct AnimVariant
{
[FieldOffset( 0 )]
public Vector4 Value;
[FieldOffset( 16 )]
public AnimParamType Type;
public T GetValue<T>()
{
return Type switch
{
AnimParamType.Bool => (T)Bool,
AnimParamType.Int => (T)Int,
AnimParamType.Enum => (T)Enum,
AnimParamType.Float => (T)Float,
AnimParamType.Vector => (T)Vector,
AnimParamType.Rotation => (T)Rotation,
_ => default,
};
}
internal object Bool => BitConverter.GetBytes( Value.x )[0] != 0;
internal object Int => BitConverter.ToInt32( BitConverter.GetBytes( Value.x ), 0 );
internal object Enum => BitConverter.GetBytes( Value.x )[0];
internal object Float => Value.x;
internal object Vector => new Vector3( Value.x, Value.y, Value.z );
internal object Rotation => new Rotation( Value.x, Value.y, Value.z, Value.w );
}