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


C# EntityManager.CreateEntity方法代码示例

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


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

示例1: Create

        public static Entity Create(EntityManager manager)
        {
            var ship = manager.CreateEntity();
            ship.AddComponent(Model);
            ship.AddComponent(new Position() { X = 0, Y = 0, Z = 0 });
            ship.AddComponent(new Weapon() { FireRate = .25 });
            ship.AddComponent(new KeyboardControl());

            return ship;
        }
开发者ID:jjvdangelo,项目名称:EStroids,代码行数:10,代码来源:PlayerTemplate.cs

示例2: Create

        public static Entity Create(EntityManager manager)
        {
            var enemy = manager.CreateEntity();
            var xMult = Rand.Next() % 2 == 0 ? -1 : 1;
            var yMult = Rand.Next() % 2 == 0 ? -1 : 1;
            var velocity = new Vector3(Rand.Next(10, 75) * xMult, Rand.Next(10, 75) * yMult, 0);

            enemy.AddComponent(new Enemy());
            enemy.AddComponent(EnemyModel);
            enemy.AddComponent(new Position() { X = Rand.Next(-300, 300), Y = Rand.Next(-300, 300), ZRot = (float)(Math.PI * Rand.NextDouble() * Rand.Next(0, 4)), Velocity = velocity });

            return enemy;
        }
开发者ID:jjvdangelo,项目名称:EStroids,代码行数:13,代码来源:EnemyTemplate.cs

示例3: CreatingEntities

        public async Task CreatingEntities()
        {
            var manager = new EntityManager(_serviceName);

            // Metadata must be fetched before CreateEntity() can be called
            await manager.FetchMetadata();

            //Snippet1
            var newCustomer = new Customer(); // rarely done in Breeze

            //Snippet2
            // Order uses an auto-generated key value
            var order = manager.CreateEntity<Order>();

            //Snippet3
            // If the key is not auto generated, it must be initialized by CreateEntity()
            var alpha = manager.CreateEntity<Customer>(new { CustomerID = Guid.NewGuid(), CompanyName = "Alpha" });

            //Snippet4
            // Unattached new customer so you can keep configuring it and add/attach it later
            // Key value initializer not required because new entity is not attached to entity manager
            var beta = manager.CreateEntity<Customer>(new { CompanyName = "Beta" }, EntityState.Detached);

            // Attached customer, as if retrieved from the database
            // Note that the key must be initialized when new entity will be in an attached state
            var gamma = manager.CreateEntity<Customer>(new { CustomerID = Guid.NewGuid(), CompanyName = "Gamma" }, EntityState.Unchanged);

            //Snippet5
            // Only need to do this once
            var metadataStore = manager.MetadataStore;                           // The model metadata known to this EntityManager instance
            var customerType = metadataStore.GetEntityType(typeof(Customer));    // Metadata about the Customer type

            // Do this for each customer to be created
            var acme = customerType.CreateEntity() as Customer;     // Returns Customer as IEntity
            acme.CompanyName = "Acme";                              // CompanyName is a required field
            acme.CustomerID = Guid.NewGuid();                       // Must set the key field before attaching to entity manager
            manager.AddEntity(acme);                                // Attach the entity as a new entity; it's EntityState is "Added"
        }
开发者ID:baotnq,项目名称:breeze.sharp.samples,代码行数:38,代码来源:CreateEntityTests.cs

示例4: TestInvalidEntityAdded

        public void TestInvalidEntityAdded()
        {
            Game game = new Game();
            EntityManager entityManager = new EntityManager(game);

            // Create compound entities.
            CompoundEntities<TestCompound> compoundEntities = new CompoundEntities<TestCompound>(entityManager);
            bool entityAdded = false;
            compoundEntities.EntityAdded += (id, entity) => { entityAdded = true; };

            // Just add one of the necessary components.
            var entityId = entityManager.CreateEntity();
            entityManager.AddComponent<TestCompoundComponentA>(entityId);

            Assert.IsFalse(entityAdded);
        }
开发者ID:jixiang111,项目名称:slash-framework,代码行数:16,代码来源:CompoundEntitiesTests.cs

示例5: BuildEntities

        static void BuildEntities(EntityManager manager)
        {
            var random = new Random();
            for (int i = 0; i < 5000; ++i)
            {
                float dxMul = i % random.Next(1, 4) == 0 ? -1 : 1;
                float dyMul = i % random.Next(1, 4) == 0 ? -1 : 1;

                dxMul *= i % random.Next(1, 25) == 0 ? 1.25f : 1.0f;
                dyMul *= i % random.Next(1, 25) == 0 ? -1.15f : 1.05f;

                var x = random.Next(0, 800);
                var y = random.Next(0, 600);

                var square = manager.CreateEntity();
                square.AddComponent(new Positionable(x, y, 0));
                square.AddComponent(new Drawable());
                square.AddComponent(new Moveable(50 * dxMul, 50 * dyMul));
            }
        }
开发者ID:jjvdangelo,项目名称:ESTest,代码行数:20,代码来源:Program.cs

示例6: TestEntityRemovedWhenRemovingWholeEntity

        public void TestEntityRemovedWhenRemovingWholeEntity()
        {
            Game game = new Game();
            EntityManager entityManager = new EntityManager(game);

            // Create compound entities.
            CompoundEntities<TestCompound> compoundEntities = new CompoundEntities<TestCompound>(entityManager);
            int eventCount = 0;
            compoundEntities.EntityRemoved += (id, entity) => { ++eventCount; };

            // Add entity with required components.
            var entityId = entityManager.CreateEntity();
            entityManager.AddComponent<TestCompoundComponentA>(entityId);
            entityManager.AddComponent<TestCompoundComponentB>(entityId);

            // Now remove entity.
            entityManager.RemoveEntity(entityId);
            entityManager.CleanUpEntities();

            Assert.AreEqual(1, eventCount);
        }
开发者ID:jixiang111,项目名称:slash-framework,代码行数:21,代码来源:CompoundEntitiesTests.cs

示例7: QueryWithAFilter

        public async Task QueryWithAFilter()
        {
            var manager = new EntityManager(_serviceName);

            // Metadata must be fetched before CreateEntity() can be called
            await manager.FetchMetadata();

            // Ensure there is at least one active todo item named Wine in the database
            var wines = await new EntityQuery<TodoItem>().Where(td => td.Description == "Wine" && !td.IsArchived && !td.IsDone).Execute(manager);
            if (!wines.Any()) {
                var newWine = manager.CreateEntity<TodoItem>(new {Description = "Wine"});
                await manager.SaveChanges();
            }
            manager.Clear();

            //Snippet1
            var query1 = new EntityQuery<TodoItem>();
            var allTodos = await manager.ExecuteQuery(query1);
            Assert.IsTrue(allTodos.Any(), "No TodoItems in the database");
            
            //Snippet2
            var query2 = query1.Where(td => !td.IsArchived);
            var unarchivedTodos = await manager.ExecuteQuery(query2);
            Assert.IsTrue(unarchivedTodos.Any(), "No unarchived TodoItems in the database");

            //Snippet3
            var query3 = query1.Where(td => !td.IsArchived && !td.IsDone);
            var activeTodos = await manager.ExecuteQuery(query3);
            Assert.IsTrue(activeTodos.Any(), "No active TodoItems in the database");

            //Snippet4
            var query4 = query1.Where(td => td.Description.Contains("Wine"));
            var wineTodos = await manager.ExecuteQuery(query4);
            Assert.IsTrue(allTodos.Any(), "No Wine TodoItems in the database");

            //Snippet5
            // Execute above query locally
            var localWineTodos = manager.ExecuteQueryLocally(query4);
            Assert.AreEqual(wineTodos.Count(), localWineTodos.Count(), "Got " + localWineTodos.Count() + " local wine TodoItems");
        }
开发者ID:baotnq,项目名称:breeze.sharp.samples,代码行数:40,代码来源:QueryWithAFilterTests.cs

示例8: Create

        public static Entity Create(EntityManager manager, Position position)
        {
            var bullet = manager.CreateEntity();
            Vector3 velocity = new Vector3(0, 600, 0);
            Matrix4 rotation;
            Matrix4.Rotation(position.XRot, position.YRot, position.ZRot, out rotation);
            Matrix4.Multiply(ref rotation, ref velocity, out velocity);
            bullet.AddComponent(new Model(new[] {
                new Vector3(-1, 1, 0), new Vector3(1, 1, 0), new Vector3(1, -1, 0), new Vector3(-1, -1, 0)
            }, new[] {
                0, 1, 2, 3
            }, 1.5f));
            bullet.AddComponent(new Expiration() { MaxLifetime = 1 });
            bullet.AddComponent(new Position()
            {
                X = position.X,
                Y = position.Y,
                Z = position.Z,
                Velocity = velocity
            });
            bullet.AddComponent(new Bullet() { Damage = 0.5f });

            return bullet;
        }
开发者ID:jjvdangelo,项目名称:EStroids,代码行数:24,代码来源:BulletSystem.cs

示例9: CreateEntity

 private static int CreateEntity(EntityManager entityManager, EntityConfiguration entityConfiguration)
 {
     int entityId = 0;
     if (entityConfiguration != null)
     {
         if (entityConfiguration.BlueprintId != null)
         {
             entityId = entityManager.CreateEntity(
                 entityConfiguration.BlueprintId,
                 entityConfiguration.Configuration);
         }
     }
     return entityId;
 }
开发者ID:jixiang111,项目名称:slash-framework,代码行数:14,代码来源:InspectorEntityAttribute.cs

示例10: CreateParentAndChildren

 private TwoCusts CreateParentAndChildren(EntityManager em) {
   var cust1 = new Customer();
   cust1.CompanyName = "Test1_" + TestFns.RandomSuffix(8);
   cust1.City = "Oakland";
   cust1.RowVersion = 13;
   cust1.Fax = "510 999-9999";
   em.AddEntity(cust1);
   var cust2 = em.CreateEntity<Customer>();
   cust2.CompanyName = "Test2_" + TestFns.RandomSuffix(8);
   cust2.City = "Emeryville";
   cust2.RowVersion = 1;
   cust2.Fax = "510 888-8888";
   var order1 = new Order();
   order1.OrderDate = DateTime.Today;
   var order2 = em.CreateEntity<Order>();
   order1.OrderDate = DateTime.Today;
   cust1.Orders.Add(order1);
   cust1.Orders.Add(order2);
   Assert.IsTrue(cust1.Orders.Count == 2);
   Assert.IsTrue(cust2.Orders.Count == 0);
   return new TwoCusts() { Cust1 = cust1, Cust2 = cust2 };
 }
开发者ID:Cosmin-Parvulescu,项目名称:Breeze,代码行数:22,代码来源:SaveTests.cs

示例11: ErrorOnNavAttach

 public async Task ErrorOnNavAttach() {
   await _emTask;
 
   var order = _em1.CreateEntity<Order>(EntityState.Unchanged);
 
   var em2 = new EntityManager(_em1);
   var cust = em2.CreateEntity<Customer>(EntityState.Unchanged);
   Assert.IsTrue(order.EntityAspect.EntityManager != cust.EntityAspect.EntityManager, "should not be the same manager");
   try {
     order.Customer = cust;
     Assert.Fail("should not get here");
   } catch (Exception e) {
     Assert.IsTrue(e.Message.Contains("EntityManager"), "message should mention 'EntityManager'");
   }
   cust.EntityAspect.Detach();
   order.Customer = cust;
   Assert.IsTrue(order.EntityAspect.EntityManager == cust.EntityAspect.EntityManager, "should be the same manager");
   Assert.IsTrue(cust.Orders.Contains(order) && order.Customer == cust, "should be properly connected");
 }
开发者ID:udomsak,项目名称:Breeze,代码行数:19,代码来源:AttachTests.cs

示例12: ImportChangedEntityAndRestoreItsOriginalState

        public async Task ImportChangedEntityAndRestoreItsOriginalState()
        {
            var manager = new EntityManager(_serviceName);
            await manager.FetchMetadata(); // Metadata must be fetched before CreateEntity() can be called

            // Suppose we are editing a customer
            const string originalCustomerName = "Foo";
            var customer =
                manager.CreateEntity<Customer>(new {CustomerID = Guid.NewGuid(), CompanyName = originalCustomerName},
                                               EntityState.Unchanged);

            // We change his CompanyName
            customer.CompanyName = "Bar";

            // We export and stash these changes offline
            // because we are not ready to save them
            // (in the test we just export)
            var exportData = manager.ExportEntities();

            // We re-run the app later with a clean manager
            manager.Clear();

            var imported = manager.ImportEntities(exportData);
            customer = imported.ImportedEntities.Cast<Customer>().First();

            // We want to revert our changes and restore the customer to its original state
            customer.EntityAspect.RejectChanges();

            Assert.AreEqual(originalCustomerName, customer.CompanyName);
        }
开发者ID:baotnq,项目名称:breeze.sharp.samples,代码行数:30,代码来源:ExportImportTests.cs

示例13: TestValidEntityAddedWithComponentField

        public void TestValidEntityAddedWithComponentField()
        {
            Game game = new Game();
            EntityManager entityManager = new EntityManager(game);

            // Create compound entities.
            CompoundEntities<TestCompoundWithField> compoundEntities =
                new CompoundEntities<TestCompoundWithField>(entityManager);
            bool entityAdded = false;
            compoundEntities.EntityAdded += (id, entity) => { entityAdded = true; };

            // Add entity with correct components.
            var entityId = entityManager.CreateEntity();
            entityManager.AddComponent<TestCompoundComponentA>(entityId);

            Assert.IsTrue(entityAdded);
        }
开发者ID:jixiang111,项目名称:slash-framework,代码行数:17,代码来源:CompoundEntitiesTests.cs

示例14: TemporaryKeyNotPreservedOnImport

        public async Task TemporaryKeyNotPreservedOnImport()
        {
            // If an earlier test has already created an entity, a new entity will not be assigned a key value of -1
            // Simulate initial launch of the client app
            SimulateResetTempKeyGeneratorSeed();

            var manager1 = new EntityManager(_serviceName);
            await manager1.FetchMetadata(); // Metadata must be fetched before CreateEntity() can be called

            // Create a new Order. The Order key is store-generated.
            // Until saved, the new Order has a temporary key such as '-1'.
            var acme1 = manager1.CreateEntity<Order>(new {ShipName = "Acme"});
            Assert.AreEqual(-1, acme1.OrderID, "Initial entity not assigned temp key -1");
 
            // export without metadata
            var exported = manager1.ExportEntities(new IEntity[] {acme1}, false);
 
            // ... much time passes 
            // ... the client app is re-launched
            // ... the seed for the temporary id generator was reset
            SimulateResetTempKeyGeneratorSeed();

            // Create a new manager2 with metadata
            var manager2 = new EntityManager(manager1);

            // Add a new order to manager2
            // This new order has a temporary key.
            // That key could be '-1' ... the same key as acme1!!!
            var beta = (Order) manager2.CreateEntity(typeof (Order), new {ShipName = "Beta"});

            // Its key will be '-1' ... the same key as acme1!!!
            Assert.AreEqual(-1, beta.OrderID);
 
            // Import the the exported acme1 from manager1
            // and get the newly merged instance from manager2
            var imported = manager2.ImportEntities(exported);
            var acme2 = imported.ImportedEntities.Cast<Order>().First();
 
            // compare the "same" order as it is in managers #1 and #2  
            var isSameName = acme1.ShipName == acme2.ShipName; // true
            Assert.IsTrue(isSameName, "ShipNames should be the same");

            // breeze had to update the acme key in manager2 because 'beta' already has ID==-1   
            var isSameId = acme1.OrderID == acme2.OrderID; // false; temporary keys are different
            Assert.IsFalse(isSameId, "OrderIDs (temporary keys) should be different");

        }
开发者ID:baotnq,项目名称:breeze.sharp.samples,代码行数:47,代码来源:ExportImportTests.cs

示例15: TestValidEntityWithOptionalCompAddedTriggerEventOnlyOnce

        public void TestValidEntityWithOptionalCompAddedTriggerEventOnlyOnce()
        {
            Game game = new Game();
            EntityManager entityManager = new EntityManager(game);

            // Create compound entities.
            CompoundEntities<TestCompoundWithOneOptionalComp> compoundEntities =
                new CompoundEntities<TestCompoundWithOneOptionalComp>(entityManager);
            int entityAddedEvent = 0;
            compoundEntities.EntityAdded += (id, entity) => { ++entityAddedEvent; };

            // Just add one of the components which is the necessary one.
            var entityId = entityManager.CreateEntity();
            entityManager.AddComponent<TestCompoundComponentA>(entityId);
            entityManager.AddComponent<TestCompoundComponentB>(entityId);

            Assert.AreEqual(1, entityAddedEvent);
        }
开发者ID:jixiang111,项目名称:slash-framework,代码行数:18,代码来源:CompoundEntitiesTests.cs


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