Beispiel #1
0
    public byte[] StructToArray()
    {
        int             childCnt  = transform.childCount;
        StructFurniture furniture = new StructFurniture();
        int             size      = Marshal.SizeOf(furniture);

        byte[] furnitures = new byte[size * transform.childCount];
        byte[] temp;

        for (int i = 0; i < childCnt; i++)
        {
            //자식 가구 Transform 받아옴
            Transform cur = transform.GetChild(i);

            //가구 정보 할당
            furniture.x1   = cur.position.x;
            furniture.y1   = cur.position.y;
            furniture.z1   = cur.position.z;
            furniture.x2   = cur.rotation.x;
            furniture.y2   = cur.rotation.y;
            furniture.z2   = cur.rotation.z;
            furniture.w2   = cur.rotation.w;
            furniture.name = cur.name;

            temp = getBytes(furniture);
            Array.Copy(temp, 0, furnitures, i * size, size);
        }

        return(furnitures);
    }
Beispiel #2
0
    byte[] getBytes(StructFurniture str)
    {
        int size = Marshal.SizeOf(str);

        byte[] arr = new byte[size];

        IntPtr ptr = Marshal.AllocHGlobal(size);

        Marshal.StructureToPtr(str, ptr, true);
        Marshal.Copy(ptr, arr, 0, size);
        Marshal.FreeHGlobal(ptr);
        return(arr);
    }
Beispiel #3
0
    StructFurniture fromBytes(byte[] arr)
    {
        StructFurniture str = new StructFurniture();

        int    size = Marshal.SizeOf(str);
        IntPtr ptr  = Marshal.AllocHGlobal(size);

        Marshal.Copy(arr, 0, ptr, size);

        str = (StructFurniture)Marshal.PtrToStructure(ptr, str.GetType());
        Marshal.FreeHGlobal(ptr);

        return(str);
    }