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


C# Entity.HasComponent方法代码示例

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


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

示例1: Process

        public override void Process(Entity e)
        {
            Health h = healthMapper.Get(e);

            if (h == null)
                return;

            if (e.HasComponent<Origin>())
            {
                Origin o = e.GetComponent<Origin>();
                Entity parent = o.Parent;

                if (!parent.HasComponent<Body>() || !parent.GetComponent<Health>().IsAlive)
                {
                    if (e.HasComponent<Health>())
                        e.GetComponent<Health>().SetHealth(e, 0);
                    else
                        e.Delete();
                }
            }

            if (!h.IsAlive)
            {
                h.SetHealth(e, 0);
                e.Delete();
            }
        }
开发者ID:LostCodeStudios,项目名称:SpaceHordes,代码行数:27,代码来源:HealthSystem.cs

示例2: UserClickedEntity

 public bool UserClickedEntity(Entity user, Entity obj, int mouseClickType)
 {
     if (user.HasComponent(ComponentFamily.Hands))
     {
         //It's something with hands!
         if (mouseClickType == MouseClickType.Left)
         {
             if (obj.HasComponent(ComponentFamily.Item))
             {
                 //It's something with hands using their hands on an item!
                 return DoHandsToItemInteraction(user, obj);
             }
             if (obj.HasComponent(ComponentFamily.LargeObject))
             {
                 //It's something with hands using their hands on a large object!
                 return DoHandsToLargeObjectInteraction(user, obj);
             }
             if (obj.HasComponent(ComponentFamily.Actor))
             {
                 //It's something with hands using their hands on an actor!
                 return DoHandsToActorInteraction(user, obj);
             }
         }
         if (mouseClickType == MouseClickType.Right)
         {
             if (obj.HasComponent(ComponentFamily.Item))
             {
                 //It's something with hands using their hands on an item!
                 return DoHandsToItemInteraction(user, obj);
             }
             if (obj.HasComponent(ComponentFamily.LargeObject))
             {
                 //It's something with hands using their hands on a large object!
                 return DoHandsToLargeObjectInteraction(user, obj);
             }
             if (obj.HasComponent(ComponentFamily.Actor))
             {
                 //It's something with hands using their hands on an actor!
                 return DoHandsToActorInteraction(user, obj);
             }
         }
     }
     return false;
 }
开发者ID:millpond,项目名称:space-station-14,代码行数:44,代码来源:InteractionSystem.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: apply

        public bool apply(Entity entity)
        {
            foreach (Type componentType in ComponentTypes) {
                if (!entity.HasComponent(componentType)) {
                    return false;
                }
            }

            return true;
        }
开发者ID:jackwilsdon,项目名称:SkiiSharp,代码行数:10,代码来源:EntityComponentTypeFilter.cs

示例5: GetIconSprite

		public static CluwneSprite GetIconSprite(Entity entity)
        {
            if(entity.HasComponent(ComponentFamily.Icon))
            {
                var icon = entity.GetComponent<IconComponent>(ComponentFamily.Icon).Icon;
                if (icon == null)
                    return IoCManager.Resolve<IResourceManager>().GetNoSprite();
                return icon;
            }
            return IoCManager.Resolve<IResourceManager>().GetNoSprite();
        }
开发者ID:millpond,项目名称:space-station-14,代码行数:11,代码来源:Utilities.cs

示例6: ProcessEntity

 // Process a single entity if it has all required components.
 internal void ProcessEntity(Entity entity)
 {
     // Make sure it has all required components.
     foreach (var t in Types)
     {
         if (!entity.HasComponent(t))
         {
             return;
         }
     }
     Process(entity);
 }
开发者ID:ZachMassia,项目名称:XNA_Project,代码行数:13,代码来源:EntitySystem.cs

示例7: RegisterEntity

        public void RegisterEntity (Entity entity)
        {
            if (!entity.HasComponent<TransformComponent>())
            {
                Logger.Log.AddLogEntry (LogLevel.Error, "AIManager",
                    "An error occured while registering new entity in AIManager: " +
                    "'{0}' has no TransformComponent!}");
            }

            lock (entities)
            {
                entities.Add (entity);
            }
        }
开发者ID:AreonDev,项目名称:NoWayOut,代码行数:14,代码来源:AIManager.cs

示例8: ItemStats

 public ItemStats(Entity item)
 {
     this.item = item;
     if (translate == null)
     {
         translate = new StatTranslator();
     }
     stats = new float[Enum.GetValues(typeof(ItemStatEnum)).Length];
     ParseSockets();
     ParseExplicitMods();
     if (item.HasComponent<Weapon>())
     {
         ParseWeaponStats();
     }
 }
开发者ID:TomTer,项目名称:PoeHud,代码行数:15,代码来源:ItemStats.cs

示例9: ApplyTo

        public override bool ApplyTo(Entity target, Entity sourceActor)
        {
            string sourceName = sourceActor.Name;
            string targetName = (sourceActor.Uid == target.Uid) ? "himself" : target.Name;
            if (!active)
            {
                IoCManager.Resolve<IChatManager>()
                    .SendChatMessage(ChatChannel.Damage, sourceName + " tries to attack " + targetName
                                                         + " with the " + owner.Owner.Name + ", but nothing happens!",
                                     null, sourceActor.Uid);
                return true;
            }

            var targetedArea = BodyPart.Torso;

            ComponentReplyMessage reply = sourceActor.SendMessage(this, ComponentFamily.Actor,
                                                                  ComponentMessageType.GetActorSession);

            if (reply.MessageType == ComponentMessageType.ReturnActorSession)
            {
                var session = (IPlayerSession) reply.ParamsList[0];
                targetedArea = session.TargetedArea;
            }
            else
                throw new NotImplementedException("Actor has no session or No actor component that returns a session");

            //Damage the item that is doing the damage.
            owner.Owner.SendMessage(this, ComponentMessageType.Damage, owner.Owner, 5, DamageType.Collateral);

            //Damage the target.
            if (target.HasComponent(ComponentFamily.Damageable))
            {
                target.SendMessage(this, ComponentMessageType.Damage, owner.Owner, damageAmount, damType, targetedArea);


                //string suffix = (sourceActor.Uid == target.Uid) ? " What a fucking weirdo..." : "";
                IoCManager.Resolve<IChatManager>()
                    .SendChatMessage(ChatChannel.Damage,
                                     sourceName + " " + DamTypeMessage(damType) + " " + targetName + " in the " +
                                     BodyPartMessage(targetedArea) + " with a " + owner.Owner.Name + "!",
                                     null, sourceActor.Uid);
                return true;
            }
            return false;
        }
开发者ID:millpond,项目名称:space-station-14,代码行数:45,代码来源:MeleeWeaponCapability.cs

示例10: BigEnemyDeath

        public static Action<Entity> BigEnemyDeath(Entity e, EntityWorld _World, int points)
        {
            return ent =>
            {
                Vector2 poss = e.GetComponent<ITransform>().Position;
                _World.CreateEntityGroup("BigExplosion", "Explosions", poss, 10, ent, e.GetComponent<IVelocity>().LinearVelocity);

                int splodeSound = rbitch.Next(1, 5);
                SoundManager.Play("Explosion" + splodeSound.ToString());

                if (ent is Entity && (ent as Entity).Group != null && ((ent as Entity).Group == "Players" || (ent as Entity).Group == "Structures") && e.HasComponent<Crystal>())
                {
                    _World.CreateEntity("Crystal", e.GetComponent<ITransform>().Position, e.GetComponent<Crystal>().Color, e.GetComponent<Crystal>().Amount, e);
                    ScoreSystem.GivePoints(points);
                    _World.CreateEntity("Score", points.ToString(), poss).Refresh();
                }
            };
        }
开发者ID:LostCodeStudios,项目名称:SpaceHordes,代码行数:18,代码来源:LambdaComplex.cs

示例11: Process

        public override void Process(Entity e)
        {
            ITransform t = TransformMapper.Get(e);
            if (t == null)
                return;
            if (Vector2.Distance(t.Position, Vector2.Zero) > bound)
            {
                e.Delete();
                return;
            }

            if (e.HasComponent<Components.Timer>() && e.GetComponent<Components.Timer>().Update(world.Delta))
            {
                if (e.Tag == "Boss1")
                    Console.WriteLine("Whooops");

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

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

示例13: ApplyTo

        public override bool ApplyTo(Entity target, Entity sourceActor)
        {
            if (capacity <= 0)
            {
                return false;
                //TODO send the player using the item a message
            }
            var targetedArea = BodyPart.Torso;

            ComponentReplyMessage reply = sourceActor.SendMessage(this, ComponentFamily.Actor,
                                                                  ComponentMessageType.GetActorSession);

            if (reply.MessageType == ComponentMessageType.ReturnActorSession)
            {
                var session = (IPlayerSession) reply.ParamsList[0];
                targetedArea = session.TargetedArea;
            }
            else
                throw new NotImplementedException("Actor has no session or No actor component that returns a session");

            //Reduce the capacity.
            capacity -= 20;

            //Heal the target.
            if (target.HasComponent(ComponentFamily.Damageable))
            {
                target.SendMessage(this, ComponentMessageType.Heal, owner.Owner, 20, damType, targetedArea);

                string sourceName = sourceActor.Name;
                string targetName = (sourceActor.Uid == target.Uid) ? "his" : target.Name + "'s";
                //string suffix = (sourceActor.Uid == target.Uid) ? " What a fucking weirdo..." : "";
                IoCManager.Resolve<IChatManager>()
                    .SendChatMessage(ChatChannel.Damage,
                                     sourceName + " applies the " + owner.Owner.Name + " to " + targetName + " " +
                                     BodyPartMessage(targetedArea) + ".",
                                     null, sourceActor.Uid);
                return true;
            }
            return false;
        }
开发者ID:millpond,项目名称:space-station-14,代码行数:40,代码来源:MedicalCapability.cs

示例14: SetMaster

        public void SetMaster(Entity m)
        {
            if (!m.HasComponent(ComponentFamily.Renderable))
                return;
            var mastercompo = m.GetComponent<SpriteComponent>(ComponentFamily.Renderable);
            //If there's no sprite component, then FUCK IT
            if (mastercompo == null)
                return;

            mastercompo.AddSlave(this);
            master = mastercompo;
        }
开发者ID:millpond,项目名称:space-station-14,代码行数:12,代码来源:SpriteComponent.cs

示例15: PickUpEntity

        public bool PickUpEntity(Entity user, Entity obj)
        {
            HumanHandsComponent userHands = user.GetComponent<HumanHandsComponent>(ComponentFamily.Hands);
            BasicItemComponent objItem = obj.GetComponent<BasicItemComponent>(ComponentFamily.Item);

            if (userHands != null && objItem != null)
            {
                return AddEntity(user, user, obj, userHands.CurrentHand);
            }
            else if (userHands == null && objItem != null && obj.HasComponent(ComponentFamily.Inventory))
            {
                return AddEntity(user, user, obj, InventoryLocation.Inventory);
            }

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


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