当前位置: 首页>>代码示例>>C#>>正文


C# EntityWorld.GetPool方法代码示例

本文整理汇总了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;
		}
开发者ID:Nailz,项目名称:MonoGame-Samples,代码行数:14,代码来源:EntityFactory.cs

示例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;
		}
开发者ID:Nailz,项目名称:MonoGame-Samples,代码行数:14,代码来源:EntityFactory.cs

示例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;
		}
开发者ID:Nailz,项目名称:MonoGame-Samples,代码行数:14,代码来源:EntityFactory.cs

示例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);
        }
开发者ID:kylepink,项目名称:artemis_CSharp,代码行数:79,代码来源:TestGeneral.cs


注:本文中的Artemis.EntityWorld.GetPool方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。