public void Iteration(ref EntityChunk chunk, int index) { Vector3 pos = Vector3.Zero; if (chunk.TryGetComponent(index, out C_Position positionComponent)) { pos = (Vector3)positionComponent.value; } Quaternion rot = Quaternion.Identity; if (chunk.TryGetComponent(index, out C_Rotation rotationComponent)) { rot = rotationComponent.value; } Vector3 scale = Vector3.One; if (chunk.TryGetComponent(index, out C_UniformScale scaleComponent)) { scale *= scaleComponent.value; } Matrix4 transform = Matrix4.Identity; transform *= Matrix4.CreateScale(scale); transform *= Matrix4.CreateFromQuaternion(rot); transform *= Matrix4.CreateTranslation(pos); chunk.SetComponent(index, new C_Transform() { value = transform }); }
public void SetComponent <T0>(Entity entity, T0 component) where T0 : IComponent { for (int i = 0; i < chunks.Count; i++) { ref EntityChunk chunk = ref chunks[i]; for (int e = 0; e < chunk.Count; e++) { Entity currEntity = chunk.GetEntity(e); if (currEntity.id == entity.id) { chunk.SetComponent(e, component); chunk.UpdateVersion(version); return; } } }