Example #1
0
        public static byte[] Serialize(RoomStats roomStats)
        {
            MemoryStream ms = new MemoryStream(24);

            ms.Write(BitConverter.GetBytes(roomStats.size), 0, 4);
            ms.Write(BitConverter.GetBytes(roomStats.b_up), 0, 1);
            ms.Write(BitConverter.GetBytes(roomStats.b_down), 0, 1);
            ms.Write(BitConverter.GetBytes(roomStats.b_left), 0, 1);
            ms.Write(BitConverter.GetBytes(roomStats.b_right), 0, 1);
            ms.Write(BitConverter.GetBytes(roomStats.up), 0, 1);
            ms.Write(BitConverter.GetBytes(roomStats.down), 0, 1);
            ms.Write(BitConverter.GetBytes(roomStats.left), 0, 1);
            ms.Write(BitConverter.GetBytes(roomStats.right), 0, 1);
            ms.Write(BitConverter.GetBytes(roomStats.x), 0, 4);
            ms.Write(BitConverter.GetBytes(roomStats.y), 0, 4);
            ms.Write(BitConverter.GetBytes(roomStats.z), 0, 4);

            return(ms.ToArray());
        }
Example #2
0
        public static RoomStats Deserialize(byte[] bytes)
        {
            RoomStats roomStats = new RoomStats
            {
                size    = BitConverter.ToInt32(bytes, 0),
                b_up    = BitConverter.ToBoolean(bytes, 4),
                b_down  = BitConverter.ToBoolean(bytes, 5),
                b_left  = BitConverter.ToBoolean(bytes, 6),
                b_right = BitConverter.ToBoolean(bytes, 7),
                up      = BitConverter.ToBoolean(bytes, 8),
                down    = BitConverter.ToBoolean(bytes, 9),
                left    = BitConverter.ToBoolean(bytes, 10),
                right   = BitConverter.ToBoolean(bytes, 11),
                x       = BitConverter.ToSingle(bytes, 12),
                y       = BitConverter.ToSingle(bytes, 16),
                z       = BitConverter.ToSingle(bytes, 20)
            };

            return(roomStats);
        }
Example #3
0
        public void Deserialize(byte[] bytes)
        {
            RoomStats roomStats = RoomStats.Deserialize(bytes);

            size    = roomStats.size;
            b_up    = roomStats.b_up;
            b_down  = roomStats.b_down;
            b_left  = roomStats.b_left;
            b_right = roomStats.b_right;
            up      = roomStats.up;
            down    = roomStats.down;
            left    = roomStats.left;
            right   = roomStats.right;

            Vector3 pos = new Vector3(roomStats.x, roomStats.y, roomStats.z);

            transform.position = pos;

            Create();
        }
Example #4
0
        public byte[] Serialize()
        {
            Vector3 pos = transform.position;

            RoomStats roomStats = new RoomStats
            {
                size    = size,
                b_up    = b_up,
                b_down  = b_down,
                b_left  = b_left,
                b_right = b_right,
                up      = up,
                down    = down,
                left    = left,
                right   = right,
                x       = pos.x,
                y       = pos.y,
                z       = pos.z
            };

            return(RoomStats.Serialize(roomStats));
        }