Files
test/Assets/Scripts/Task/SizeTest.cs
T
2025-11-01 19:21:48 +07:00

28 lines
672 B
C#

using System.Runtime.InteropServices;
using UnityEngine;
public class SizeTest : MonoBehaviour
{
[StructLayout(LayoutKind.Sequential, Pack = 1)]
public struct TestStruct
{
public int intValue;
public float floatValue;
[MarshalAs(UnmanagedType.U1)]
public bool byteValue;
}
[ContextMenu("Test Size")]
void TestSize()
{
TestStruct q = new();
var size = Marshal.SizeOf(typeof(TestStruct));
// byte[] data = new byte[Marshal.SizeOf(typeof(TestStruct))];
// q = Marshal.PtrToStructure<TestStruct>();
Debug.Log("Size of TestStruct: " + size);
}
}