void LoadInitialSystem() { UInt16 count = ReadInt16(); int packetSize = count * MeshFirstPacketSize; byte[] b = new byte[packetSize]; stream.Read(b, 0, b.Length); PacketDecoder decoder = new PacketDecoder(ref b); //List<SpaceObject> spaceObjects = new List<SpaceObject>(); foreach (var item in SpaceObjects) { SceneSystem.SceneInstance.RootScene.Entities.Remove(item.Value.entityRef); } SpaceObjects.Clear(); for (ushort i = 0; i < count; i++) { int id = decoder.Read_UInt16(); ListOf_Entity type = (ListOf_Entity)decoder.Read_UInt16(); Vector3 location = decoder.Read_Vector3(); Vector3 scale = decoder.Read_Vector3(); Quaternion rotation = decoder.Read_Quat(); Entity entitieRef = AddObject(type, id, location, scale, rotation); SpaceObjects.Add(id, new SpaceObject(ref entitieRef, type)); } }
Entity AddObject(ListOf_Entity objectType, int Id, Vector3 locaiton, Vector3 scale, Quaternion rotation) { Model model = Models[objectType]; // Create a new entity to add to the scene Entity entity = new Entity(locaiton, $"Object_{Id}") { new ModelComponent { Model = model } }; entity.Transform.Rotation = rotation; entity.Transform.Scale = scale; // Add a new entity to the scene SceneSystem.SceneInstance.RootScene.Entities.Add(entity); return(entity); }
public SpaceObject(ref Entity entity, ListOf_Entity type) { entityRef = entity; ObjectType = type; }