public void Initialize <TC0, TC1>(uint id, TC0 component0, TC1 component1) where TC0 : class, IEcsComponent, new() where TC1 : class, IEcsComponent, new() { Id = id; byte index0 = EcsComponentType <TC0> .Index; byte index1 = EcsComponentType <TC1> .Index; _archetype = _archetypeManager.FindOrCreateArchetype(index0, index1); _archetype.AddComponent(index0, component0); _archetype.AddComponent(index1, component1); _archetype.AddEntity(this); }
internal void AddComponent(byte index, IEcsComponent component) { EcsArchetype newArchetype = _archetypeManager.FindOrCreateNextArchetype(_archetype, index); foreach (byte curIndex in _archetype.Indices) { IEcsComponentPool componentPool = _archetype.GetComponentPool(curIndex); newArchetype.AddComponent(curIndex, componentPool.Get(ArchetypeIndex)); } newArchetype.AddComponent(index, component); _archetype.RemoveEntity(this); _archetype = newArchetype; _archetype.AddEntity(this); }
internal void RemoveComponent(byte index) { EcsArchetype newArchetype = _archetypeManager.FindOrCreatePriorArchetype(_archetype, index); foreach (byte curIndex in _archetype.Indices) { if (curIndex == index) { continue; } IEcsComponentPool componentPool = _archetype.GetComponentPool(curIndex); newArchetype.AddComponent(curIndex, componentPool.Get(ArchetypeIndex)); } _archetype.RemoveEntity(this); _archetype = newArchetype; _archetype.AddEntity(this); }