本文整理汇总了C#中Artemis.EntityWorld.GetPool方法的典型用法代码示例。如果您正苦于以下问题:C# EntityWorld.GetPool方法的具体用法?C# EntityWorld.GetPool怎么用?C# EntityWorld.GetPool使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Artemis.EntityWorld
的用法示例。
在下文中一共展示了EntityWorld.GetPool方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: CreateShipExplosion
public static Entity CreateShipExplosion(EntityWorld world, float x, float y)
{
Entity e = world.CreateEntity();
GamePool pool = (GamePool)world.GetPool();
e.SetGroup("EFFECTS");
e.AddComponent(pool.TakeComponent<Transform>());
e.AddComponent(pool.TakeComponent<SpatialForm>());
e.AddComponent(pool.TakeComponent<Expires>());
e.GetComponent<SpatialForm>().SetSpatialFormFile("ShipExplosion");
e.GetComponent<Transform>().SetCoords(new Vector3(x, y, 0));
e.GetComponent<Expires>().SetLifeTime(1000);
return e;
}
示例2: CreateMissile
public static Entity CreateMissile(EntityWorld world)
{
Entity missile = world.CreateEntity();
GamePool pool = (GamePool)world.GetPool();
missile.SetGroup("BULLETS");
missile.AddComponent(pool.TakeComponent<Transform>());
missile.AddComponent(pool.TakeComponent<SpatialForm>());
missile.AddComponent(pool.TakeComponent<Velocity>());
missile.AddComponent(pool.TakeComponent<Expires>());
missile.GetComponent<SpatialForm>().SetSpatialFormFile("Missile");
missile.GetComponent<Expires>().SetLifeTime(2000);
return missile;
}
示例3: CreateEnemyShip
public static Entity CreateEnemyShip(EntityWorld world) {
Entity e = world.CreateEntity();
e.SetGroup("SHIPS");
GamePool pool = (GamePool)world.GetPool();
e.AddComponent(pool.TakeComponent<Transform>());
e.AddComponent(pool.TakeComponent<SpatialForm>());
e.AddComponent(pool.TakeComponent<Health>());
e.AddComponent(pool.TakeComponent<Weapon>());
e.AddComponent(pool.TakeComponent<Enemy>());
e.AddComponent(pool.TakeComponent<Velocity>());
e.GetComponent<SpatialForm>().SetSpatialFormFile("EnemyShip");
e.GetComponent<Health>().SetHealth(10);
return e;
}
示例4: TestPoolableComponents
public void TestPoolableComponents()
{
var entityWorld = new EntityWorld(isSortedEntities: false, processAttributes: true, initializeAll: true) { PoolCleanupDelay = 0 };
var pool = (ComponentPool<ComponentPoolable>)entityWorld.GetPool(typeof(TestPowerComponentPoolable));
Debug.WriteLine("ComponentPool<TestPowerComponentPoolable> is not Null:");
Assert.IsNotNull(pool);
Debug.WriteLine("OK");
var poolAttribute = (ArtemisComponentPool) typeof(TestPowerComponentPoolable).GetCustomAttributes(typeof(ArtemisComponentPool), false).Single();
Assert.AreEqual(poolAttribute.InitialSize, pool.InvalidCount, "Initially component pool should contain only invalid items");
int expectedPower = default(int);
var addedComponentEventHandler = new AddedComponentHandler((e, c) =>
{
Debug.WriteLine("TestPowerComponentPoolable added: ");
Assert.AreEqual(typeof (TestPowerComponentPoolable), c.GetType());
Debug.WriteLine("OK");
Debug.WriteLine("TestPowerComponentPoolable.Power == {0}:", expectedPower);
Assert.AreEqual(expectedPower, ((TestPowerComponentPoolable) c).Power);
Debug.WriteLine("OK");
});
entityWorld.EntityManager.AddedComponentEvent += addedComponentEventHandler;
Entity entity = entityWorld.CreateEntity();
Debug.WriteLine("Adding FRESH uninitialized TestPowerComponentPoolable from pool (expected power = {0})", default(int));
TestPowerComponentPoolable testPowerComponent = entity.AddComponentFromPool<TestPowerComponentPoolable>();
Assert.AreEqual(expectedPower, testPowerComponent.Power);
Assert.AreEqual(expectedPower, entity.GetComponent<TestPowerComponentPoolable>().Power);
entity.RemoveComponent<TestPowerComponentPoolable>();
entityWorld.Update();
Assert.IsFalse(entity.HasComponent<TestPowerComponentPoolable>());
expectedPower = 100;
Debug.WriteLine("Adding initialized TestPowerComponentPoolable from pool (expected power = {0})", expectedPower);
entity.AddComponentFromPool<TestPowerComponentPoolable>(c => c.Power = expectedPower);
Assert.AreEqual(expectedPower, entity.GetComponent<TestPowerComponentPoolable>().Power);
entity.RemoveComponent<TestPowerComponentPoolable>();
entityWorld.Update();
Assert.IsFalse(entity.HasComponent<TestPowerComponentPoolable>());
entityWorld.EntityManager.AddedComponentEvent -= addedComponentEventHandler;
Debug.WriteLine("Causing ComponentPool<TestPowerComponentPoolable> to fill up to maximum capacity...");
var entities = new List<Entity>();
while (pool.InvalidCount > 0)
{
var ent = entityWorld.CreateEntity();
ent.AddComponentFromPool<TestPowerComponentPoolable>(c => c.Power = expectedPower);
entities.Add(ent);
}
foreach (var ent in entities)
{
ent.RemoveComponent<TestPowerComponentPoolable>();
}
Debug.WriteLine("Causing ComponentPool<TestPowerComponentPoolable> cleanup...");
entityWorld.Update();
Assert.AreEqual(poolAttribute.InitialSize, pool.InvalidCount, "Cleaned up component pool should contain only invalid items");
Debug.WriteLine("OK");
entityWorld.EntityManager.AddedComponentEvent += addedComponentEventHandler;
Debug.WriteLine("Adding USED uninitialized TestPowerComponentPoolable from pool (expected power = {0})", expectedPower);
testPowerComponent = entity.AddComponentFromPool<TestPowerComponentPoolable>();
Assert.AreEqual(expectedPower, testPowerComponent.Power);
Assert.AreEqual(expectedPower, entity.GetComponent<TestPowerComponentPoolable>().Power);
}