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


C# Entity.AddChild方法代码示例

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


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

示例1: HudDecorator

        /// <summary>
        /// Instantiates the HUD
        /// </summary>
        /// <param name="name">The entity name</param>
        public HudDecorator(string name)
        {
            this.entity = new Entity(name)
            .AddComponent(new Transform3D() { LocalScale = Vector3.One * 3 })
            .AddComponent(new Model("Content/Models/Hud/HudStatic.FBX"))
            .AddComponent(new ModelRenderer())
            .AddComponent(new MaterialsMap(new BasicMaterial("Content/Textures/Hud/Hud_1.png", typeof(AdditiveLayer))))
            ;

            Entity rotationEntity = new Entity("rotation")
            .AddComponent(new Transform3D())
            .AddComponent(new Model("Content/Models/Hud/HudRotation.FBX"))
            .AddComponent(new ModelRenderer())
            .AddComponent(new MaterialsMap(new BasicMaterial("Content/Textures/Hud/Hud_1.png", typeof(AdditiveLayer))))
            .AddComponent(new HudRotationBehavior(new Vector3(1, 1, 0)))
            ;

            this.entity.AddChild(rotationEntity);

            Entity radarEntity = new Entity("radar")
            .AddComponent(new Transform3D() { LocalPosition = new Vector3(0, -0.32f, 0.5f), LocalRotation = Vector3.UnitY * MathHelper.Pi })
            .AddComponent(new Model("Content/Models/Hud/HudRadarStatic.FBX"))
            .AddComponent(new ModelRenderer())
            .AddComponent(new MaterialsMap(new BasicMaterial("Content/Textures/Hud/HudRadar.png", typeof(AdditiveLayer))))
            ;

            Entity rotationRadar1 = new Entity("rotationRadar1")
            .AddComponent(new Transform3D())
            .AddComponent(new Model("Content/Models/Hud/HudRadarRotation1.FBX"))
            .AddComponent(new ModelRenderer())
            .AddComponent(new MaterialsMap(new BasicMaterial("Content/Textures/Hud/HudRadar.png", typeof(AdditiveLayer))))
            .AddComponent(new HudRotationBehavior(new Vector3(1, 1, 0)))
            .AddComponent(new RadarBehavior())
            ;

            radarEntity.AddChild(rotationRadar1);

            Entity rotationRadar3 = new Entity("rotationRadar3")
             .AddComponent(new Transform3D())
             .AddComponent(new Model("Content/Models/Hud/HudRadarRotation3.FBX"))
             .AddComponent(new ModelRenderer())
             .AddComponent(new MaterialsMap(new BasicMaterial("Content/Textures/Hud/HudRadar.png", typeof(AdditiveLayer))))
             .AddComponent(new Spinner() { IncreaseY = -10 })
             ;

            rotationRadar1.AddChild(rotationRadar3);

            Entity rotationRadar2 = new Entity("rotationRadar2")
            .AddComponent(new Transform3D())
            .AddComponent(new Model("Content/Models/Hud/HudRadarRotation2.FBX"))
            .AddComponent(new ModelRenderer())
            .AddComponent(new MaterialsMap(new BasicMaterial("Content/Textures/Hud/HudRadar.png", typeof(AdditiveLayer))))
            .AddComponent(new HudRotationBehavior(new Vector3(1, 1, 0)))
            ;

            radarEntity.AddChild(rotationRadar2);

            this.entity.AddChild(radarEntity);
        }
开发者ID:seraph526,项目名称:Samples,代码行数:63,代码来源:HudDecorator.cs

示例2: SpawnPrefabModel

        public static void SpawnPrefabModel(this ScriptComponent script, Prefab source, Entity attachEntity, Matrix localMatrix, Vector3 forceImpulse)
        {
            if (source == null)
                return;

            // Clone
            var spawnedEntities = source.Instantiate();

            // Add
            foreach (var prefabEntity in spawnedEntities)
            {
                prefabEntity.Transform.UpdateLocalMatrix();
                var entityMatrix = prefabEntity.Transform.LocalMatrix * localMatrix;
                entityMatrix.Decompose(out prefabEntity.Transform.Scale, out prefabEntity.Transform.Rotation, out prefabEntity.Transform.Position);

                if (attachEntity != null)
                {
                    attachEntity.AddChild(prefabEntity);
                }
                else
                {
                    script.SceneSystem.SceneInstance.Scene.Entities.Add(prefabEntity);
                }

                var physComp = prefabEntity.Get<RigidbodyComponent>();
                if (physComp != null)
                {
                    physComp.ApplyImpulse(forceImpulse);
                }
            }
        }
开发者ID:Kryptos-FR,项目名称:xenko-reloaded,代码行数:31,代码来源:Utils.cs

示例3: CreateDebugEntity

        public Entity CreateDebugEntity(PhysicsComponent component, bool alwaysAddOffset = false)
        {
            if (component?.ColliderShape == null) return null;

            if (component.DebugEntity != null) return null;

            var debugEntity = new Entity();

            var skinnedElement = component as PhysicsSkinnedComponentBase;
            if (skinnedElement != null && skinnedElement.BoneIndex != -1)
            {
                Vector3 scale, pos;
                Quaternion rot;
                skinnedElement.BoneWorldMatrixOut.Decompose(out scale, out rot, out pos);
                debugEntity.Transform.Position = pos;
                debugEntity.Transform.Rotation = rot;
            }
            else
            {
                Vector3 scale, pos;
                Quaternion rot;
                component.Entity.Transform.WorldMatrix.Decompose(out scale, out rot, out pos);
                debugEntity.Transform.Position = pos;
                debugEntity.Transform.Rotation = rot;
            }

            var rigidBody = component as RigidbodyComponent;

            //don't add offset for non bone dynamic and kinematic as it is added already in the updates
            var colliderEntity = CreateChildEntity(component, component.ColliderShape, alwaysAddOffset || rigidBody == null);
            if (colliderEntity != null) debugEntity.AddChild(colliderEntity);

            return debugEntity;
        }
开发者ID:Kryptos-FR,项目名称:xenko-reloaded,代码行数:34,代码来源:PhysicsShapesRenderingService.cs

示例4: TestComponentAccess

        public unsafe void TestComponentAccess()
        {
            var entity = new Entity();

            entity.AddChild(new Entity("child1")
            {
                new LightComponent()
            });

            var modelComponent = new ModelComponent();

            var compiledUpdate = UpdateEngine.Compile(typeof(Entity), new List<UpdateMemberInfo>
            {
                new UpdateMemberInfo("[ModelComponent.Key]", 0),
                new UpdateMemberInfo("child1[LightComponent.Key].Intensity", 0),
            });

            var testData = new TestData[] { 32.0f };

            fixed (TestData* dataPtr = testData)
            {
                UpdateEngine.Run(entity, compiledUpdate, (IntPtr)dataPtr, new[] { new UpdateObjectData(modelComponent) });
            }

            Assert.That(entity.Get(ModelComponent.Key), Is.EqualTo(modelComponent));
            Assert.That(entity.GetChild(0).Get(LightComponent.Key).Intensity, Is.EqualTo(32.0f));
        }
开发者ID:h78hy78yhoi8j,项目名称:xenko,代码行数:27,代码来源:EntityUpdateEngineTest.cs

示例5: SpawnInstance

        protected void SpawnInstance(Prefab source, Entity attachEntity, float timeout, Matrix localMatrix)
        {
            if (source == null)
                return;

            Func<Task> spawnTask = async () =>
            {
                // Clone
                var spawnedEntities = source.Instantiate();

                // Add
                foreach (var prefabEntity in spawnedEntities)
                {
                    prefabEntity.Transform.UpdateLocalMatrix();
                    var entityMatrix = prefabEntity.Transform.LocalMatrix * localMatrix;
                    entityMatrix.Decompose(out prefabEntity.Transform.Scale, out prefabEntity.Transform.Rotation, out prefabEntity.Transform.Position);

                    if (attachEntity != null)
                    {
                        attachEntity.AddChild(prefabEntity);
                    }
                    else
                    {
                        SceneSystem.SceneInstance.Scene.Entities.Add(prefabEntity);
                    }
                }

                // Countdown
                var secondsCountdown = timeout;
                while (secondsCountdown > 0f)
                {
                    await Script.NextFrame();
                    secondsCountdown -= (float)Game.UpdateTime.Elapsed.TotalSeconds;
                }

                // Remove
                foreach (var clonedEntity in spawnedEntities)
                {
                    if (attachEntity != null)
                    {
                        attachEntity.RemoveChild(clonedEntity);
                    }
                    else
                    {
                        SceneSystem.SceneInstance.Scene.Entities.Remove(clonedEntity);
                    }
                }

                // Cleanup
                spawnedEntities.Clear();
            };

            Script.AddTask(spawnTask);
        }
开发者ID:Kryptos-FR,项目名称:xenko-reloaded,代码行数:54,代码来源:TriggerScript.cs

示例6: CreateDebugEntity

        public Entity CreateDebugEntity(PhysicsComponent component)
        {
            if (component?.ColliderShape == null) return null;

            if (component.DebugEntity != null) return null;

            var debugEntity = new Entity();

            var colliderEntity = CreateChildEntity(component, component.ColliderShape, true);
            if (colliderEntity == null) return null;

            debugEntity.AddChild(colliderEntity);

            if (component.CanScaleShape)
            {
                debugEntity.Transform.Scale = component.ColliderShape.Scaling;
            }

            var skinnedElement = component as PhysicsSkinnedComponentBase;
            if (skinnedElement != null && skinnedElement.BoneIndex != -1)
            {
                Vector3 scale, pos;
                Quaternion rot;
                skinnedElement.BoneWorldMatrixOut.Decompose(out scale, out rot, out pos);
                debugEntity.Transform.Position = pos;
                debugEntity.Transform.Rotation = rot;
            }
            else
            {
                Vector3 scale, pos;
                Quaternion rot;
                component.Entity.Transform.WorldMatrix.Decompose(out scale, out rot, out pos);
                debugEntity.Transform.Position = pos;
                debugEntity.Transform.Rotation = rot;
            }

            return debugEntity;
        }
开发者ID:psowinski,项目名称:xenko,代码行数:38,代码来源:PhysicsDebugShapeRendering.cs

示例7: ProcessUnionSubclasses

        private void ProcessUnionSubclasses(object parent, MappingSet mappingSet, IDatabase database, EntitySet entities, Entity newEntity, IEnumerable<unionsubclass> unionsubclasses, ParseResults results, string unqualifiedNamespace)
        {
            if (unionsubclasses == null) return;

            @class hClass = null;
            unionsubclass parentSubClass = null;

            if (parent is @class)
                hClass = (@class)parent;
            else
                parentSubClass = (unionsubclass)parent;

            foreach (unionsubclass hSubclass in unionsubclasses)
            {
                Entity childEntity;

                string @namespace;
                string name;

                if (IsNameFullyQualified(hSubclass.name, out @namespace, out name))
                {
                    childEntity = new EntityImpl(name);

                    string currentNamespace = ArchAngel.Interfaces.SharedData.CurrentProject.GetUserOption("ProjectNamespace") == null ? "" : ArchAngel.Interfaces.SharedData.CurrentProject.GetUserOption("ProjectNamespace").ToString();

                    if (string.IsNullOrWhiteSpace(currentNamespace))
                        ArchAngel.Interfaces.SharedData.CurrentProject.SetUserOption("ProjectNamespace", @namespace);
                }
                else
                    childEntity = new EntityImpl(hSubclass.name);

                childEntity.SetEntityLazy(hSubclass.lazy);
                newEntity.AddChild(childEntity);

                var childTableMapping = new MappingImpl();
                childTableMapping.FromTable = database.GetTable(hSubclass.table.UnBackTick(), hSubclass.schema.UnBackTick());
                childTableMapping.ToEntity = childEntity;

                foreach (var ip in childEntity.InheritedProperties)
                {
                    PropertyImpl np = new PropertyImpl(ip);
                    np.IsHiddenByAbstractParent = true;
                    childEntity.AddProperty(np);
                    string columnName = "";
                    var props = hClass.Properties().ToList();

                    if (hClass != null)
                    {
                        property matchingProp = hClass.Properties().SingleOrDefault(p => p.name == ip.Name);

                        if (matchingProp != null)
                        {
                            if (matchingProp.column != null)
                                columnName = matchingProp.column;
                            else if (matchingProp.Columns().Count > 0)
                                columnName = matchingProp.Columns()[0].name;
                        }
                        else
                        {
                            if (hClass.Id().column1 != null)
                                columnName = hClass.Id().column1;
                            else if (hClass.Id().column != null && hClass.Id().column.Count() > 0)
                                columnName = hClass.Id().column[0].name;
                        }
                    }
                    else
                        columnName = parentSubClass.Properties().Single(p => p.name == ip.Name).column;

                    IColumn column = childTableMapping.FromTable.GetColumn(columnName.UnBackTick());

                    if (column != null)
                        childTableMapping.AddPropertyAndColumn(np, column);
                }

                foreach (var hProperty in hSubclass.Properties())
                {
                    var property = CreateProperty(childEntity, childTableMapping, hProperty);
                    SetPropertyInfoFromParsedCode(property, results, unqualifiedNamespace, childTableMapping.FromTable.Schema, hSubclass.name);
                }
                // Add the parent's key properties as hidden properties
                foreach (var keyProp in newEntity.Key.Properties)
                {
                    Property childP = childEntity.PropertiesHiddenByAbstractParent.SingleOrDefault(p => p.Name == keyProp.Name);

                    if (childP != null)
                    {
                        //childP.IsHiddenByAbstractParent = true;
                        childP.IsKeyProperty = true;
                    }
                }

                entities.AddEntity(childEntity);
                mappingSet.AddMapping(childTableMapping);

                ProcessUnionSubclasses(hSubclass, mappingSet, database, entities, childEntity, hSubclass.unionsubclass1, results, unqualifiedNamespace);
            }
        }
开发者ID:uQr,项目名称:Visual-NHibernate,代码行数:97,代码来源:EntityLoader.cs

示例8: ProcessSubclasses

        private void ProcessSubclasses(MappingSet mappingSet, IDatabase database, EntitySet entities, Entity parentEntity, IEnumerable<subclass> subclasses, string schemaName, string tableName, ParseResults parseResults, string unqualifiedNamespace)
        {
            if (subclasses == null) return;

            foreach (subclass hSubclass in subclasses)
            {
                Entity childEntity;

                string @namespace;
                string name;

                if (IsNameFullyQualified(hSubclass.name, out @namespace, out name))
                {
                    childEntity = new EntityImpl(name);

                    string currentNamespace = ArchAngel.Interfaces.SharedData.CurrentProject.GetUserOption("ProjectNamespace") == null ? "" : ArchAngel.Interfaces.SharedData.CurrentProject.GetUserOption("ProjectNamespace").ToString();

                    if (string.IsNullOrWhiteSpace(currentNamespace))
                        ArchAngel.Interfaces.SharedData.CurrentProject.SetUserOption("ProjectNamespace", @namespace);
                }
                else
                    childEntity = new EntityImpl(hSubclass.name);

                childEntity.SetEntityLazy(hSubclass.lazy);

                #region Discriminator
                if (!string.IsNullOrWhiteSpace(hSubclass.discriminatorvalue))
                {
                    childEntity.DiscriminatorValue = hSubclass.discriminatorvalue;

                    //ArchAngel.Providers.EntityModel.Model.EntityLayer.Discriminator d = new Discriminator()
                    //{
                    //    AllowNull = xx,
                    //    ColumnName = hSubclass.d,
                    //    DiscriminatorType = xx,
                    //    Force = xx,
                    //    Formula = xx,
                    //    Insert = xx
                    //};
                    //throw new NotImplementedException("TODO: fixup discriminator stuff");
                    //Grouping g = new AndGrouping();
                    //IColumn column = parentEntity.Discriminator.RootGrouping.Conditions[0].Column;
                    //ArchAngel.Providers.EntityModel.Model.DatabaseLayer.Discrimination.Operator op = ArchAngel.Providers.EntityModel.Model.DatabaseLayer.Discrimination.Operator.Equal;
                    //ExpressionValue value = new ExpressionValueImpl(hSubclass.discriminatorvalue);

                    //if (column != null && op != null && value != null)
                    //    g.AddCondition(new ConditionImpl(column, op, value));

                    //if (childEntity.Discriminator == null)
                    //    childEntity.Discriminator = new DiscriminatorImpl();

                    //childEntity.Discriminator.RootGrouping = g;
                }
                #endregion

                parentEntity.AddChild(childEntity);

                var childTableMapping = new MappingImpl();

                childTableMapping.FromTable = database.GetTable(tableName, schemaName);
                childTableMapping.ToEntity = childEntity;

                foreach (var hProperty in hSubclass.Properties())
                {
                    var property = CreateProperty(childEntity, childTableMapping, hProperty);
                    SetPropertyInfoFromParsedCode(property, parseResults, unqualifiedNamespace, childTableMapping.FromTable.Schema, hSubclass.name);
                }

                entities.AddEntity(childEntity);
                mappingSet.AddMapping(childTableMapping);

                ProcessSubclasses(mappingSet, database, entities, childEntity, hSubclass.subclass1, schemaName, tableName, parseResults, unqualifiedNamespace);
            }
        }
开发者ID:uQr,项目名称:Visual-NHibernate,代码行数:74,代码来源:EntityLoader.cs

示例9: ProcessJoinedSubclasses

        private void ProcessJoinedSubclasses(MappingSet mappingSet, IDatabase database, EntitySet entities, Entity newEntity, IEnumerable<joinedsubclass> joinedsubclasses, ParseResults results, string unqualifiedNamespace)
        {
            if (joinedsubclasses == null) return;

            ITable parentTable = null;

            if (newEntity.MappedTables().Count() > 0)
                parentTable = newEntity.MappedTables().ElementAt(0);

            foreach (joinedsubclass hSubclass in joinedsubclasses)
            {
                Entity childEntity;
                string @namespace;
                string name;

                if (IsNameFullyQualified(hSubclass.name, out @namespace, out name))
                {
                    childEntity = new EntityImpl(name);

                    string currentNamespace = ArchAngel.Interfaces.SharedData.CurrentProject.GetUserOption("ProjectNamespace") == null ? "" : ArchAngel.Interfaces.SharedData.CurrentProject.GetUserOption("ProjectNamespace").ToString();

                    if (string.IsNullOrWhiteSpace(currentNamespace))
                        ArchAngel.Interfaces.SharedData.CurrentProject.SetUserOption("ProjectNamespace", @namespace);

                    unqualifiedNamespace = @namespace;
                }
                else
                    childEntity = new EntityImpl(hSubclass.name);

                childEntity.SetEntityLazy(hSubclass.lazy);
                newEntity.AddChild(childEntity);

                var childTableMapping = new MappingImpl();
                ITable subClassTable;

                if (!string.IsNullOrEmpty(hSubclass.table))
                {
                    string schema = "";

                    if (!string.IsNullOrEmpty(hSubclass.schema))
                        schema = hSubclass.schema;
                    else if (parentTable != null)
                        schema = parentTable.Schema;

                    subClassTable = database.GetTable(hSubclass.table.UnBackTick(), schema.UnBackTick());
                    subClassTable.Database = database;
                }
                else
                    subClassTable = parentTable;

                childTableMapping.FromTable = subClassTable;
                childTableMapping.ToEntity = childEntity;

                foreach (var hProperty in hSubclass.Properties())
                {
                    var property = CreateProperty(childEntity, childTableMapping, hProperty);
                    SetPropertyInfoFromParsedCode(property, results, unqualifiedNamespace, childTableMapping.FromTable.Schema, hSubclass.name);
                }
                if (hSubclass.key != null)
                {
                    string keyColumnName;

                    if (!string.IsNullOrEmpty(hSubclass.key.column1))
                        keyColumnName = hSubclass.key.column1;
                    else //if (hSubclass.key.column != null && hSubclass.key.column.Count() > 0)
                        keyColumnName = hSubclass.key.column[0].name;

                    Property keyProp = childEntity.Properties.FirstOrDefault(p => p.MappedColumn() != null && p.MappedColumn().Name == keyColumnName);

                    if (keyProp == null)
                    {
                        keyProp = CreateProperty(childEntity, childTableMapping, hSubclass.key, subClassTable);
                        SetPropertyInfoFromParsedCode(keyProp, results, unqualifiedNamespace, childTableMapping.FromTable.Schema, childEntity.Name);
                        keyProp.IsHiddenByAbstractParent = true;
                    }
                    keyProp.IsKeyProperty = true;
                }
                entities.AddEntity(childEntity);
                mappingSet.AddMapping(childTableMapping);

                ProcessJoinedSubclasses(mappingSet, database, entities, childEntity, hSubclass.joinedsubclass1, results, unqualifiedNamespace);
            }
        }
开发者ID:uQr,项目名称:Visual-NHibernate,代码行数:83,代码来源:EntityLoader.cs

示例10: AddTreeLimits

 private void AddTreeLimits(string name, Vector3 position, Entity parent)
 {
     Entity limitEntity = this.RetrieveTerrainLimitEntity();
     if (limitEntity != null)
     {
         limitEntity.Name = name;
         limitEntity.FindComponent<Transform3D>().LocalPosition = position;
         parent.AddChild(limitEntity);
     }
 }
开发者ID:WaveEngine,项目名称:QuickStarters,代码行数:10,代码来源:EntityPoolComponent.cs

示例11: AddRandomTrees

        private void AddRandomTrees(int count, Entity nextTerrain)
        {
            for (int i = 0; i < count; i++)
            {
                Entity tree = this.RetrieveTreeEntity();
                if (tree != null)
                {
                    tree.Name += i.ToString();

                    Vector3 pos = Vector3.Zero;
                    pos.X = WaveServices.Random.Next(-this.HalfExtendLimits, this.HalfExtendLimits + 1);
                    pos.Z = WaveServices.Random.Next(4);

                    tree.FindComponent<Transform3D>().LocalPosition = pos;

                    nextTerrain.AddChild(tree);
                }
            }
        }
开发者ID:WaveEngine,项目名称:QuickStarters,代码行数:19,代码来源:EntityPoolComponent.cs

示例12: TestMultiplePrefabsInheritanceAndChildren

        public void TestMultiplePrefabsInheritanceAndChildren()
        {
            // The purpose of this test is to check that modifying a prefab base is correctly propagated through all 
            // derived prefabs. We use the following scenario:
            //
            // a1: base asset
            // a2: inherit from a1 by composition with 2 instances (baseParts: a1 => 2 instances)
            // a3: inherit from a1 by composition with 1 instances (baseParts: a1 => 1 instances)
            // a4: inherit from a2 and a3 by composition with 1 instances for each (baseParts: a1 => 1 instance, a2 => 1 instance)
            //
            // Unlike TestMultiplePrefabsMixedInheritance, we use only inheritance by composition for this scenario to match current use cases

            var package = new Package();

            var assetItems = package.Assets;


            // First we create assets with the following configuration:
            // a1:                  a2: (baseParts: a1, 2 instances)     a3: (baseParts: a1)               a4: (baseParts: a2 x 1, a3 x 1)
            //  | er                 | er1 (base: er)                     | er1' (base: er)                 | eRoot
            //    | ea                 | ea1 (base: ea)                     | ea1' (base: ea)                 | er1* (base: er)  
            //    | eb                 | eb1 (base: eb)                     | eb1' (base: eb)                   | ea1* (base: ea)
            //    | ec                 | ec1 (base: ec)                     | ec1' (base: ec)                   | eb1* (base: eb)
            //                       | er2 (base: er)                                                           | ec1* (base: ec)
            //                         | ea2 (base: ea)                                                       | er2* (base: er)  
            //                         | eb2 (base: eb)                                                         | ea2* (base: ea)
            //                         | ec2 (base: ec)                                                         | eb2* (base: eb)
            //                                                                                                  | ec2* (base: ec)  
            //                                                                                              | er1'* (base: er)     
            //                                                                                                | ea1'* (base: ea)    
            //                                                                                                | eb1'* (base: eb)  
            //                                                                                                | ec1'* (base: ec)
            var a1 = new PrefabAsset();
            var er = new Entity("er");
            var ea = new Entity("ea");
            var eb = new Entity("eb");
            var ec = new Entity("ec");
            a1.Hierarchy.Parts.Add(new EntityDesign(er));
            a1.Hierarchy.Parts.Add(new EntityDesign(ea));
            a1.Hierarchy.Parts.Add(new EntityDesign(eb));
            a1.Hierarchy.Parts.Add(new EntityDesign(ec));
            a1.Hierarchy.RootPartIds.Add(er.Id);
            er.AddChild(ea);
            er.AddChild(eb);
            er.AddChild(ec);

            assetItems.Add(new AssetItem("a1", a1));

            var member = (IMemberDescriptor)TypeDescriptorFactory.Default.Find(typeof(Entity))[nameof(Entity.Name)];
            
            var a2 = new PrefabAsset();
            var a2PartInstance1 = a1.CreatePrefabInstance(a2, "a1");
            foreach (var entity in a2PartInstance1.Parts)
            {
                entity.Entity.Name += "1";
            }

            var a2PartInstance2 = a1.CreatePrefabInstance(a2, "a1");
            foreach (var entity in a2PartInstance2.Parts)
            {
                entity.Entity.Name += "2";
            }

            a2.Hierarchy.Parts.AddRange(a2PartInstance1.Parts);
            a2.Hierarchy.Parts.AddRange(a2PartInstance2.Parts);
            a2.Hierarchy.RootPartIds.AddRange(a2PartInstance1.RootPartIds);
            a2.Hierarchy.RootPartIds.AddRange(a2PartInstance2.RootPartIds);
            Assert.AreEqual(8, a2.Hierarchy.Parts.Count);
            Assert.AreEqual(2, a2.Hierarchy.RootPartIds.Count);
            assetItems.Add(new AssetItem("a2", a2));

            var a3 = new PrefabAsset();
            var a3PartInstance1 = a1.CreatePrefabInstance(a3, "a1");
            foreach (var entity in a3PartInstance1.Parts)
            {
                entity.Entity.Name += "1'";
            }
            a3.Hierarchy.Parts.AddRange(a3PartInstance1.Parts);
            a3.Hierarchy.RootPartIds.AddRange(a3PartInstance1.RootPartIds);
            Assert.AreEqual(4, a3.Hierarchy.Parts.Count);
            Assert.AreEqual(1, a3.Hierarchy.RootPartIds.Count);
            assetItems.Add(new AssetItem("a3", a3));

            var a4 = new PrefabAsset();
            var eRoot = new Entity("eRoot");
            var a2PartInstance3 = a2.CreatePrefabInstance(a4, "a2");

            foreach (var entity in a2PartInstance3.Parts)
            {
                entity.Entity.Name += "*";
            }
            foreach (var entity in a2PartInstance3.Parts.Where(t => a2PartInstance3.RootPartIds.Contains(t.Entity.Id)))
            {
                eRoot.AddChild(entity.Entity);
            }
            var a3PartInstance2 = a3.CreatePrefabInstance(a4, "a3");
            foreach (var entity in a3PartInstance2.Parts)
            {
                entity.Entity.Name += "*";
            }
//.........这里部分代码省略.........
开发者ID:Kryptos-FR,项目名称:xenko-reloaded,代码行数:101,代码来源:TestPrefabAssetMerge.cs

示例13: CreateChildEntity

        private Entity CreateChildEntity(ColliderShape shape, PhysicsElementBase.Types type, bool addOffset = false)
        {
            if (shape == null)
                return null;

            switch (shape.Type)
            {
                case ColliderShapeTypes.StaticPlane:
                    {
                        //Hmm TODO maybe can draw an infinite plane??
                        return null;
                    }
                case ColliderShapeTypes.Compound:
                    {
                        var entity = new Entity();

                        //We got to recurse
                        var compound = (CompoundColliderShape)shape;
                        for (var i = 0; i < compound.Count; i++)
                        {
                            var subShape = compound[i];
                            var subEntity = CreateChildEntity(subShape, type, true);

                            subEntity.Transform.UseTRS = false;
                            entity.AddChild(subEntity);
                        }

                        entity.Transform.LocalMatrix = Matrix.Identity;
                        entity.Transform.UseTRS = false;

                        return entity;
                    }
                default:
                    {
                        Material mat;
                        switch (type)
                        {
                            case PhysicsElementBase.Types.PhantomCollider:
                                mat = triggerMaterial;
                                break;

                            case PhysicsElementBase.Types.StaticCollider:
                            case PhysicsElementBase.Types.StaticRigidBody:
                                mat = staticMaterial;
                                break;

                            case PhysicsElementBase.Types.DynamicRigidBody:
                                mat = dynamicMaterial;
                                break;

                            case PhysicsElementBase.Types.KinematicRigidBody:
                                mat = kinematicMaterial;
                                break;

                            case PhysicsElementBase.Types.CharacterController:
                                mat = characterMaterial;
                                break;

                            default:
                                throw new ArgumentOutOfRangeException("type", type, null);
                        }

                        var entity = new Entity
                        {
                            new ModelComponent
                            {
                                Model = new Model
                                {
                                    mat,
                                    new Mesh
                                    {
                                        Draw = shape.CreateDebugPrimitive(graphicsDevice)
                                    }
                                }
                            }
                        };

                        var offset = addOffset ? Matrix.RotationQuaternion(shape.LocalRotation)*Matrix.Translation(shape.LocalOffset) : Matrix.Identity;

                        if (shape.Type == ColliderShapeTypes.ConvexHull)
                        {
                            var hullDesc = (ConvexHullColliderShape)shape;

                            entity.Transform.LocalMatrix = shape.DebugPrimitiveMatrix * Matrix.Scaling(hullDesc.Scaling) * offset;
                        }
                        else
                        {
                            entity.Transform.LocalMatrix = shape.DebugPrimitiveMatrix * offset;
                        }
                        entity.Transform.UseTRS = false;

                        return entity;
                    }
            }
        }
开发者ID:h78hy78yhoi8j,项目名称:xenko,代码行数:95,代码来源:PhysicsDebugShapeRendering.cs

示例14: Create_Towers_Bar

        private void Create_Towers_Bar()
        {
            var touchGestures = new TouchGestures();
               var x = WaveServices.Platform.ScreenWidth / 2;
               var y = WaveServices.Platform.ScreenHeight - 150;
               var sprite = "Content/Other/TowerBar/Bar_Background.wpk";
               TowersBar = Static.Functions.Create_entity("Tower_Bar", x, y, sprite);

               x = 0;
               y = 0;
               sprite = "Content/Other/TowerBar/Tower1_Sprite.wpk";

               Tower1Button = Static.Functions.Create_entity("Tower1",x,y,sprite);
               Tower1Button.AddComponent(new RectangleCollider())
            .AddComponent(touchGestures);
               Tower1Button.FindComponent<Transform2D>().ParentDependencyObject = null;
               Tower1Button.FindComponent<Transform2D>().DrawOrder = 0;

            sprite = "Content/Other/TowerBar/Chandler_Icon.wpk";
            var Chandler_tower = Static.Functions.Create_entity("Chandler_tower", Static.Const.Tower_Position["Chandler_tower"].Item1
                ,Static.Const.Tower_Position["Chandler_tower"].Item2,sprite);
            Chandler_tower.FindComponent<Transform2D>().ParentDependencyObject = null;
            Chandler_tower.FindComponent<Transform2D>().DrawOrder = 0;
            Chandler_tower.AddComponent(new RectangleCollider());
            Chandler_tower.AddComponent(new TouchGestures());

            touchGestures.TouchMoved += touchGestures_TouchMoved;
            touchGestures.TouchReleased += touchGestures_TouchReleased;

            Chandler_tower.FindComponent<TouchGestures>().TouchMoved += touchGestures_TouchMoved;
            Chandler_tower.FindComponent<TouchGestures>().TouchReleased += touchGestures_TouchReleased;

            TowersBar.AddChild(Chandler_tower);
            TowersBar.AddChild(Tower1Button);
        }
开发者ID:edzio94,项目名称:Tower-Defense,代码行数:35,代码来源:Level_Classes.cs

示例15: CreateScene

        protected override void CreateScene()
        {
            FixedCamera2D camera2d = new FixedCamera2D("camera");
            camera2d.BackgroundColor = Color.White;
            EntityManager.Add(camera2d);

            // FrontController
            Entity frontController = new Entity()
                                            .AddComponent(new Transform2D()
                                            {
                                                X = 67,
                                                Y = 203,
                                                DrawOrder = 0.9f,
                                            })
                                            .AddComponent(new Sprite("Content/FrontController.wpk"))
                                            .AddComponent(new SpriteRenderer(DefaultLayers.Alpha));
            EntityManager.Add(frontController);

            // Top Controller
            Entity topController = new Entity()
                                            .AddComponent(new Transform2D()
                                            {
                                                X = 656,
                                                Y = 249,
                                                DrawOrder = 0.9f,
                                            })
                                            .AddComponent(new Sprite("Content/TopController.wpk"))
                                            .AddComponent(new SpriteRenderer(DefaultLayers.Alpha));
            EntityManager.Add(topController);

            // Sticks
            Entity leftParent = new Entity()
                       .AddComponent(new Transform2D()
                       {
                           Origin = Vector2.One / 2,
                           Position = new Vector2(183, 311),
                           DrawOrder = 0.5f,
                       });
            this.EntityManager.Add(leftParent);

            this.leftJoystick = new Entity()
                                        .AddComponent(new Transform2D()
                                        {
                                            Origin = Vector2.One / 2,
                                        })
                                        .AddComponent(new SpriteAtlas("Content/Buttons.wpk", "JoyStick"))
                                        .AddComponent(new SpriteAtlasRenderer(DefaultLayers.Alpha));
            leftParent.AddChild(leftJoystick);

            Entity rightParent = new Entity()
                       .AddComponent(new Transform2D()
                       {
                           Origin = Vector2.One / 2,
                           Position = new Vector2(427, 407),
                           DrawOrder = 0.5f,
                       });
            this.EntityManager.Add(rightParent);

            this.rightJoystick = new Entity()
                                        .AddComponent(new Transform2D()
                                        {
                                            Origin = Vector2.One / 2,                                            
                                        })
                                        .AddComponent(new SpriteAtlas("Content/Buttons.wpk", "JoyStick"))
                                        .AddComponent(new SpriteAtlasRenderer(DefaultLayers.Alpha));
            rightParent.AddChild(rightJoystick);

            // Button A
            this.buttonA = new Entity()
                                        .AddComponent(new Transform2D()
                                        {
                                            Origin = Vector2.One / 2,
                                            X = 509,
                                            Y = 349,
                                            DrawOrder = 0.5f,
                                        })
                                        .AddComponent(new SpriteAtlas("Content/Buttons.wpk", "circlePressed"))
                                        .AddComponent(new SpriteAtlasRenderer(DefaultLayers.Alpha));
            EntityManager.Add(buttonA);

            // Button B
            this.buttonB = new Entity()
                                        .AddComponent(new Transform2D()
                                        {
                                            Origin = Vector2.One / 2,
                                            X = 552,
                                            Y = 305,
                                            DrawOrder = 0.5f,
                                        })
                                        .AddComponent(new SpriteAtlas("Content/Buttons.wpk", "circlePressed"))
                                        .AddComponent(new SpriteAtlasRenderer(DefaultLayers.Alpha));
            EntityManager.Add(buttonB);

            // ButtonX
            this.buttonX = new Entity()
                                       .AddComponent(new Transform2D()
                                       {
                                           Origin = Vector2.One / 2,
                                           X = 465,
                                           Y = 305,
//.........这里部分代码省略.........
开发者ID:123asd123A,项目名称:Samples,代码行数:101,代码来源:MyScene.cs


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