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


C# GameObject.AddComponent方法代码示例

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


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

示例1: ItWillBeSetToBeAPrefabIfTheGameObjectIsAPRefab

 public void ItWillBeSetToBeAPrefabIfTheGameObjectIsAPRefab()
 {
     GameObject go = new GameObject() { isPrefab = true };
     Component comp = new TestComponent();
     go.AddComponent(comp);
     Assert.That(comp.isPrefab, Is.EqualTo(go.isPrefab));
 }
开发者ID:Joelone,项目名称:FFWD,代码行数:7,代码来源:WhenAddingAComponentToAGameObject.cs

示例2: WeCanDoItWithJustItsType

 public void WeCanDoItWithJustItsType()
 {
     GameObject go = new GameObject();
     Component comp = go.AddComponent(typeof(TestComponent));
     Assert.That(comp, Is.Not.Null);
     Assert.That(comp.gameObject, Is.SameAs(go));
 }
开发者ID:Joelone,项目名称:FFWD,代码行数:7,代码来源:WhenAddingAComponentToAGameObject.cs

示例3: ItWillHaveTheGameObjectSet

 public void ItWillHaveTheGameObjectSet()
 {
     GameObject go = new GameObject();
     Component comp = new TestComponent();
     go.AddComponent(comp);
     Assert.That(comp.gameObject, Is.SameAs(go));
 }
开发者ID:Joelone,项目名称:FFWD,代码行数:7,代码来源:WhenAddingAComponentToAGameObject.cs

示例4: SetUp

		public void SetUp()
		{
			var gameObject = new GameObject();
			_rigidBody = new RigidBody();
			gameObject.AddComponent(_rigidBody);
			gameObject.AddComponent(new Transform());
		}
开发者ID:Andrea,项目名称:duality-withsvn-history,代码行数:7,代码来源:RigidBodyTests.cs

示例5: MsgShowGhost

            /** ToolbeltManager will call .SendMessage("MsgShowGhost", true/false)
             *
             */
            void MsgShowGhost(bool show)
            {
                if (this._viewpointGhost == null)
                {
                GameObject vg = GameObject.CreatePrimitive(PrimitiveType.Sphere);
                vg.transform.parent = this.gameObject.transform;
                vg.renderer.material.shader = Shader.Find ("Transparent/Diffuse");
                vg.renderer.material.SetColor("", new Color(1.0f, 1.0f, 1.0f, 0.5f));
                this._viewpointGhost = vg;
                }

                if (this._avieCylinder == null)
                {
                GameObject ac = new GameObject("Ghost Cylinder");
                ac.AddComponent<MeshRenderer>();
                ac.renderer.material.shader = Shader.Find("Transparent/Diffuse");
                ac.renderer.material.SetColor( "_Emission", new Color(1.0f, 1.0f, 1.0f, 0.2f) );

                icScreenSpaceCyli cyliScript = ac.AddComponent<icScreenSpaceCyli>();
                cyliScript.parentToCamera = false;
                cyliScript.screenSpacePosition.z = 5.0f;
                cyliScript.screenSpaceScale.x = 1.0f;
                cyliScript.screenSpaceScale.y = 1.0f;
                cyliScript.tessellationPerCircle = 60;
                cyliScript.tessellationPerY = 3;
                ac.transform.parent = this.gameObject.transform;

                this._avieCylinder = ac;
                }

                this._viewpointGhost.renderer.enabled = show;
                this._avieCylinder.renderer.enabled = show;
            }
开发者ID:rlawther,项目名称:AmnesiaMuseumUnity,代码行数:36,代码来源:CameraInterfaceExample.cs

示例6: CreateBullet

		public Bullet CreateBullet()
		{
			GameObject		obj			= new GameObject("Bullet");
			Transform		transform	= obj.AddComponent<Transform>();
			RigidBody		body		= obj.AddComponent<RigidBody>();
			SpriteRenderer	sprite		= obj.AddComponent<SpriteRenderer>();
			Bullet			bullet		= obj.AddComponent<Bullet>();

			Material spriteMaterial = this.spriteMaterial.Res ?? Material.SolidWhite.Res;
			Vector2 spriteSize = spriteMaterial.MainTexture.IsAvailable ? spriteMaterial.MainTexture.Res.Size : new Vector2(5, 5);
			float spriteRadius = MathF.Max(spriteSize.X, spriteSize.Y) * 0.25f;

			body.ClearShapes();
			CircleShapeInfo circleShape = new CircleShapeInfo(spriteRadius, Vector2.Zero, 1.0f);
			circleShape.IsSensor = true;
			body.AddShape(circleShape);
			body.CollisionCategory = CollisionCategory.Cat3;
			body.CollidesWith &= ~CollisionCategory.Cat3;

			sprite.SharedMaterial = this.spriteMaterial;
			sprite.Rect = Rect.Align(Alignment.Center, 0.0f, 0.0f, spriteSize.X * 0.5f, spriteSize.Y * 0.5f);

			bullet.InitFrom(this);

			return bullet;
		}
开发者ID:ChrisLakeZA,项目名称:duality,代码行数:26,代码来源:BulletBlueprint.cs

示例7: BuildGameObject

 public void BuildGameObject(Vector2 position)
 {
     GameObject gameObject = new GameObject();
     gameObject.AddComponent(new SpriteRenderer(gameObject, "BoxPreassurePlate", 1f));
     gameObject.Transform.Position = position;
     gameObject.AddComponent(new BoxPreassurePlate(gameObject, Color.White, name));
     gameObject.AddComponent(new Collider(gameObject));
     this.gameObject = gameObject;
 }
开发者ID:monogameproject,项目名称:WrapThat,代码行数:9,代码来源:BoxPreassurePlateBuilder.cs

示例8: BuildGameObject

 public void BuildGameObject(Vector2 position)
 {
     GameObject gameObject = new GameObject();
     gameObject.AddComponent(new SpriteRenderer(gameObject, "MoveableBox", 0.9f));
     gameObject.Transform.Position = position;
     gameObject.AddComponent(new MoveableBox(gameObject));
     gameObject.AddComponent(new Collider(gameObject));
     this.gameObject = gameObject;
 }
开发者ID:monogameproject,项目名称:WrapThat,代码行数:9,代码来源:MoveableBoxBuilder.cs

示例9: BuildGameObject

 public void BuildGameObject(Vector2 position)
 {
     GameObject gameObject = new GameObject();
     gameObject.AddComponent(new SpriteRenderer(gameObject, "DoorOne", 1f));
     gameObject.Transform.Position = new Vector2(410, 150);
     gameObject.AddComponent(new Door(gameObject, name));
     gameObject.AddComponent(new Collider(gameObject));
     this.gameObject = gameObject;
 }
开发者ID:monogameproject,项目名称:WrapThat,代码行数:9,代码来源:DoorBuilder.cs

示例10: BuildGameObject

        public void BuildGameObject(Vector2 position)
        {
            GameObject gameObject = new GameObject();
            gameObject.AddComponent(new SpriteRenderer(gameObject, "Gave", 1f));
            gameObject.Transform.Position = position;
            gameObject.AddComponent(new Collider(gameObject));
            gameObject.AddComponent(new Gift());
            this.gameObject = gameObject;

        }
开发者ID:monogameproject,项目名称:WrapThat,代码行数:10,代码来源:Gift.cs

示例11: BuildGameObject

 public void BuildGameObject(Vector2 position, string name)
 {
     this.name = name;
     GameObject gameObject = new GameObject();
     gameObject.AddComponent(new SpriteRenderer(gameObject, "PreassurePlate", 0.1f));
     gameObject.Transform.Position = position;
     gameObject.AddComponent(new PreassurePlate(gameObject, Color.White, name));
     gameObject.AddComponent(new Collider(gameObject));
     this.gameObject = gameObject;
 }
开发者ID:monogameproject,项目名称:WrapThat,代码行数:10,代码来源:PreassurePlateBuilder.cs

示例12: CreateEmptyBody

		[Test] public void CreateEmptyBody()
		{
			// Create a new RigidBody
			GameObject obj = new GameObject("Object");
			obj.AddComponent<Transform>();
			RigidBody body = obj.AddComponent<RigidBody>();

			// Expect the body to be empty
			Assert.IsTrue(body.Shapes == null || !body.Shapes.Any());
			Assert.IsTrue(body.Joints == null || !body.Joints.Any());
		}
开发者ID:ChrisLakeZA,项目名称:duality,代码行数:11,代码来源:RigidBodyTest.cs

示例13: WeWillFindTheCorrectSubType

        public void WeWillFindTheCorrectSubType()
        {
            GameObject go = new GameObject();
            go.AddComponent(typeof(TestComponent));
            go.AddComponent(typeof(MyTestComponent));

            UnityObject obj = Application.FindObjectOfType(typeof(MyTestComponent));

            Assert.That(obj, Is.Not.Null);
            Assert.That(obj, Is.TypeOf<MyTestComponent>());
        }
开发者ID:Joelone,项目名称:FFWD,代码行数:11,代码来源:WhenFindingAnObject.cs

示例14: BuildGameObject

        public void BuildGameObject(Vector2 position)
        {
            GameObject gameObject = new GameObject();
            gameObject.AddComponent(new SpriteRenderer(gameObject, "PlayerSheet", 1f));
            gameObject.Transform.Position = new Vector2(50, 50);
            gameObject.AddComponent(new Animator(gameObject));
            gameObject.AddComponent(new Player(gameObject));
            gameObject.AddComponent(new Collider(gameObject));

            this.gameObject = gameObject;

        }
开发者ID:monogameproject,项目名称:WrapThat,代码行数:12,代码来源:PlayerBuilder.cs

示例15: LevelBorderBuild

        public void LevelBorderBuild()
        {
            for (int i = 0; i < 16; i++)
            {
                GameObject gameObject = new GameObject();
                int newx = 50 * i;

                gameObject.AddComponent(new SpriteRenderer(gameObject, "Tile", 2f));
                gameObject.Transform.Position = new Vector2(-6 + newx, -6);
                gameObject.AddComponent(new Collider(gameObject));


                _levelOneObjects.Add(gameObject);
            }

            for (int i = 0; i < 9; i++)
            {
                GameObject gameObject = new GameObject();
                int newy = 50 * i;

                gameObject.AddComponent(new SpriteRenderer(gameObject, "Tile", 2f));
                gameObject.Transform.Position = new Vector2(-6, -6 + newy);
                gameObject.AddComponent(new Collider(gameObject));

                _levelOneObjects.Add(gameObject);
            }

            for (int i = 0; i < 9; i++)
            {
                GameObject gameObject = new GameObject();
                int newy = 50 * i;

                gameObject.AddComponent(new SpriteRenderer(gameObject, "Tile", 2f));
                gameObject.Transform.Position = new Vector2(750, -6 + newy);
                gameObject.AddComponent(new Collider(gameObject));


                _levelOneObjects.Add(gameObject);
            }
            for (int i = 0; i < 16; i++)
            {
                GameObject gameObject = new GameObject();
                int newx = 50 * i;

                gameObject.AddComponent(new SpriteRenderer(gameObject, "Tile", 2f));
                gameObject.Transform.Position = new Vector2(newx, 444);
                gameObject.AddComponent(new Collider(gameObject));


                _levelOneObjects.Add(gameObject);
            }
        }
开发者ID:monogameproject,项目名称:WrapThat,代码行数:52,代码来源:Level.cs


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