public static Offset <ObjectList> CreateObjectList(FlatBufferBuilder builder, VectorOffset listOffset = default(VectorOffset), ushort length = 0) { builder.StartObject(2); ObjectList.AddList(builder, listOffset); ObjectList.AddLength(builder, length); return(ObjectList.EndObjectList(builder)); }
public static byte[] SerializeSyncObject(Dictionary <int, GameObject> dic) { var builder = new FlatBufferBuilder(1); int length = dic.Count; Offset <SyncObject>[] off = new Offset <SyncObject> [length]; int index = 0; foreach (var item in dic) { Transform transform = item.Value.transform; SyncObject.StartSyncObject(builder); SyncObject.AddId(builder, (ushort)item.Key); SyncObject.AddPos(builder, Vec3.CreateVec3(builder, transform.position.x, transform.position.y, transform.position.z)); SyncObject.AddRot(builder, Vec4.CreateVec4(builder, transform.rotation.x, transform.rotation.y, transform.rotation.z, transform.rotation.w)); SyncObject.AddScale(builder, Vec3.CreateVec3(builder, transform.localScale.x, transform.localScale.y, transform.localScale.z)); off[index] = SyncObject.EndSyncObject(builder); index++; } var objs = ObjectList.CreateListVector(builder, off); ObjectList.StartObjectList(builder); ObjectList.AddLength(builder, (ushort)length); ObjectList.AddList(builder, objs); var list = ObjectList.EndObjectList(builder); ObjectList.FinishObjectListBuffer(builder, list); using (var ms = new MemoryStream(builder.DataBuffer.Data, builder.DataBuffer.Position, builder.Offset)) { var data = ms.ToArray(); return(data); } }