public static void Register() { _isRegister = true; _index = EcsTypeManager.RegisterType <TC>(); Serializer.RegisterType(typeof(TC)); }
/// <summary> /// Reads data from DataReader, and updates the world of entities. /// </summary> /// <param name="data">data</param> public void Update(byte[] data) { using (BinaryDataReader reader = new BinaryDataReader(data)) { while (reader.Position < reader.Length) { uint key = reader.ReadUInt(); if (key == uint.MaxValue) { break; } if (!_entities.TryGetValue(key, out EcsEntityExtended entity)) { entity = CreateEntity(key); } using (BinaryDataReader entityReader = reader.ReadNode()) { while (entityReader.Position < entityReader.Length) { byte index = entityReader.ReadByte(); if (index == byte.MaxValue) { break; } using (BinaryDataReader componentReader = entityReader.ReadNode()) { IEcsComponent component; if (entity.HasComponent(index)) { component = entity.GetComponent(index); } else { component = EcsTypeManager.CreateComponent(index); entity.AddComponent(index, component); } Serializer.GetSerializer(EcsTypeManager.Types[index]) .Update(component, componentReader); } } while (entityReader.Position < entityReader.Length) { entity.RemoveComponent(entityReader.ReadByte()); } } } while (reader.Position < reader.Length) { _entities[reader.ReadUInt()].Destroy(); } } }