本文整理汇总了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));
}
示例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));
}
示例3: ItWillHaveTheGameObjectSet
public void ItWillHaveTheGameObjectSet()
{
GameObject go = new GameObject();
Component comp = new TestComponent();
go.AddComponent(comp);
Assert.That(comp.gameObject, Is.SameAs(go));
}
示例4: SetUp
public void SetUp()
{
var gameObject = new GameObject();
_rigidBody = new RigidBody();
gameObject.AddComponent(_rigidBody);
gameObject.AddComponent(new Transform());
}
示例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;
}
示例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;
}
示例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;
}
示例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;
}
示例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;
}
示例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;
}
示例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;
}
示例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());
}
示例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>());
}
示例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;
}
示例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);
}
}