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


C# GameObject.Add方法代码示例

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


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

示例1: BattlefieldScene

        /// <summary>
        /// Constructor of BattlefieldScene class
        /// </summary>
        public BattlefieldScene()
        {
            for (int i = 0; i < SimultaneousSoldier; i++)
            {
                GameObject soldier = new GameObject();
                soldier.Add(new HealthComponent());
                soldier.Add(new ShieldComponent());

                _gameObjectsPool.Push(soldier);
            }

            _mediator.RegisterListener(EventTypeConstant.DeathEvent, this); // Register a listener for a specific event
            _mediator.RegisterListener(EventTypeConstant.ShowMessageEvent, this);
        }
开发者ID:Julien-Pires,项目名称:Pulsar.Demo,代码行数:17,代码来源:BattlefieldScene.cs

示例2: GameObjectComponentAttachmentValidators

        public void GameObjectComponentAttachmentValidators()
        {
            GameObject gameObject = new GameObject(new Transform());
            gameObject.Add(new Transform());

            Assert.AreEqual(1, gameObject.Count, "Count was not one, as it should've been as adding another transform shouldn't be possible.");
        }
开发者ID:ScianGames,项目名称:Engine,代码行数:7,代码来源:GameObjectTest.cs

示例3: GameObjectComponentAttachment

        public void GameObjectComponentAttachment()
        {
            GameObject gameObject = new GameObject(new Transform());
            gameObject.Add(new CoroutineController());

            Assert.AreEqual(2, gameObject.Count, "The count was not two, so the item was not added properly.");
        }
开发者ID:ScianGames,项目名称:Engine,代码行数:7,代码来源:GameObjectTest.cs

示例4: LoadContent

        protected override void LoadContent()
        {
            spriteBatch = new SpriteBatch(GraphicsDevice);
            model = Content.Load<Model>("Models/Sphere");
            foreach (ModelMesh mesh in model.Meshes)
                foreach (BasicEffect effect in mesh.Effects)
                    effect.EnableDefaultLighting();

            cameraObject = new GameObject();
            cameraObject.Transform.LocalPosition = Vector3.Backward * 20;
            camera = cameraObject.Add<Camera>();

            boxCollider = new BoxCollider();
            boxCollider.Size = 10;
            AddSphere();
        }
开发者ID:ravikamath,项目名称:CPI311,代码行数:16,代码来源:Lab06.cs

示例5: LoadContent

        protected override void LoadContent()
        {
            spriteBatch = new SpriteBatch(GraphicsDevice);
            font = Content.Load<SpriteFont>("Fonts/Georgia");
            model = Content.Load<Model>("Models/Sphere");
            foreach (ModelMesh mesh in model.Meshes)
                foreach (BasicEffect effect in mesh.Effects)
                    effect.EnableDefaultLighting();

            cameraObject = new GameObject();
            cameraObject.Transform.LocalPosition = Vector3.Backward * 20;
            camera = cameraObject.Add<Camera>();

            boxCollider = new BoxCollider();
            boxCollider.Size = 10;
            AddSphere();

            haveThreadRunning = true;
            ThreadPool.QueueUserWorkItem(
                new WaitCallback(CollisionReset));
        }
开发者ID:ravikamath,项目名称:CPI311,代码行数:21,代码来源:Lab07.cs

示例6: AddSphere

 private void AddSphere()
 {
     GameObject gameObject = new GameObject();
     Rigidbody rigidbody = gameObject.Add<Rigidbody>();
     rigidbody.Mass = 1;
     //rigidbody.Acceleration = Vector3.Down * 9.81f;
     //rigidbody.Velocity = new Vector3((float)random.NextDouble() * 5, (float)random.NextDouble() * 5, (float)random.NextDouble() * 5);
     Vector3 direction = new Vector3((float)random.NextDouble(), (float)random.NextDouble(), (float)random.NextDouble());
     direction.Normalize();
     rigidbody.Velocity = direction * ((float)random.NextDouble() * 5 + 5);
     SphereCollider sphereCollider = gameObject.Add<SphereCollider>();
     sphereCollider.Radius = gameObject.Transform.LocalScale.Y;
     objects.Add(gameObject);
     colliders.Add(sphereCollider);
     rigidbodies.Add(rigidbody);
 }
开发者ID:ravikamath,项目名称:CPI311,代码行数:16,代码来源:Lab07.cs

示例7: LisaaAliNelio

 void LisaaAliNelio(GameObject palikka, double sivulle, double alas)
 {
     var nelio = new GameObject(PalikanKoko-2, PalikanKoko-2);
     nelio.Color = palikka.Color;
     nelio.Position = new Vector(sivulle * PalikanKoko, alas * PalikanKoko);
     palikka.Add(nelio);
 }
开发者ID:juherask,项目名称:sejypeli,代码行数:7,代码来源:JyTetris.cs

示例8: Create

 /// <summary>
 /// Creates a new GameObject with a CurvySplineGroup
 /// </summary>
 /// <param name="splines">the splines to add to the group</param>
 /// <returns>the new CurvySplineGroup component</returns>
 public static CurvySplineGroup Create(params CurvySpline[] splines)
 {
     CurvySplineGroup grp = new GameObject("Curvy Spline Group", typeof(CurvySplineGroup)).GetComponent<CurvySplineGroup>();
     grp.Add(splines);
     return grp;
 }
开发者ID:shaunvxc,项目名称:Infamy,代码行数:11,代码来源:CurvySplineGroup.cs

示例9: LoadContent

        protected override void LoadContent()
        {
            spriteBatch = new SpriteBatch(GraphicsDevice);
            plane = Content.Load<Model>("Models/Plane");
            sphere = Content.Load<Model>("Models/Sphere");

            GameObject gameObject = new GameObject();
            gameObject.Transform.LocalPosition = Vector3.One * 50;
            gameObject.Transform.Rotate(Vector3.Right, -MathHelper.PiOver2);
            camera = gameObject.Add<Camera>();
        }
开发者ID:ravikamath,项目名称:CPI311,代码行数:11,代码来源:Lab09.cs

示例10: ReloadScene

        void ReloadScene(Device device)
        {
            bool gameRunning = false;

            if (_map != null)
            {
                gameRunning = true;
                _map.Dispose();
            }

            string[] mapContent = File.ReadAllLines(_mapFile);
            _mapModifyDate = File.GetLastWriteTime(_mapFile);

            _map = Add(new GameObject());

            var y = mapContent.Length;
            for (var l = 0; l < mapContent.Length; l++)
            {
                var line = mapContent[l];
                for (int x = 0; x < line.Length; x++)
                {
                    var c = line[x];
                    string blockTexture = null;

                    switch (c)
                    {
                        case 'm':
                        case 'M':
                            if (_player == null || _oldStartPos != new Vector3(x, y, 0))
                            {
                                if (_player == null)
                                {
                                    _player = (Mario)Add(new Mario(device));
                                    var deathController = _player.SearchComponent<MainPlayerDeath>();
                                    GameObject dummyCameraTarget = null;
                                    deathController.OnDeathStarted += delegate
                                    {
                                        dummyCameraTarget = Add(new GameObject());
                                        dummyCameraTarget.Translate(_player.GlobalTransform.TranslationVector);
                                        _camera.SearchComponent<LookAtObject>().Target = dummyCameraTarget;
                                    };
                                    deathController.OnDeathFinalized += delegate
                                    {
                                        if (dummyCameraTarget != null)
                                        {
                                            dummyCameraTarget.Dispose();
                                            dummyCameraTarget = null;
                                        }
                                        _camera.SearchComponent<LookAtObject>().Target = _player;
                                        deathController.Reset();
                                        ReloadScene(device);
                                        _player.Enabled = true;
                                        _player.Transform = Matrix.Translation(_oldStartPos.X, _oldStartPos.Y + 0.5f, 0);
                                        _player.SearchComponent<RigidBody>().Momentum = Vector3.Zero;
                                        _player.SearchComponent<Blink>().IsActive = true;
                                        _camera.Transform = _player.Transform * Matrix.Translation(0, 0, -15);
                                    };
                                }

                                _player.Transform = Matrix.Translation(x, y + 0.5f, 0);
                                _oldStartPos = new Vector3(x, y, 0);
                            }
                            _player.IsSmall = c == 'm';
                            break;

                        case 'G':
                            _map.Add(new Goomba(device)).Translate(x, y, 0);
                            break;

                        case '?':
                            _map.Add(new ItemBlock(device)).Translate(x, y, 0);
                            break;

                        case 'B':
                            _map.Add(new BrickBlock(device)).Translate(x, y, 0);
                            break;

                        case 'P':
                            {
                                if (l > 0 && mapContent[l - 1].Length > x && mapContent[l - 1][x] == c)
                                    break;
                                var height = 1;
                                while (l + height < mapContent.Length && mapContent[l + height][x] == c)
                                    height++;

                                _map.Add(new Pipe(device, height)).Translate(x, y - (float)(height - 1) / 2, 0);
                                break;
                            }

                        case '|':
                            {
                                if (l > 0 && mapContent[l - 1].Length > x && mapContent[l - 1][x] == c)
                                    break;
                                var height = 1;
                                while (l + height < mapContent.Length && mapContent[l + height][x] == c)
                                    height++;

                                _map.Add(new Poll(device, height)).Translate(x, y - (float)(height - 1) / 2, 0);
                                break;
                            }
//.........这里部分代码省略.........
开发者ID:jvlppm,项目名称:pucpr-dx-cube_mario,代码行数:101,代码来源:Level.cs

示例11: CreateBody

        void CreateBody(Device device, Texture texture)
        {
            _sizeContainer = Add(new GameObject());

            // Container vai ser rotacionado no plano xz para olhar na direção do movimento
            var container = _sizeContainer.Add(new GameObject {
                (_collider = new Components.AxisAlignedBoxCollider { Object = this })
                //new Behaviors.LookForward()
            });

            // Body container poderá rotacionar no seu eixo X, sem que a direção seja impactada
            var bodyContainer = container.Add(new GameObject());
            //.add(Behaviors.RotateWhileJumping, { speed: 6 });
            bodyContainer.Translate(0, 0.1f, 0);

            _body = bodyContainer.Add(new GameObject());
            _body.Translate(0, -0.5f - bodyContainer.Transform.TranslationVector.Y, 0);

            var xAxis = new Vector3(1, 0, 0);

            AddHead(device, texture);
            AddCap(device, texture);
            AddChest(device, texture);
            AddArm(device, texture, new Vector3(-0.35f, 0.05f, 0f))
                .Add(new SwingWhileMoving(xAxis) { Inverse = true });
            AddArm(device, texture, new Vector3(0.35f, 0.05f, 0f))
                .Add(new SwingWhileMoving(xAxis));
            AddLeg(device, texture, new Vector3(-0.125f, -0.35f, 0f))
                .Add(new SwingWhileMoving(xAxis));
            AddLeg(device, texture, new Vector3(0.125f, -0.35f, 0f))
                .Add(new SwingWhileMoving(xAxis) { Inverse = true });
        }
开发者ID:jvlppm,项目名称:pucpr-dx-cube_mario,代码行数:32,代码来源:Mario.cs


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