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


C# EntityWorld.CreateEntity方法代码示例

本文整理汇总了C#中Artemis.EntityWorld.CreateEntity方法的典型用法代码示例。如果您正苦于以下问题:C# EntityWorld.CreateEntity方法的具体用法?C# EntityWorld.CreateEntity怎么用?C# EntityWorld.CreateEntity使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Artemis.EntityWorld的用法示例。


在下文中一共展示了EntityWorld.CreateEntity方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: LoadTiledMap

        // BuildEntity(entity, entityWorld)
        public static void LoadTiledMap(EntityWorld entityWorld, string mapFile, string tilesetLocation)
        {
            // Actual map entity. Contains map data. Rendering system draws map from this entity
            Entity tiledMapEntity = entityWorld.CreateEntity();
            tiledMapEntity.Tag = "map";
            tiledMapEntity.AddComponent(new TransformComponent());
            tiledMapEntity.AddComponent(new TiledMapComponent(mapFile, tilesetLocation));
            TmxMap tmxMap = tiledMapEntity.GetComponent<TiledMapComponent>().Map;
            List<Texture2D> textures = tiledMapEntity.GetComponent<TiledMapComponent>().Textures;

            // Farseer world associated with map
            Entity farseerWorldEntity = entityWorld.CreateEntity();
            farseerWorldEntity.AddComponent(new FarseerWorldComponent(9.81f));
            World world = farseerWorldEntity.GetComponent<FarseerWorldComponent>().world;
            
            foreach (var objLayer in tmxMap.ObjectGroups)
            {
                // Create entities for static objects in map
                // TODO: If there are performance issues, can optimize all static objects into single entity
                if (objLayer.Name == "collision")
                {
                    foreach (var tmxObj in objLayer.Objects)
                    {
                        Entity fixtureEntity = entityWorld.CreateEntity();
                        fixtureEntity.AddComponent(new FarseerFixtureComponent(tmxObj, world));
                    }
                }

                // Create dynamic objects
                // In particular starting location of player is in here
                if (objLayer.Name == "dynamic")
                {
                    foreach (var tmxObj in objLayer.Objects)
                    {
                        tmxObj.Properties.Add("BodyType", "Dynamic");
                        Entity dynamicEntity = entityWorld.CreateEntity();

                        if (tmxObj.Tile != null)
                        {
                            dynamicEntity.AddComponent(new TransformComponent());

                            Texture2D texture = GetTexture(tmxMap, textures, tmxObj.Tile.Gid);
                            dynamicEntity.AddComponent(new TextureComponent(texture));
                        }

                        dynamicEntity.AddComponent(new FarseerFixtureComponent(tmxObj, world));

                        if (tmxObj.Name == "player")
                        {
                            dynamicEntity.Tag = "player";
                        }
                    }
                }
            }

        }
开发者ID:AnotherProgrammingGroup,项目名称:Project-CS,代码行数:57,代码来源:LoadTiledMapUtility.cs

示例2: HybridQueueSystemTeste

        public static void HybridQueueSystemTeste()
        {
            EntityWorld world = new EntityWorld();
            SystemManager systemManager = world.SystemManager;
            HybridQueueSystemTest HybridQueueSystemTest = new ArtemisTest.HybridQueueSystemTest();
            EntitySystem hs = systemManager.SetSystem(HybridQueueSystemTest, ExecutionType.Update);
            systemManager.InitializeAll();

            List<Entity> l = new List<Entity>();
            for (int i = 0; i < 100; i++)
            {
                Entity et = world.CreateEntity();
                et.AddComponent(new Health());
                et.GetComponent<Health>().HP += 100;
                et.Refresh();
                l.Add(et);
            }

            for (int i = 0; i < 100; i++)
            {
                Entity et = world.CreateEntity();
                et.AddComponent(new Health());
                et.GetComponent<Health>().HP += 100;
                HybridQueueSystemTest.
                    AddToQueue(et);
                l.Add(et);
            }

            int j = 0;
            while (HybridQueueSystemTest.QueueCount > 0)
            {
                j++;
                DateTime dt = DateTime.Now;
                world.LoopStart();
                systemManager.UpdateSynchronous(ExecutionType.Update);
                Console.WriteLine((DateTime.Now - dt).TotalMilliseconds);
            }

            for (int i = 0; i < 100; i++)
            {
                Debug.Assert(l[i].GetComponent<Health>().HP == 100 - (10 * j));
            }

            for (int i = 100; i < 200; i++)
            {
                Debug.Assert(l[i].GetComponent<Health>().HP == 90);
            }
        }
开发者ID:hidra1,项目名称:artemis_CSharp,代码行数:48,代码来源:Test.cs

示例3: CreateTestHealthEntityWithId

 /// <summary>Creates the test health entity with ID.</summary>
 /// <param name="entityWorld">The entity world.</param>
 /// <param name="id">The id.</param>
 /// <returns>The Entity.</returns>
 public static Entity CreateTestHealthEntityWithId(EntityWorld entityWorld, long id)
 {
     Entity entity = entityWorld.CreateEntity(id);
     entity.AddComponent(new TestHealthComponent());
     entity.GetComponent<TestHealthComponent>().Points = 100;            
     return entity;
 }
开发者ID:KellanHiggins,项目名称:artemis_CSharp,代码行数:11,代码来源:TestEntityFactory.cs

示例4: AttributesTestsMethod

        public void AttributesTestsMethod()
        {
            EntityWorld world = new EntityWorld();
            world.PoolCleanupDelay = 1;
            world.InitializeAll();

            Debug.Assert(world.SystemManager.Systems.Size == 2);

            Entity et = world.CreateEntity();
            var power = et.AddComponentFromPool<Power2>();
            power.POWER = 100;
            et.Refresh();

            Entity et1 = world.CreateEntityFromTemplate("teste");
            Debug.Assert(et1 != null);

            {
                world.Update(0, ExecutionType.UpdateSynchronous);
            }

            et.RemoveComponent<Power2>();
            et.Refresh();

            {
                world.Update(0, ExecutionType.UpdateSynchronous);
            }

            et.AddComponentFromPool<Power2>();
            et.GetComponent<Power2>().POWER = 100;
            et.Refresh();

            world.Update(0, ExecutionType.UpdateSynchronous);
        }
开发者ID:dackjaniels2001,项目名称:artemis_CSharp,代码行数:33,代码来源:GeneralTest.cs

示例5: CreateStandAloneEntity

        public Entity CreateStandAloneEntity(EntityWorld world)
        {
            var entity = world.CreateEntity();
            entity.AddComponentFromPool<Transform>();
            entity.AddComponent(new SceneGraphComponent());
            entity.AddComponent(new SceneGraphRenderRoot<StandardShipModelRenderer>());
            CreateChildEntities(world, entity);

            return entity;
        }
开发者ID:raycrasher,项目名称:Fell-Sky,代码行数:10,代码来源:ShipModel.cs

示例6: TestAspectEmpty

        public void TestAspectEmpty()
        {
            Aspect aspect = Aspect.Empty();
            EntityWorld entityWorld = new EntityWorld();
            Entity entity;

            // Aspect.Empty is a base Aspect for EntitySystem meaning "no entities to process"
            entity = entityWorld.CreateEntity();
            Assert.IsFalse(aspect.Interests(entity), "Entity without components must NOT be subject to empty Aspect");

            entity = entityWorld.CreateEntity();
            entity.AddComponent(new TestHealthComponent());
            Assert.IsFalse(aspect.Interests(entity), "Entity with any component must NOT be subject to empty Aspect");

            entity = entityWorld.CreateEntity();
            entity.AddComponent(new TestPowerComponent());
            entity.AddComponent(new TestHealthComponent());
            Assert.IsFalse(aspect.Interests(entity), "Entity with any components must NOT be subject to empty Aspect");
        } 
开发者ID:KellanHiggins,项目名称:artemis_CSharp,代码行数:19,代码来源:TestAspect.cs

示例7: CreateEntity

 public override Entity CreateEntity(EntityWorld world, Entity ship, Entity parent, int? index = default(int?))
 {
     var entity = world.CreateEntity();
     parent.AddChild(entity);
     var xform = entity.AddComponentFromPool<Transform>();
     xform.CopyValuesFrom(Transform);
     var component = new DummyPartComponent(this, ship);
     entity.AddComponent(component);
     entity.AddComponent<IShipPartComponent>(component);
     entity.AddComponent(new BoundingBoxComponent(new FloatRect(-10, -10, 20, 20)));
     return entity;
 }
开发者ID:raycrasher,项目名称:Fell-Sky,代码行数:12,代码来源:DummyPart.cs

示例8: Install

        public virtual Entity Install(EntityWorld world, Entity shipEntity, Entity hardpointEntity)
        {
            var slot = hardpointEntity.GetComponent<HardpointComponent>();
            if (!hardpointEntity.IsChildOf(shipEntity)) throw new InvalidOperationException("Cannot install, ship entity does not own hardpoint entity.");
            if (slot == null) throw new InvalidOperationException("Cannot install on non-hardpoint entity.");
            var shipComponent = shipEntity.GetComponent<ShipComponent>();
            var moduleEntity = world.CreateEntity();

            var hardpointTransform = hardpointEntity.GetComponent<Transform>();
            var moduleTransform = moduleEntity.AddComponentFromPool<Transform>();
            moduleTransform.Position = Vector2.Zero;
            moduleTransform.Rotation = 0;
            moduleTransform.Scale = Vector2.One;
            moduleTransform.Origin = -hardpointTransform.Origin;            

            var scale = hardpointTransform.Scale;
            var origin = -hardpointTransform.Origin;
            if (scale.X < 0)
            {
                scale.X = Math.Abs(scale.X);
                origin.X *= -1;
            }
            if (scale.Y < 0)
            {
                scale.Y *= Math.Abs(scale.Y);
                origin.Y *= -1;
            }
            moduleTransform.Scale = scale;
            moduleTransform.Origin = origin;

            hardpointEntity.AddChild(moduleEntity);
            var previousInstalled = slot.InstalledEntity;
            if (previousInstalled != null)
            {
                previousInstalled.GetComponent<ModuleComponent>().Module.Uninstall(shipEntity, previousInstalled);
            }

            if (!string.IsNullOrWhiteSpace(PartGroupId))
            {
                ShipEntityFactory.GetShipModel(PartGroupId).CreateChildEntities(world, moduleEntity);
            }

            var moduleComponent = new ModuleComponent
            {
                HardpointEntity = hardpointEntity,
                Module = this
            };
            slot.InstalledEntity = moduleEntity;
            moduleEntity.AddComponent(moduleComponent);
            return moduleEntity;
        }
开发者ID:raycrasher,项目名称:Fell-Sky,代码行数:51,代码来源:Module.cs

示例9: CreateBulletExplosion

        public static Entity CreateBulletExplosion(EntityWorld world, float x, float y)
        {
            Entity e = world.CreateEntity();
            GamePool pool = (GamePool)world.Pool;
            e.SetGroup("EFFECTS");

            e.AddComponent(pool.TakeComponent<Transform>());
            e.AddComponent(pool.TakeComponent<SpatialForm>());
            e.AddComponent(pool.TakeComponent<Expires>());
            e.GetComponent<SpatialForm>().SpatialFormFile = "BulletExplosion";
            e.GetComponent<Expires>().LifeTime = 1000;
            e.GetComponent<Transform>().Coords = new Vector3(x, y, 0);
            return e;
        }
开发者ID:raittd,项目名称:starwarrior_CSharp,代码行数:14,代码来源:EntityFactory.cs

示例10: 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

示例11: 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

示例12: 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

示例13: DummyTests

        public void DummyTests()
        {
            EntityWorld world = new EntityWorld();
            SystemManager systemManager = world.SystemManager;
            DummyCommunicationSystem DummyCommunicationSystem = new DummyCommunicationSystem();
            systemManager.SetSystem(DummyCommunicationSystem, ExecutionType.UpdateSynchronous);
            world.InitializeAll(false);

            for (int i = 0; i < 100; i++)
            {
                Entity et = world.CreateEntity();
                et.AddComponent(new Health());
                et.GetComponent<Health>().HP += 100;
                et.Group = "teste";
                et.Refresh();
            }

            {
                Entity et = world.CreateEntity();
                et.Tag = "tag";
                et.AddComponent(new Health());
                et.GetComponent<Health>().HP += 100;
                et.Refresh();
            }

            {
                DateTime dt = DateTime.Now;
                world.Update(0);
                Console.WriteLine((DateTime.Now - dt).TotalMilliseconds);
            }

            Debug.Assert(world.TagManager.GetEntity("tag") != null);
            Debug.Assert(world.GroupManager.GetEntities("teste").Size == 100);
            Debug.Assert(world.EntityManager.ActiveEntitiesCount == 101);
            Debug.Assert(world.SystemManager.Systems.Size == 1);
        }
开发者ID:dackjaniels2001,项目名称:artemis_CSharp,代码行数:36,代码来源:GeneralTest.cs

示例14: Awake

    // Use this for initialization
    void Awake()
    {
        world = new EntityWorld();

        for(int i = 0; i< 5; ++i){
            Entity e = world.CreateEntity();
            TestComp1 te = new TestComp1();
            e.AddComponent(te);
        }
        EntitySystem.BlackBoard.SetEntry<TestProcessor>("test1", new TestProcessor());
        //world.RefreshEntity();
        TestProcessor processor = new TestProcessor();
        TestProcessor2 processor2 = new TestProcessor2();
        world.SystemManager.SetSystem<TestProcessor>(processor,Artemis.Manager.GameLoopType.Update);
        //		world.SystemManager.SetSystem<TestProcessor2>(processor2,Artemis.Manager.GameLoopType.Update);
    }
开发者ID:kokichi88,项目名称:ArtemisForUnity,代码行数:17,代码来源:Main.cs

示例15: multi

        static void multi()
        {
            healthBag.Add(new Health());
            healthBag.Add(new Health());
            componentPool.Add(typeof(Health), healthBag);

            Bag<Component> tempBag;
            EntityWorld world = new EntityWorld();
            SystemManager systemManager = world.GetSystemManager();
            world.GetEntityManager().RemovedComponentEvent += new RemovedComponentHandler(RemovedComponent);
            world.GetEntityManager().RemovedEntityEvent += new RemovedEntityHandler(RemovedEntity);

            EntitySystem hs = systemManager.SetSystem(new MultHealthBarRenderSystem(),ExecutionType.Update);
            //EntitySystem hs = systemManager.SetSystem(new SingleHEAVYHealthBarRenderSystem(),ExecutionType.Update);
            systemManager.InitializeAll();

            List<Entity> l = new List<Entity>();
            for (int i = 0; i < 1000; i++)
            {
                Entity et = world.CreateEntity();
                et.AddComponent(new Health());
                et.GetComponent<Health>().AddHealth(100);
                et.Refresh();
                l.Add(et);
            }

            for (int i = 0; i < 100; i++)
            {
                DateTime dt = DateTime.Now;
                world.LoopStart();                
                systemManager.UpdateSynchronous(ExecutionType.Update);
                Console.WriteLine((DateTime.Now - dt).TotalMilliseconds);
            }            

            int df = 0;
            foreach (var item in l)
            {
                if (item.GetComponent<Health>().GetHealth() == 90)
                {
                    df++;
                }
            }

 
            Console.ReadLine();
        }
开发者ID:brunoduartec,项目名称:port-ploobsengine,代码行数:46,代码来源:Test.cs


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