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


C# EntityWorld.CreateEntityFromTemplate方法代码示例

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


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

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

示例2: Start

 void Start()
 {
     world = new EntityWorld (false, true, true);
     world.InitializeAll (true);
     Entity e = world.CreateEntityFromTemplate ("Ship");
     GameObject obj = new GameObject("Ship");
     PhysicsRelay relay = obj.AddComponent<PhysicsRelay>();
     relay.SetEntity (e);
 }
开发者ID:coryleeio,项目名称:SPClient,代码行数:9,代码来源:ECSTest.cs

示例3: TestAttributes

        public void TestAttributes()
        {
            Debug.WriteLine("Initialize EntityWorld: ");
            EntityWorld entityWorld = new EntityWorld { PoolCleanupDelay = 1 };
            #if (!FULLDOTNET && !METRO) || CLIENTPROFILE
            entityWorld.InitializeAll(global::System.Reflection.Assembly.GetExecutingAssembly());
            #else
            entityWorld.InitializeAll(true);
            #endif
            Debug.WriteLine("OK");

            const int ExpectedNumberOfSystems = 2;
            int actualNumberOfSystems = entityWorld.SystemManager.Systems.Count;
            Assert.AreEqual(ExpectedNumberOfSystems, actualNumberOfSystems, "Number of initial systems does not fit.");
            Debug.WriteLine("Number of Systems: {0} OK", actualNumberOfSystems);

            Debug.WriteLine("Build up entity with component from pool manually: ");
            Entity entityWithPooledComponent = TestEntityFactory.CreateTestPowerEntityWithPooledComponent(entityWorld);
            Debug.WriteLine("OK");

            Debug.WriteLine("Build up entity from template: ");
            Entity entityFromTemplate = entityWorld.CreateEntityFromTemplate("test");
            Assert.IsNotNull(entityFromTemplate, "Entity from test template is null.");
            Debug.WriteLine("OK");

            entityWorld.Update();
            entityWorld.Draw();

            Debug.WriteLine("Remove component from entity: ");
            entityWithPooledComponent.RemoveComponent<TestPowerComponentPoolable>();

            entityWorld.Update();
            entityWorld.Draw();

            Assert.IsFalse(entityWithPooledComponent.HasComponent<TestPowerComponentPoolable>(), "Entity has still deleted component.");
            Debug.WriteLine("OK");

            Debug.WriteLine("Add component to entity: ");
            entityWithPooledComponent.AddComponentFromPool<TestPowerComponentPoolable>();
            entityWithPooledComponent.GetComponent<TestPowerComponentPoolable>().Power = 100;

            entityWorld.Update();
            entityWorld.Draw();

            Assert.IsTrue(entityWithPooledComponent.HasComponent<TestPowerComponentPoolable>(), "Could not add component to entity.");
            Debug.WriteLine("OK");
        }
开发者ID:GrafSeismo,项目名称:artemis_CSharp,代码行数:47,代码来源:TestGeneral.cs

示例4: TestAttributes

        public void TestAttributes()
        {
            Debug.WriteLine("Initialize EntityWorld: ");
            EntityWorld entityWorld = new EntityWorld(false,true,true) { PoolCleanupDelay = 1 };
#if (!FULLDOTNET && !METRO) || CLIENTPROFILE
            entityWorld.InitializeAll(global::System.Reflection.Assembly.GetExecutingAssembly());       
#endif
            Debug.WriteLine("OK");

            const int ExpectedNumberOfSystems = 2;
            int actualNumberOfSystems = entityWorld.SystemManager.Systems.Count;
            Assert.AreEqual(ExpectedNumberOfSystems, actualNumberOfSystems, "Number of initial systems does not fit.");
            Debug.WriteLine("Number of Systems: {0} OK", actualNumberOfSystems);

            Debug.WriteLine("Build up entity with component from pool manually: ");
            Entity entityWithPooledComponent = TestEntityFactory.CreateTestPowerEntityWithPooledComponent(entityWorld);
            Debug.WriteLine("OK");

            Debug.WriteLine("Build up entity from template: ");
            Entity entityFromTemplate = entityWorld.CreateEntityFromTemplate("test");
            Assert.IsNotNull(entityFromTemplate, "Entity from test template is null.");
            Debug.WriteLine("OK");

            entityWorld.Update();
            entityWorld.Draw();

            Debug.WriteLine("Remove component from entity: ");
            entityWithPooledComponent.RemoveComponent<TestPowerComponentPoolable>();
       
            entityWorld.Update();
            entityWorld.Draw();

            Assert.IsFalse(entityWithPooledComponent.HasComponent<TestPowerComponentPoolable>(), "Entity has still deleted component.");
            Debug.WriteLine("OK");

            Debug.WriteLine("Add component to entity: ");
            entityWithPooledComponent.AddComponentFromPool<TestPowerComponentPoolable>();
            entityWithPooledComponent.GetComponent<TestPowerComponentPoolable>().Power = 100;

            entityWorld.Update();
            entityWorld.Draw();

            Assert.IsTrue(entityWithPooledComponent.HasComponent<TestPowerComponentPoolable>(), "Could not add component to entity.");
            Debug.WriteLine("OK");

            // TestNormalEntityProcessingSystem2 and TestNormalEntityProcessingSystem3 are autoloaded (marked with ArtemisEntitySystem attribute)
            List<TestNormalEntityProcessingSystem2> listOfTestNormalEntityProcessingSystem2 = entityWorld.SystemManager.GetSystems<TestNormalEntityProcessingSystem2>();
            Assert.IsNotNull(listOfTestNormalEntityProcessingSystem2, "Failed to retrieve autoloaded TestNormalEntityProcessingSystem2 system.");
            Assert.AreEqual(1, listOfTestNormalEntityProcessingSystem2.Count, "Invalid count of TestNormalEntityProcessingSystem2 systems");
            Debug.WriteLine("OK");

            List<TestNormalEntityProcessingSystem3> listOfTestNormalEntityProcessingSystem3 = entityWorld.SystemManager.GetSystems<TestNormalEntityProcessingSystem3>();
            Assert.IsNotNull(listOfTestNormalEntityProcessingSystem3, "Failed to retrieve autoloaded TestNormalEntityProcessingSystem3 system.");
            Assert.AreEqual(1, listOfTestNormalEntityProcessingSystem3.Count, "Invalid count of TestNormalEntityProcessingSystem3 systems");
            Debug.WriteLine("OK");

        }
开发者ID:kylepink,项目名称:artemis_CSharp,代码行数:57,代码来源:TestGeneral.cs

示例5: CreatePlayer

 /// <summary>
 /// Creates our Player.
 /// </summary>
 /// <param name="world">The Game's EntityWorld.</param>
 /// <returns>The Player that was just created.</returns>
 public static Entity CreatePlayer(EntityWorld world)
 {
     Player = world.CreateEntityFromTemplate("agent");
     return Player;
 }
开发者ID:krixalis,项目名称:Subject2Change,代码行数:10,代码来源:EntityFactory.cs

示例6: generate

        public void generate(EntityWorld entityWorld)
        {
            occupied = new bool[tileMap.Size.x, tileMap.Size.y];

            // Create border forest
            fillArea(generateArea(tileMap.Size / 2, (float)tileMap.Size.x + 1, (float)tileMap.Size.x + 1), 4);
            fillArea(generateArea(tileMap.Size / 2, 0f, (float)tileMap.Size.x / 2), 1);

            // Forest
            for (int i = 0; i < 16; ++i)
            {
                int2 pos = new int2(random.Next(tileMap.Size.x), random.Next(tileMap.Size.y));
                fillArea(generateArea(pos, 8f, 16f), 4);
            }

            // Small Forest
            for (int i = 0; i < 32; ++i)
            {
                int2 pos = new int2(random.Next(tileMap.Size.x), random.Next(tileMap.Size.y));
                fillArea(generateArea(pos, 2f, 8f), 4);
            }

            // Create player land
            fillArea(generateArea(new int2(18, 18), 4, 16), 2);
            fillArea(createPath(new Point(18, 18), new Point(tileMap.Size.x/2, tileMap.Size.y/2), 2, 0.5f), 2);

            // Paths:
            //float curliness = 0.75f;
            //for (int i = 0; i < 3; ++i)
            //{
            //    fillArea(createPath(new Point(0, 0), new Point(tileMap.Size.x - 1, tileMap.Size.y - 1), i + 2, curliness), 2);
            //    fillArea(createPath(new Point(0, 0), new Point(tileMap.Size.x - 1, tileMap.Size.y - 1), i + 2, curliness), 2);
            //    fillArea(createPath(new Point(0, 0), new Point(tileMap.Size.x - 1, tileMap.Size.y - 1), i + 2, curliness), 2);

            //    curliness *= 0.85f;
            //}

            List<Point> players = new List<Point>();
            players.Add(new Point(tileMap.Size.x / 6, tileMap.Size.y / 6));
            players.Add(new Point(tileMap.Size.x*3 / 6, tileMap.Size.y / 6));
            players.Add(new Point(tileMap.Size.x*5 / 6, tileMap.Size.y / 6));
            players.Add(new Point(tileMap.Size.x*5 / 6, tileMap.Size.y*5 / 6));
            players.Add(new Point(tileMap.Size.x*3 / 6, tileMap.Size.y*5 / 6));
            players.Add(new Point(tileMap.Size.x / 6, tileMap.Size.y*5 / 6));

            for (int i = 0; i < players.Count; ++i)
            {
                fillArea(createPath(players[i], players[(i+1)%players.Count], 5, 0.25f), 2);
                fillArea(generateArea(new int2(players[i].X, players[i].Y), 2, 16), 2);
                fillArea(generateArea(new int2(players[i].X, players[i].Y), 2, 4), 5);
            }
            fillArea(createPath(players[1], players[4], 5, 0.25f), 2);

            // River:
            Area riverArea = createPath(new Point(tileMap.Size.x - 1, 0), new Point(0, tileMap.Size.y - 1), 8, 0.5f);
            replaceArea(riverArea, 1, 3);
            replaceArea(riverArea, 2, 5);

            for (int x = 0; x < tileMap.Size.x; x++)
            {
                for (int y = 0; y < tileMap.Size.y; y++)
                {
                    float zoom = 0.05f;
                    if (tileMap.getTileID(x, y) == 4)
                    {
                        int treeWidth = 2;
                        int treeHeight = 2;

                        bool canPlaceTree = true;
                        for (int xt = 0; xt < treeWidth; xt++)
                        {
                            for (int yt = 0; yt < treeHeight; yt++)
                            {
                                int checkX = xt + x;
                                int checkY = yt + y;

                                if (checkX >= tileMap.Size.x || checkY >= tileMap.Size.y || occupied[checkX, checkY] || !tileMap.getTile(checkX, checkY).Name.Equals("tree"))
                                {
                                    canPlaceTree = false;
                                    break;
                                }
                            }
                            if (!canPlaceTree)
                                break;
                        }
                        if (!canPlaceTree)
                            continue;

                        entityWorld.CreateEntityFromTemplate("Resource", new object[] {
                            new int2(x, y),
                            (float)random.Next(360),
                            "wood",
                            500,
                            5
                        });

                        for (int xt = 0; xt < treeWidth; xt++)
                        {
                            for (int yt = 0; yt < treeHeight; yt++)
                            {
//.........这里部分代码省略.........
开发者ID:CheeseSoftware,项目名称:RTS-test,代码行数:101,代码来源:Generator.cs


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