本文整理汇总了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);
}
示例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.");
}
示例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.");
}
示例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();
}
示例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));
}
示例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);
}
示例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);
}
示例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;
}
示例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>();
}
示例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;
}
//.........这里部分代码省略.........
示例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 });
}