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


C# GameObject.QueryComponent方法代码示例

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


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

示例1: Update

        public void Update(Playstates.PlayState State, Worldspawn Worldspawn, GameObject Owner, int GOID)
        {
            var text = Owner.QueryComponent<TextHolder>();
            var builder = new StringBuilder();

            foreach (var property in Properties)
            {
                var split = property.Item1.Split(' ');
                var useful = split.First();
                var propName = useful.Split('.').Last();
                var className = useful.Substring(0, useful.Length - propName.Length - 1);

                var classType = Extensions.GetTypeInfo(Type.GetType(className));
                var propType = classType.GetDeclaredProperty(propName);
                var fieldType = classType.GetDeclaredField(propName);

                builder.Append(propName);
                if (split.Length > 1)
                {
                    builder.Append(" (");
                    builder.Append(property.Item1.Substring(useful.Length + 1));
                    builder.Append(")");
                }
                builder.Append(" : ");
                builder.Append(propType != null ? propType.GetValue(property.Item2) : fieldType.GetValue(property.Item2));
                builder.AppendLine();
            }

            text.Text.Text = builder.ToString();
        }
开发者ID:iLambda,项目名称:Freemwork,代码行数:30,代码来源:PropertyDisplayer.cs

示例2: Update

        public void Update(PlayState State, Worldspawn Worldspawn, GameObject Owner, int GOID)
        {
            if (!Activated)
                return;

            if (frame == 0) Owner.QueryComponent<Identity2D>().Transform.Rotation += Increase;
            frame = (frame + 1) % interval;
        }
开发者ID:iLambda,项目名称:Freemwork,代码行数:8,代码来源:Rotator2D.cs

示例3: Update

        public void Update(PlayState State, Worldspawn Worldspawn, GameObject Owner, int GOID)
        {
            var spriteHolder = Owner.QueryComponent<SpriteHolder>();

            var sX = (int)((MaxSize.Width - MinSize.Width) * Maths.Cos(frame * 2 * Maths.Pi / Frequency)) + MinSize.Width;
            var sY = (int)((MaxSize.Height - MinSize.Height) * Maths.Cos(frame * 2 * Maths.Pi / Frequency)) + MinSize.Height;

            spriteHolder.Sprite.Size = new Size2D<int>(IdleSize.HasValue ? (Oscillate ? sX : IdleSize.Value.Width) : sX, IdleSize.HasValue ? (Oscillate ? sY : IdleSize.Value.Height) : sY);

            if (Oscillate)
                frame = ((frame + 1) % 65536);
        }
开发者ID:iLambda,项目名称:Freemwork,代码行数:12,代码来源:SpriteOscillator.cs

示例4: Update

 public override void Update(PlayState State, Worldspawn Worldspawn, GameObject Owner, int GOID)
 {
     var hitbox = Owner.QueryComponent<Hitbox>();
     var gobs = Worldspawn.SpacePartitionning
         ? Worldspawn.GetNearObjects<Lifespan>(Owner)
         : Worldspawn.GameObjects.Where(Gob => Gob.Value.HasComponent<Lifespan>());
     foreach (var gob in gobs)
     {
         var lifeSpan = gob.Value.QueryComponent<Lifespan>();
         if (lifeSpan.Group != Group) continue;
         var boundingBox = gob.Value.QueryComponent<Hitbox>();
         if (hitbox.Intersects(boundingBox))
         {
             lifeSpan.Kill();
             if (lifeSpan.IsDead)
                 if (InstantlyKill != null) InstantlyKill(this, new InstantlyKilledEventArgs { State = State, GOID = GOID, Owner = Owner, Worldspawn = Worldspawn, DealtTo = gob });
         }
     }
 }
开发者ID:iLambda,项目名称:Freemwork,代码行数:19,代码来源:InstantKiller.cs

示例5: Update

        public override void Update(PlayState State, Worldspawn Worldspawn, GameObject Owner, int GOID)
        {
            var hitbox = Owner.QueryComponent<Hitbox>();
            var gobs = Worldspawn.SpacePartitionning
                ? Worldspawn.GetNearObjects<Lifespan>(Owner)
                : Worldspawn.GameObjects.Where(Gob => Gob.Value.HasComponent<Lifespan>() );
            foreach (var gob in gobs)
            {
                var lifeSpan = gob.Value.QueryComponent<Lifespan>();
                if(lifeSpan.Group != Group) continue;
                var boundingBox = gob.Value.QueryComponent<Hitbox>();
                if (!hitbox.Intersects(boundingBox)) continue;

                var args = new DamageDealtEventArgs { State = State, Worldspawn = Worldspawn, DealtTo = gob, Owner = Owner, GOID = GOID, Amount = Damages };
                var oldLife = lifeSpan.Current;
                lifeSpan.Hurt(Damages);
                args.EffectiveAmount = lifeSpan.Current - oldLife;
                if (DamageDealt != null) DamageDealt(this, args);
            }
        }
开发者ID:iLambda,项目名称:Freemwork,代码行数:20,代码来源:DamageDealer.cs

示例6: _BuildComponment

    private static void _BuildComponment(GameObject obj, IEnumerable<Vector3> positions)
    {
        var mark = obj.GetComponent<EntityLayoutMark>();
        if (mark != null)
        {
            if (mark.Name != ENTITY.STATIC)
                return;
        }
        else
        {
            mark = obj.AddComponent<EntityLayoutMark>();
            mark.Name = ENTITY.STATIC;
        }

        var staticLayout = obj.QueryComponent<StaticLayoutMark>();
        staticLayout.Static = mark;
        staticLayout.Polygon = positions.ToArray();
    }
开发者ID:jiowchern,项目名称:ItIsNotAGame-FrontEnd,代码行数:18,代码来源:StaticLayoutGenerator.cs

示例7: Draw

        public void Draw(PlayState State, Worldspawn Worldspawn, GameObject Owner, int GOID)
        {
            var screenCoordinates = Worldspawn.Camera.Viewport;
            var x = (int) ((screenCoordinates.Left/TileSize).Floor());
            var y = (int) ((screenCoordinates.Top/TileSize).Floor());
            var w = (int) ((screenCoordinates.Width/TileSize).Floor()) + 2;
            var h = (int) ((screenCoordinates.Height/TileSize).Floor()) + 2;

            var identity2D = Owner.QueryComponent<Identity2D>();
            var transform = identity2D.Transform;
            var region = Tileset.Region;
            var size = Tileset.Size;
            var emptyTransform = Transform2D.Identity;
            var depth = Tileset.Depth;

            Tileset.Size = new Size2D<int>(TileSize, TileSize);

            for (int i = x; i < x + w; i++)
            {
                for (int j = y; j < y + h; j++)
                {
                    for (int k = 0; k < Tiles.GetLength(2); k++)
                    {
                        var tile = GetTile(i, j, k);

                        if (tile == null)
                            continue;
                        if (tile.Item1 < 0 || tile.Item2 < 0)
                            continue;

                        Tileset.Region = new Rectangle<int>(tile.Item1*TileSize, tile.Item2*TileSize, TileSize, TileSize);
                        Tileset.Depth = Tiles.GetLength(2) == 1
                            ? MinDepth
                            : Maths.Lerp(MinDepth, MaxDepth, (float) k/(Tiles.GetLength(2) - 1));
                        emptyTransform.Position = new Vector2(i*TileSize, j*TileSize) - Center;
                        ServiceLocator.GraphicsService.Draw(Tileset,
                            Transform2D.Compose(emptyTransform, identity2D.CameraTransform));

                    }
                    emptyTransform.Position += new Vector2(0, TileSize);
                }
            }

            identity2D.Transform = transform;
            Tileset.Region = region;
            Tileset.Size = size;
            Tileset.Depth = depth;
        }
开发者ID:iLambda,项目名称:Freemwork,代码行数:48,代码来源:CompositeSpriteHolder.cs

示例8: Update

        public void Update(PlayState State, Worldspawn Worldspawn, GameObject Owner, int GOID)
        {
            if (CommandMap[up].Evaluate())
            {
                Owner.QueryComponent<Identity2D>().Transform.Position += new Vector2(0, -Speed);
                if (Owner.HasComponent<SpriteAnimator>() && Animate && UpAnimation != null)
                    Owner.QueryComponent<SpriteAnimator>().CurrentAnimation = UpAnimation;
            }
            if (CommandMap[down].Evaluate())
            {
                Owner.QueryComponent<Identity2D>().Transform.Position += new Vector2(0, Speed);
                if (Owner.HasComponent<SpriteAnimator>() && Animate && DownAnimation != null)
                    Owner.QueryComponent<SpriteAnimator>().CurrentAnimation = DownAnimation;
            }
            if (CommandMap[left].Evaluate())
            {
                Owner.QueryComponent<Identity2D>().Transform.Position += new Vector2(-Speed, 0);
                if (Owner.HasComponent<SpriteAnimator>() && Animate && LeftAnimation != null)
                    Owner.QueryComponent<SpriteAnimator>().CurrentAnimation = LeftAnimation;
            }
            if (CommandMap[right].Evaluate())
            {
                Owner.QueryComponent<Identity2D>().Transform.Position += new Vector2(Speed, 0);
                if (Owner.HasComponent<SpriteAnimator>() && Animate && RightAnimation != null)
                    Owner.QueryComponent<SpriteAnimator>().CurrentAnimation = RightAnimation;
            }

            var pos = Owner.QueryComponent<Identity2D>().Transform.Position;

            if(oldPosition == pos)
                if (Owner.HasComponent<SpriteAnimator>() && Animate)
                    Owner.QueryComponent<SpriteAnimator>().CurrentAnimation = null;

            if (Owner.HasComponent<SpriteOscillator>() && Bobbing)
                Owner.QueryComponent<SpriteOscillator>().Oscillate = oldPosition != pos;
            oldPosition = pos;
        }
开发者ID:iLambda,项目名称:Freemwork,代码行数:37,代码来源:BasicController2D.cs

示例9: Update

        public void Update(PlayState State, Worldspawn Worldspawn, GameObject Owner, int GOID)
        {
            var identity2D = Owner.QueryComponent<Identity2D>();
            var sprite = Owner.QueryComponent<SpriteHolder>();
            var hitbox = CustomHitbox.HasValue
                ? new Rectangle<int>((int)identity2D.CameraTransform.Position.X,
                    (int)identity2D.CameraTransform.Position.Y,
                    CustomHitbox.Value.Width,
                    CustomHitbox.Value.Height)
                : new Rectangle<int>((int)identity2D.CameraTransform.Position.X,
                    (int)identity2D.CameraTransform.Position.Y,
                    sprite.Sprite.Size.Width,
                    sprite.Sprite.Size.Height);

            var isDown = false;
            if (ServiceLocator.DeviceService.IsMouseSupported) isDown |= MouseTest(hitbox);
            if (ServiceLocator.DeviceService.IsTouchSupported) isDown |= TouchTest(hitbox);
            IsDown = isDown;

            if (IsPressedOnce && Press != null) Press(this, new VirtualButtonEventArgs { Owner = Owner, Worldspawn = Worldspawn, GOID = GOID, State = State });
            if (IsReleasedOnce && Release != null) Release(this, new VirtualButtonEventArgs { Owner = Owner, Worldspawn = Worldspawn, GOID = GOID, State = State });

            if (Animate) Owner.QueryComponent<SpriteAnimator>().CurrentAnimation = IsDown ? PressedAnimation : ReleasedAnimation;

            wasUp = IsUp;
            wasDown = IsDown;
        }
开发者ID:iLambda,项目名称:Freemwork,代码行数:27,代码来源:VirtualButton.cs

示例10: Update

        public void Update(PlayState State, Worldspawn Worldspawn, GameObject Owner, int GOID)
        {
            var sprite = Owner.QueryComponent<SpriteHolder>();

            if (CurrentAnimation == null)
            {
                sprite.Sprite.Region = Animations[lastAnimation].First();
                return;
            }

            var animation = Animations[CurrentAnimation];

            sprite.Sprite.Region = animation[i];

            j = (j + 1) % (animation.Length * (int)frameDuration);
            i = (j / (float)frameDuration).IntegerPart();
        }
开发者ID:iLambda,项目名称:Freemwork,代码行数:17,代码来源:SpriteAnimator.cs

示例11: Draw

 public void Draw(PlayState State, Worldspawn Worldspawn, GameObject Owner, int GOID)
 {
     if(Sprite != null)
         ServiceLocator.GraphicsService.Draw(Sprite, Owner.QueryComponent<Identity2D>().CameraTransform);
 }
开发者ID:iLambda,项目名称:Freemwork,代码行数:5,代码来源:SpriteHolder.cs

示例12: Update

        public void Update(PlayState State, Worldspawn Worldspawn, GameObject Owner, int GOID)
        {
            var identity = Owner.QueryComponent<Identity2D>();
            var position = identity.CameraTransform.Position;
            var rect = new Rectangle<float>(position.X - MaxRadius, position.Y - MaxRadius, MaxRadius * 2, MaxRadius * 2);

            switch (AllowedMode)
            {
                case CursorMode.Touch:
                    if (lastId == -1)
                    {
                        var touches = ServiceLocator.InputService.GetTouches().Where(To => rect.Contains(To.Position) && To.State == TouchState.Pressed).ToList();
                        if (touches.Any()) lastId = touches.First().Id;
                    }

                    if (lastId != -1)
                    {
                        var touch = ServiceLocator.InputService.GetTouches().Where(To => To.Id == lastId).ToList();
                        if (!touch.Any()) lastId = -1;

                        var vect = touch.First().Position - position;
                        if (vect.LengthSquared() > MaxRadius * MaxRadius)
                            vect *= (MaxRadius / vect.Length());

                        moverPosition = position + vect;
                        Value = vect / MaxRadius;
                    }
                    else
                    {
                        moverPosition = position;
                        Value = Vector2.Zero;
                    }
                    break;

                case CursorMode.Mouse:
                    if (!isClicked)
                        if (rect.Contains(ServiceLocator.InputService.GetMousePosition()) && ServiceLocator.InputService.IsMouseButtonDown(MouseButton.LeftButton))
                            isClicked = true;
                    if(isClicked)
                        if (ServiceLocator.InputService.IsMouseButtonUp(MouseButton.LeftButton))
                            isClicked = false;

                    if (isClicked)
                    {
                        var vect = ServiceLocator.InputService.GetMousePosition() - position;
                        if (vect.LengthSquared() > MaxRadius*MaxRadius)
                            vect *= (MaxRadius/vect.Length());

                        moverPosition = position + vect;
                        Value = vect/MaxRadius;
                    }
                    else
                    {
                        moverPosition = position;
                        Value = Vector2.Zero;
                    }

                    break;

                case CursorMode.Mouse | CursorMode.Touch:
                    if (lastId == -1 && !isClicked)
                    {
                        var touches = ServiceLocator.InputService.GetTouches().Where(To => rect.Contains(To.Position) && To.State == TouchState.Pressed).ToList();
                        if (touches.Any()) lastId = touches.First().Id;
                    }

                    if (lastId != -1)
                    {
                        isClicked = false;
                        var touch = ServiceLocator.InputService.GetTouches().Where(To => To.Id == lastId).ToList();
                        if (!touch.Any()) lastId = -1;

                        var vect = touch.First().Position - position;
                        if (vect.LengthSquared() > MaxRadius * MaxRadius)
                            vect *= (MaxRadius / vect.Length());

                        moverPosition = position + vect;
                        Value = vect / MaxRadius;
                    }
                    else
                    {
                        if (!isClicked)
                        {
                            moverPosition = position;
                            Value = Vector2.Zero;
                        }
                    }

                    if (lastId == -1)
                    {
                        if (!isClicked)
                            if (rect.Contains(ServiceLocator.InputService.GetMousePosition()) && ServiceLocator.InputService.IsMouseButtonDown(MouseButton.LeftButton))
                                isClicked = true;
                        if (isClicked)
                            if (ServiceLocator.InputService.IsMouseButtonUp(MouseButton.LeftButton))
                                isClicked = false;

                        if (isClicked)
                        {
                            var vect = ServiceLocator.InputService.GetMousePosition() - position;
//.........这里部分代码省略.........
开发者ID:iLambda,项目名称:Freemwork,代码行数:101,代码来源:VirtualJoystick.cs


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