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


C# Entity.RemoveComponent方法代码示例

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


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

示例1: Process

        public override void Process(Entity e)
        {
            Damage d = e.GetComponent<Damage>();
            Health h = e.GetComponent<Health>();

            if (d.Seconds <= 0)
            {
                e.RemoveComponent<Damage>(d);
                e.Refresh();

                return;
            }

            d.Seconds -= (float)world.Delta / 1000;

            h.SetHealth(e, h.CurrentHealth - d.DamagePerSecond * (world.Delta / 1000));

            Sprite s = e.GetComponent<Sprite>();

            Vector2 offset;
            if (!e.Tag.Contains("Boss"))
            {
                double mes = Math.Sqrt(s.CurrentRectangle.Width * s.CurrentRectangle.Height / 4);
                offset = new Vector2((float)((r.NextDouble() * 2 - 1) * mes), (float)((r.NextDouble() * 2 - 1) * mes));
            }
            else
            {
                offset = new Vector2((float)((r.NextDouble() * 2 - 1) * s.CurrentRectangle.Width / 2), (float)((r.NextDouble() * 2 - 1) * s.CurrentRectangle.Height / 2));
            }
            world.CreateEntity("GREENFAIRY", e, ConvertUnits.ToSimUnits(offset)).Refresh();
        }
开发者ID:LostCodeStudios,项目名称:SpaceHordes,代码行数:31,代码来源:DamageSystem.cs

示例2: Process

        public void Process(Entity toProcess, GameTime gameTime)
        {
            if (!IsApplicableTo(toProcess))
            {
                return;
            }

            // TODO pass this in so it can be controlled
            Random rand = new Random();

            RandomPositionOffsetComponent offset = (RandomPositionOffsetComponent)toProcess.components[typeof(RandomPositionOffsetComponent)];
            int minX = (int)Math.Min(offset.Maximum.X, offset.Minimum.X);
            int maxX = (int)Math.Max(offset.Maximum.X, offset.Minimum.X);

            int minY = (int)Math.Min(offset.Maximum.Y, offset.Minimum.Y);
            int maxY = (int)Math.Max(offset.Maximum.Y, offset.Minimum.Y);

            int x = rand.Next(minX, maxX);
            int y = rand.Next(minY, maxY);

            PositionDeltaComponent delta = new PositionDeltaComponent();
            if (toProcess.components.ContainsKey(typeof(PositionDeltaComponent)))
            {
                delta = (PositionDeltaComponent)toProcess.components[typeof(PositionDeltaComponent)];
                delta.Delta += new Vector2(x, y);
            }
            else
            {
                delta.Delta = new Vector2(x, y);
                toProcess.AddComponent(delta);
            }

            toProcess.RemoveComponent(offset);
        }
开发者ID:knexer,项目名称:MonoGameShooterModernUI,代码行数:34,代码来源:RandomPositionOffsetSystem.cs

示例3: Process

        public override void Process(Entity e)
        {
            if (!e.HasComponent<Animation>())
                return;

            Sprite sprite = e.GetComponent<Sprite>();
            Animation anim = e.GetComponent<Animation>();

            if (anim.Type != AnimationType.None)
            {
                anim._Tick += world.Delta;

                if (anim._Tick >= anim.FrameRate)
                {
                    anim._Tick -= anim.FrameRate;
                    switch (anim.Type)
                    {
                        case AnimationType.Loop:
                            sprite.FrameIndex++; //Console.WriteLine("Animation happened");
                            break;

                        case AnimationType.ReverseLoop:
                            sprite.FrameIndex--;
                            break;

                        case AnimationType.Increment:
                            sprite.FrameIndex++;
                            anim.Type = AnimationType.None;
                            break;

                        case AnimationType.Decrement:
                            sprite.FrameIndex--;
                            anim.Type = AnimationType.None;
                            break;

                        case AnimationType.Bounce:
                            sprite.FrameIndex += anim.FrameInc;
                            if (sprite.FrameIndex == sprite.Source.Count() - 1)
                                anim.FrameInc = -1;

                            if (sprite.FrameIndex == 0)
                                anim.FrameInc = 1;
                            break;

                        case AnimationType.Once:
                            if (sprite.FrameIndex < sprite.Source.Count() - 1)
                                sprite.FrameIndex++;
                            else
                                anim.Type = AnimationType.None;
                            break;
                    }
                    e.RemoveComponent<Sprite>(e.GetComponent<Sprite>());
                    e.AddComponent<Sprite>(sprite);
                }
            }
        }
开发者ID:LostCodeStudios,项目名称:GameLib,代码行数:56,代码来源:AnimationSystem.cs

示例4: Process

        public override void Process(Entity e)
        {
            Slow slow = slowMapper.Get(e);
            if (slow != null && slow != Slow.None) //If particle is slowing
            {
                slow.Elapsed--;
                if (slow.Elapsed <= 0)
                {
                    e.RemoveComponent<Slow>(slow);
                    IDamping d = dampingMapper.Get(e);
                    d.LinearDamping = 0;
                    d.AngularDamping = 0;
                    if (e.HasComponent<AI>())
                    {
                        AI a = e.GetComponent<AI>();
                        e.RemoveComponent<AI>(e.GetComponent<AI>());
                        a.Calculated = false;
                        e.AddComponent<AI>(a);
                    }

                    e.Refresh();
                    return;
                }
                IVelocity velocity = velocityMapper.Get(e);
                IDamping damping = dampingMapper.Get(e);

                //Slow particle angular speed
                if (velocity.AngularVelocity > slow.AngularTargetVelocity || damping.AngularDamping != slow.AngularSlowRate)
                    damping.AngularDamping = slow.AngularSlowRate;
                else
                    damping.AngularDamping = 0;

                //Slow particle linear speed
                if (velocity.LinearVelocity.Length() - slow.LinearTargetVelocity.Length() > 1 || damping.LinearDamping != slow.LinearSlowRate)
                    damping.LinearDamping = slow.LinearSlowRate;
                else
                    damping.LinearDamping = 0;

                SpawnFrostEffect(e);
            }
        }
开发者ID:LostCodeStudios,项目名称:SpaceHordes,代码行数:41,代码来源:SlowSystem.cs

示例5: Process

        public void Process(Entity toProcess, GameTime gameTime)
        {
            if (!IsApplicableTo(toProcess))
            {
                return;
            }

            //Get the components out of the entity
            PositionComponent pos = (PositionComponent)toProcess.components[typeof(PositionComponent)];
            PositionDeltaComponent delta = (PositionDeltaComponent)toProcess.components[typeof(PositionDeltaComponent)];

            //Update the entity's position
            pos.Position = pos.Position + delta.Delta;
            pos.Rotation = pos.Rotation + delta.RotationDelta;

            //This unit no longer needs to move
            toProcess.RemoveComponent(delta);
        }
开发者ID:knexer,项目名称:MonoGameShooterModernUI,代码行数:18,代码来源:EntityTranslationSystem.cs

示例6: Process

        public Entity Process(EntityManagerManager manager, Entity toProcess, GameTime gameTime)
        {
            if (!IsApplicableTo(toProcess))
            {
                return null;
            }

            //Get the component
            SpawnEntityComponent spawner = (SpawnEntityComponent)toProcess.components[typeof(SpawnEntityComponent)];

            //Construct a copy of the entity to be spawned
            Entity toSpawn = spawner.Factory.CreateEntity(toProcess, new Entity());

            //Remove the offending component so we don't get more spawns
            toProcess.RemoveComponent(spawner);

            //Spawn that entity by adding it to the list of entities to be updated by systems
            return toSpawn;
        }
开发者ID:knexer,项目名称:MonoGameShooterModernUI,代码行数:19,代码来源:SpawnEntitySystem.cs

示例7: Process

        public override void Process(Entity e)
        {
            Body b = bodyMapper.Get(e);

            #region UserMovement
            if (WasMoving) //Stops movement
            {
                b.LinearDamping = (float)Math.Pow(_Velocity, _Velocity*4);
                WasMoving = false;
            }
            else
                b.LinearDamping = 0;

            Vector2 target = Vector2.Zero;
            if (Keyboard.GetState().IsKeyDown(Keys.D)){ //Right
                target += Vector2.UnitX;
            }
            else if (Keyboard.GetState().IsKeyDown(Keys.A)){ //Left
                target += -Vector2.UnitX;
            }
            if (Keyboard.GetState().IsKeyDown(Keys.S)){ //Down
                target += Vector2.UnitY;
            }
            else if (Keyboard.GetState().IsKeyDown(Keys.W)){ //Up?
                target += -Vector2.UnitY;
            }

            if (target != Vector2.Zero) //If being moved by player
            {
                WasMoving = true;
                b.LinearDamping = _Velocity*2;
            }

            //Rotation
            if (b.LinearVelocity != Vector2.Zero)
                //b.Rotation = MathHelper.SmoothStep(b.Rotation, (float)Math.Atan2(b.LinearVelocity.Y, b.LinearVelocity.X) + (float)Math.PI/2f, 0.1f);
                b.Rotation = (float)Math.Atan2(b.LinearVelocity.Y, b.LinearVelocity.X) + (float)Math.PI / 2f;

            //update position
            b.ApplyLinearImpulse((target)*new Vector2(_Velocity));
            #endregion

            #region Animation
            if (target != Vector2.Zero && b.LinearVelocity.Length() != 0 && (int)(5/Math.Pow(b.LinearVelocity.Length(), 1 / 2)) != 0)
            { //if player is being moved.
                if (world.StepCount % (int)(5 / Math.Pow(b.LinearVelocity.Length(), 1 / 2)) == 0)
                {
                    AnimationHeight += 30;
                    AnimationHeight %= 90; //Max height on spritesheet.
                }
            }

            else
                AnimationHeight = 30;
            Sprite s = e.GetComponent<Sprite>();
            s = new Sprite(s.SpriteSheet.Texture, new Rectangle(15, AnimationHeight, 50, 30), s.Origin, s.Scale, s.Color, s.Layer);
            e.RemoveComponent(ComponentTypeManager.GetTypeFor<Sprite>());
            e.AddComponent<Sprite>(s);
            #endregion
        }
开发者ID:LostCodeStudios,项目名称:GameLib,代码行数:60,代码来源:PlayerControlSystem.cs

示例8: BuildEntity


//.........这里部分代码省略.........
                    health = 150;
                    break;

                case 2:
                    points = 500;
                    health = 175;
                    break;

                case 3:
                    points = 1000;
                    health = 200;
                    break;
            }

            Health h = new Health(health);
            h.OnDeath += LambdaComplex.BossDeath(type, _World, e, s, tier, points, bosses[type].BossName);

            if (type == 1)
            {
                h.OnDeath +=
                    ex =>
                        {
                               Console.WriteLine("DEad");
                        };
            }

            if (a != null)
            {
                h.OnDamage +=
                    ent =>
                    {
                        if (h.IsAlive && a.Type == AnimationType.None)
                        {
                            e.RemoveComponent<Sprite>(s);

                            double healthFraction = (h.CurrentHealth / h.MaxHealth);

                            int frame = 0;
                            int frames = s.Source.Length;

                            frame = (int)(frames - (frames * healthFraction));

                            if (frame != s.FrameIndex)
                            {
                                int splodeSound = rbitch.Next(1, 5);
                                SoundManager.Play("Explosion" + splodeSound.ToString());
                                Vector2 poss = e.GetComponent<ITransform>().Position;
                                _World.CreateEntityGroup("BigExplosion", "Explosions", poss, 15, e, e.GetComponent<IVelocity>().LinearVelocity);
                            }
                            s.FrameIndex = frame;

                            e.AddComponent<Sprite>(s);
                        }
                    };
            }

            if (spriteKey.Equals("flamer"))
            {
                h.OnDamage +=
                    ent =>
                    {
                        //Fire flame from random spot

                        int range = s.CurrentRectangle.Width / 2;
                        float posx = rbitch.Next(-range, range);
                        Vector2 pos1 = bitch.Position + ConvertUnits.ToSimUnits(new Vector2(posx, 0));
开发者ID:LostCodeStudios,项目名称:SpaceHordes,代码行数:67,代码来源:BossTemplate.cs

示例9: handleSlow

 private static void handleSlow(Entity ent, EntityWorld _World)
 {
     (_World as SpaceWorld).slowSystem.SpawnFrostEffect(ent);
     Slow slow = ent.GetComponent<Slow>();
     slow.Elapsed--;
     if (slow.Elapsed <= 0)
     {
         ent.RemoveComponent<Slow>(slow);
     }
 }
开发者ID:LostCodeStudios,项目名称:SpaceHordes,代码行数:10,代码来源:AI.cs

示例10: RefreshModel

        /// <summary>
        /// Refresh the surface mesh
        /// </summary>
        /// <param name="surface">The hololens surface information</param>
        /// <param name="surfaceEntity">The entity to update</param>
        protected override void RefreshModel(SpatialMappingSurface surface, Entity surfaceEntity)
        {
            if (!surfaceEntity.IsDisposed)
            {
                surfaceEntity.RemoveComponent<Model>()
                    .RemoveComponent<ModelRenderer>()
                    .AddComponent(Model.CreateFromMesh(surface.Mesh));

                if (this.IsVisible && !string.IsNullOrEmpty(this.MaterialPath))
                {
                    surfaceEntity.AddComponent(new ModelRenderer());
                }
            }
        }
开发者ID:WaveEngine,项目名称:Extensions,代码行数:19,代码来源:SpatialMapping.cs

示例11: RefreshCollider

        /// <summary>
        /// Refresh the collider of a surface entity
        /// </summary>
        /// <param name="surfaceEntity">The entity to update</param>
        protected override void RefreshCollider(Entity surfaceEntity)
        {
            if (!surfaceEntity.IsDisposed)
            {
                surfaceEntity.RemoveComponent<MeshCollider3D>();
                surfaceEntity.RemoveComponent<RigidBody3D>();

                if (this.GenerateColliders)
                {
                    surfaceEntity.AddComponent(new MeshCollider3D());
                    surfaceEntity.AddComponent(new RigidBody3D() { IsKinematic = true });

                    surfaceEntity.RefreshDependencies();
                }
            }
        }
开发者ID:WaveEngine,项目名称:Extensions,代码行数:20,代码来源:SpatialMapping.cs

示例12: AddEntity

        public bool AddEntity(Entity user, Entity inventory, Entity toAdd, InventoryLocation location = InventoryLocation.Any)
        {
            var comHands = inventory.GetComponent<HumanHandsComponent>(ComponentFamily.Hands);
            var comEquip = inventory.GetComponent<EquipmentComponent>(ComponentFamily.Equipment);
            var comInv = inventory.GetComponent<InventoryComponent>(ComponentFamily.Inventory);

            if ((location == InventoryLocation.Inventory) && comInv != null)
            {
                if (comInv.AddEntity(user, toAdd))
                {
                    //Do sprite stuff and attaching
                    return true;
                }
            }
            else if ((location == InventoryLocation.HandLeft || location == InventoryLocation.HandRight) && comHands != null)
            {
                if (comHands.AddEntity(user, toAdd, location))
                {
                    //Do sprite stuff and attaching
                    toAdd.RemoveComponent(ComponentFamily.Mover);
                    toAdd.AddComponent(ComponentFamily.Mover, EntityManager.ComponentFactory.GetComponent<SlaveMoverComponent>());
                    toAdd.GetComponent<SlaveMoverComponent>(ComponentFamily.Mover).Attach(inventory);
                    if (toAdd.HasComponent(ComponentFamily.Renderable) && inventory.HasComponent(ComponentFamily.Renderable))
                    {
                        toAdd.GetComponent<IRenderableComponent>(ComponentFamily.Renderable).SetMaster(inventory);
                    }
                    toAdd.GetComponent<BasicItemComponent>(ComponentFamily.Item).HandlePickedUp(inventory, location);
                    return true;
                }
            }
            else if ((location == InventoryLocation.Equipment || location == InventoryLocation.Any) && comEquip != null)
            {
                if (comEquip.AddEntity(user, toAdd))
                {
                    EquippableComponent eqCompo = toAdd.GetComponent<EquippableComponent>(ComponentFamily.Equippable);
                    eqCompo.currentWearer = user;
                    //Do sprite stuff and attaching.
                    return true;
                }
            }     
            else if (location == InventoryLocation.Any)
            {
                //Do sprite stuff and attaching.
                bool done = false;

                if (comInv != null)
                    done = comInv.AddEntity(user, toAdd);

                if (comEquip != null && !done)
                    done = comEquip.AddEntity(user, toAdd);

                if (comHands != null && !done)
                    done = comHands.AddEntity(user, toAdd, location);

                return done;
            }

            return false;
        }
开发者ID:Gartley,项目名称:ss13remake,代码行数:59,代码来源:InventorySystem.cs

示例13: RemoveEntity

        public bool RemoveEntity(Entity user, Entity inventory, Entity toRemove, InventoryLocation location = InventoryLocation.Any)
        {
            var comHands = inventory.GetComponent<HumanHandsComponent>(ComponentFamily.Hands);
            var comEquip = inventory.GetComponent<EquipmentComponent>(ComponentFamily.Equipment);
            var comInv = inventory.GetComponent<InventoryComponent>(ComponentFamily.Inventory);

            if ((location == InventoryLocation.Inventory) && comInv != null)
            {
                if (comInv.RemoveEntity(user, toRemove))
                {
                    //Do sprite stuff and detaching
                    return true;
                }
            }
            else if ((location == InventoryLocation.HandLeft || location == InventoryLocation.HandRight) && comHands != null)
            {
                if (comHands.RemoveEntity(user, toRemove))
                {
                    //Do sprite stuff and attaching
                    var toRemoveSlaveMover = toRemove.GetComponent<SlaveMoverComponent>(ComponentFamily.Mover);
                    if(toRemoveSlaveMover != null)
                    {
                        toRemoveSlaveMover.Detach();
                    }

                    if (toRemove.HasComponent(ComponentFamily.Renderable))
                    {
                        toRemove.GetComponent<IRenderableComponent>(ComponentFamily.Renderable).UnsetMaster();
                    }
                    toRemove.RemoveComponent(ComponentFamily.Mover);
                    toRemove.AddComponent(ComponentFamily.Mover, EntityManager.ComponentFactory.GetComponent<BasicMoverComponent>());
                    toRemove.GetComponent<BasicItemComponent>(ComponentFamily.Item).HandleDropped();
                    return true;
                }
            }
            else if ((location == InventoryLocation.Equipment || location == InventoryLocation.Any) && comEquip != null)
            {
                if (comEquip.RemoveEntity(user, toRemove))
                {
                    //Do sprite stuff and detaching
                    EquippableComponent eqCompo = toRemove.GetComponent<EquippableComponent>(ComponentFamily.Equippable);
                    if(eqCompo != null) eqCompo.currentWearer = null;
                    return true;
                }
            }
            else if (location == InventoryLocation.Any)
            {
                //Do sprite stuff and detaching
                bool done = false;

                if (comInv != null)
                    done = comInv.RemoveEntity(user, toRemove);

                if (comEquip != null && !done)
                    done = comEquip.RemoveEntity(user, toRemove);

                if (comHands != null && !done)
                    done = comHands.RemoveEntity(user, toRemove);

                return done;
            }

            return false;
        }
开发者ID:Gartley,项目名称:ss13remake,代码行数:64,代码来源:InventorySystem.cs

示例14: DrawComponent

        public static void DrawComponent(bool[] unfoldedComponents, Entity entity, int index, IComponent component)
        {
            var componentType = component.GetType();

            var componentName = componentType.Name.RemoveComponentSuffix();
            if(componentName.ToLower().Contains(_componentNameSearchTerm.ToLower())) {

                var boxStyle = getColoredBoxStyle(entity.totalComponents, index);
                EntitasEditorLayout.BeginVerticalBox(boxStyle);
                {
                    var memberInfos = componentType.GetPublicMemberInfos();
                    EntitasEditorLayout.BeginHorizontal();
                    {
                        if(memberInfos.Count == 0) {
                            EditorGUILayout.LabelField(componentName, EditorStyles.boldLabel);
                        } else {
                            unfoldedComponents[index] = EntitasEditorLayout.Foldout(unfoldedComponents[index], componentName, _foldoutStyle);
                        }
                        if(GUILayout.Button("-", GUILayout.Width(19), GUILayout.Height(14))) {
                            entity.RemoveComponent(index);
                        }
                    }
                    EntitasEditorLayout.EndHorizontal();

                    if(unfoldedComponents[index]) {

                        var componentDrawer = getComponentDrawer(componentType);
                        if(componentDrawer != null) {
                            var newComponent = entity.CreateComponent(index, componentType);
                            component.CopyPublicMemberValues(newComponent);
                            EditorGUI.BeginChangeCheck();
                            {
                                componentDrawer.DrawComponent(newComponent);
                            }
                            var changed = EditorGUI.EndChangeCheck();
                            if(changed) {
                                entity.ReplaceComponent(index, newComponent);
                            } else {
                                entity.GetComponentPool(index).Push(newComponent);
                            }
                        } else {
                            foreach(var info in memberInfos) {
                                DrawAndSetElement(info.type, info.name, info.GetValue(component),
                                    entity, index, component, info.SetValue);
                            }
                        }
                    }
                }
                EntitasEditorLayout.EndVertical();
            }
        }
开发者ID:sschmid,项目名称:Entitas-CSharp,代码行数:51,代码来源:EntityDrawer.cs


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