Make sure that your DestroyComponent
is added to all the pools you want it to be added to. Then add the system using pools.CreateSystem(new DestroySystem())
, where pools
is an instance of Pools
which has all the systems you added the component to.
Last active
February 15, 2017 19:12
-
-
Save bddckr/5743c492e730858189bf126fc779c3aa to your computer and use it in GitHub Desktop.
A system to destroy entities in Entitas, for all pools
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Collections.Generic; | |
using System.Linq; | |
using Entitas; | |
public sealed class DestroySystem : ISetPools, IGroupObserverSystem | |
{ | |
public GroupObserver groupObserver | |
{ | |
get | |
{ | |
var poolsCount = _allPools.Length; | |
var groups = new Group[poolsCount]; | |
var eventTypes = new GroupEventType[poolsCount]; | |
for (var poolIndex = 0; poolIndex < poolsCount; poolIndex++) | |
{ | |
var pool = _allPools[poolIndex]; | |
var componentIndex = Array.IndexOf(pool.metaData.componentTypes, typeof(DestroyComponent)); | |
if (componentIndex == -1) | |
{ | |
continue; | |
} | |
groups[poolIndex] = pool.GetGroup(Matcher.AllOf(componentIndex)); | |
eventTypes[poolIndex] = GroupEventType.OnEntityAdded; | |
} | |
return new GroupObserver(groups, eventTypes); | |
} | |
} | |
private Pool[] _allPools; | |
public void SetPools(Pools pools) | |
{ | |
_allPools = pools.allPools; | |
} | |
public void Execute(List<Entity> entities) | |
{ | |
foreach (var entity in entities) | |
{ | |
_allPools.First(pool => pool.HasEntity(entity)).DestroyEntity(entity); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
For Entitas 0.37.0(+) see this gist.