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


C# Entity.GetComponent方法代码示例

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


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

示例1: ProcessEntity

		protected override void ProcessEntity(Engine engine, Entity entity)
		{
			// 2 per 1000 milliseconds
			var amountPerSecond = 2;
			var people = entity.GetComponent<PeopleComponent>().Amount;
			entity.GetComponent<GoldComponent>().Amount += (engine.DeltaMs*amountPerSecond/1000.0) * people;
		}
开发者ID:tolemac,项目名称:RosWorld,代码行数:7,代码来源:Program.cs

示例2: Attach

 private void Attach(int uid)
 {
     _master = Owner.EntityManager.GetEntity(uid);
     // TODO handle this using event queue so that these sorts of interactions are deferred until we can be sure the target entity exists
     _master.GetComponent<TransformComponent>(ComponentFamily.Transform).OnMove += HandleOnMove;
     Translate(_master.GetComponent<TransformComponent>(ComponentFamily.Transform).Position);
 }
开发者ID:MSylvia,项目名称:space-station-14,代码行数:7,代码来源:SlaveMoverComponent.cs

示例3: Process

        /// <summary>
        /// Renders all entities with a sprite and a transform to the screen.
        /// </summary>
        /// <param name="e"></param>
        public override void Process(Entity e)
        {
            try
            {
                //Get sprite data and transform
                ITransform transform = e.GetComponent<ITransform>();
                Sprite sprite = e.GetComponent<Sprite>();

                if (sprite.Source != null)
                    //Draw to sprite batch
                    spriteBatch.Draw(
                        sprite.SpriteSheet.Texture,
                        ConvertUnits.ToDisplayUnits(transform.Position),
                        sprite.CurrentRectangle,
                        sprite.Color,
                        transform.Rotation,
                        sprite.Origin,
                        sprite.Scale,
                        SpriteEffects.None, sprite.Layer);
            }
            catch
            {
                e.Delete();
                Console.WriteLine("Exception try-caught in RenderSystem");
            }
        }
开发者ID:LostCodeStudios,项目名称:GameLib,代码行数:30,代码来源:RenderSystem.cs

示例4: Process

 /// <summary>
 /// Updates all the positions by applying velocity.
 /// </summary>
 /// <param name="entity"></param>
 protected override void Process(Entity entity)
 {
     var pos = entity.GetComponent<PositionComponent>();
     var vel = entity.GetComponent<VelocityComponent>();
     var dif = vel.Value * (float)AlmiranteEngine.Time.Frame;
     pos.Set(dif.X + pos.X, dif.Y + pos.Y);
 }
开发者ID:WoLfulus,项目名称:Almirante,代码行数:11,代码来源:MovementSystem.cs

示例5: attack

        public static void attack(Entity attacker, Entity target)
        {
            // calc dmg
            Weapon weapon = ((Equipment)attacker.GetComponent("Equipment")).MainHand;
            int predamage = RollManager.roll(weapon.Dice_Num, weapon.Dice_Sides, weapon.Roll_Mod);
            // subtract dmg reduction
            Armor armor = ((Equipment)target.GetComponent("Equipment")).Chest;

            int damage = predamage - armor.DmgReduction;
            // reduce hp and shoot messages

            Information targetInfo = target.GetComponent("Information") as Information;
            Information attackerInfo = attacker.GetComponent("Information") as Information;

            if (damage > 0)
            {
                target.DoAction("TakeDamage", new TakeDamageArgs(damage));
                string message = String.Format("{0} swings at {1} for {2} damage.", attackerInfo.Username, targetInfo.Username, damage);
                MessageManager.Instance.addMessage(message);
                if (!((Hitpoints)target.GetComponent("Hitpoints")).Alive)
                    MessageManager.Instance.addMessage(String.Format("{0} dies!", (target.GetComponent("Information") as Information).Username));
            }
            else
            {
                string message = String.Format("{0} attacks {1}, but it glances off.", attackerInfo.Username, targetInfo.Username, damage);
                MessageManager.Instance.addMessage(message);
            }
        }
开发者ID:poemdexter,项目名称:Dungeoneers,代码行数:28,代码来源:CombatManager.cs

示例6: Process

        public override void Process(Entity e)
        {
            Body b = e.GetComponent<Body>();
            Origin o = e.GetComponent<Origin>();
            if (o != null)
            {
                Entity parent = o.Parent;

                Vector2 origin = parent.GetComponent<Body>().Position;

                float lastTime = elapsedSeconds;
                elapsedSeconds += 16 / 1000f;

                if (elapsedSeconds > orbitTime)
                {
                    elapsedSeconds = 0f;
                }

                Vector2 oldPosition = origin + new Vector2((float)(ConvertUnits.ToSimUnits(Radius) * (Math.Cos(MathHelper.ToRadians(360 / orbitTime) * lastTime))), (float)(ConvertUnits.ToSimUnits(Radius) * (Math.Sin(MathHelper.ToRadians(360 / orbitTime) * lastTime))));
                Vector2 newPosition = origin + new Vector2((float)(ConvertUnits.ToSimUnits(Radius) * (Math.Cos(MathHelper.ToRadians(360 / orbitTime) * elapsedSeconds))), (float)(ConvertUnits.ToSimUnits(Radius) * (Math.Sin(MathHelper.ToRadians(360 / orbitTime) * elapsedSeconds))));

                //b.LinearVelocity = parent.GetComponent<Body>().LinearVelocity + (newPosition - oldPosition);
                b.Position = newPosition;
            }
        }
开发者ID:LostCodeStudios,项目名称:SpaceHordes,代码行数:25,代码来源:SmasherBallSystem.cs

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

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

示例9: Process

        // Updates the entities position based on it's velocity.
        protected override void Process(Entity entity)
        {
            var vel = entity.GetComponent<VelocityComponent>();
            var transform = entity.GetComponent<TransformComponent>();

            transform.Position += vel.Velocity * entityWorld.DeltaTime.Milliseconds;
        }
开发者ID:ZachMassia,项目名称:XNA_Project,代码行数:8,代码来源:MovementSystem.cs

示例10: PlaceItem

 private void PlaceItem(Entity actor, Entity item)
 {
     var rnd = new Random();
     actor.SendMessage(this, ComponentMessageType.DropItemInCurrentHand);
     item.GetComponent<SpriteComponent>(ComponentFamily.Renderable).drawDepth = DrawDepth.ItemsOnTables;
     //TODO Unsafe, fix.
     item.GetComponent<TransformComponent>(ComponentFamily.Transform).TranslateByOffset(
         new Vector2f(rnd.Next(-28, 28), rnd.Next(-28, 15)));
 }
开发者ID:MSylvia,项目名称:space-station-14,代码行数:9,代码来源:WorktopComponent.cs

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

示例12: OnCollision

 protected override bool OnCollision(Entity Entity, EntityClassification Classification)
 {
     var sc = Entity.GetComponent<ScoreComponent>();
     sc.Coins += Value;
     var ftc = Entity.GetComponent<FloatingTextComponent>();
     if (ftc != null)
         ftc.Add("+" + Value.ToString(), Color.Gold);
     AudioManager.PlaySoundEffect("CoinPickup");
     Parent.Dispose();
     return true;
 }
开发者ID:Octanum,项目名称:Corvus,代码行数:11,代码来源:CollisionCoinComponent.cs

示例13: SpecialSquareTo

        private bool SpecialSquareTo(Entity mEntity, int mNextX, int mNextY, bool mNextSuccess, out bool mAbort)
        {
            mAbort = false;

            if (mEntity.GetComponent<TDCWielder>() == null) return true;
            if (!mNextSuccess) return true;
            if (!TrySheateEntity(mEntity)) return true;

            mEntity.GetComponent<TDCDirection>().Direction = TDCDirection.GetDirection(new TDVector2(mNextX, mNextY));

            return true;
        }
开发者ID:SuperV1234,项目名称:TimeDRODPOF,代码行数:12,代码来源:TDCOremites.cs

示例14: BuildEntity

        /// <summary>
        ///
        /// </summary>
        /// <param name="e"></param>
        /// <param name="args">args[0] = Entity smasher, args[1] = Smasher loc</param>
        /// <returns></returns>
        public Entity BuildEntity(Entity e, params object[] args)
        {
            string spriteKey = "smasherball";

            #region Body

            Body bitch = e.AddComponent<Body>(new Body(_World, e));
            FixtureFactory.AttachEllipse(ConvertUnits.ToSimUnits(_SpriteSheet[spriteKey][0].Width / 2), ConvertUnits.ToSimUnits(_SpriteSheet[spriteKey][0].Height / 2), 20, 1f, bitch);
            Sprite s = new Sprite(_SpriteSheet, spriteKey, bitch, 1f, Color.White, 0.5f);
            e.AddComponent<Sprite>(s);

            bitch.BodyType = GameLibrary.Dependencies.Physics.Dynamics.BodyType.Dynamic;
            bitch.CollisionCategories = GameLibrary.Dependencies.Physics.Dynamics.Category.Cat2 | GameLibrary.Dependencies.Physics.Dynamics.Category.Cat1;
            bitch.CollidesWith = GameLibrary.Dependencies.Physics.Dynamics.Category.Cat6 | GameLibrary.Dependencies.Physics.Dynamics.Category.Cat1;
            bitch.OnCollision += LambdaComplex.BossCollision();

            ++bitch.Mass;

            Entity smasher = (args[0] as Entity);

            float dist = ConvertUnits.ToSimUnits(20f);
            Vector2 pos = smasher.GetComponent<Body>().Position + new Vector2(0, dist);
            bitch.Position = pos;

            #endregion Body

            #region Animation

            if (s.Source.Count() > 1)
                e.AddComponent<Animation>(new Animation(AnimationType.Bounce, 10));

            #endregion Animation

            #region Health

            e.AddComponent<Health>(new Health(1000000)).OnDeath +=
                ent =>
                {
                    Vector2 poss = e.GetComponent<ITransform>().Position;
                    _World.CreateEntityGroup("BigExplosion", "Explosions", poss, 10, e, e.GetComponent<IVelocity>().LinearVelocity);

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

            #endregion Health

            e.AddComponent<Origin>(new Origin(smasher));
            e.Group = "Enemies";
            e.Tag = "SmasherBall";
            return e;
        }
开发者ID:LostCodeStudios,项目名称:SpaceHordes,代码行数:58,代码来源:SmasherBallTemplate.cs

示例15: BuildEntity

        public Entity BuildEntity(Entity e, params object[] args)
        {
            e.Tag = "Player";
            Rectangle source = (Rectangle)args[1];

            FixtureFactory.AttachCircle(ConvertUnits.ToSimUnits(source.Height/2),1f,e.AddComponent<Body>(new Body(_World, e)));
            e.GetComponent<Body>().BodyType = GameLibrary.Dependencies.Physics.Dynamics.BodyType.Dynamic;
            e.GetComponent<Body>().FixedRotation = true;

            e.AddComponent<Sprite>(new Sprite(args[0] as Texture2D, source, new Vector2(30,16),1f,Color.White,0.1f)); //Sprite

            return e;
        }
开发者ID:LostCodeStudios,项目名称:GameLib,代码行数:13,代码来源:PlayerTemplate.cs


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