本文整理汇总了C#中System.Entity.AddComponent方法的典型用法代码示例。如果您正苦于以下问题:C# Entity.AddComponent方法的具体用法?C# Entity.AddComponent怎么用?C# Entity.AddComponent使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Entity
的用法示例。
在下文中一共展示了Entity.AddComponent方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: BuildEntity
/// <summary>
/// Builds a bullet entity.
/// </summary>
/// <param name="e">The entity to build.</param>
/// <param name="args">[0] = ITransform; [1] = IVelocity; [2] = Sprite; [3] = Bullet </param>
/// <returns></returns>
public Entity BuildEntity(Entity e, params object[] args)
{
e.Group = "Bullets";
//Set up defaults
IVelocity velocity = _DefaultVelocity;
Sprite sprite = _DefaultSprite;
ITransform transform = new Transform(Vector2.Zero, 0.0f);
Bullet bullet = _DefaultBullet;
//Check arguments.
if (args != null)
{
if (args.Length > 0)
transform = (args[0] as ITransform);
if (args.Length > 1)
velocity = (args[1] as IVelocity);
if (args.Length > 2)
sprite = (Sprite)args[2];
if (args.Length > 3)
bullet = (Bullet)args[3];
}
//Make the velocity proportional to the default velocity and the target rotation
e.AddComponent<Particle>(new Particle(e, transform.Position, transform.Rotation,
velocity.LinearVelocity * new Vector2((float)Math.Cos(transform.Rotation),
(float)Math.Sin(transform.Rotation)),
velocity.AngularVelocity));
e.AddComponent<Sprite>(sprite);
e.AddComponent<Bullet>(bullet);
return e;
}
示例2: LoadModel
private Entity LoadModel(string model, string texture, Entity parent, bool isAdditive)
{
Entity entity = new Entity(model)
.AddComponent(new Model(string.Format(PATHMODELS, model)))
.AddComponent(new Transform3D())
.AddComponent(new ModelRenderer());
if (!isAdditive)
{
entity.AddComponent(new MaterialsMap(new BasicMaterial(string.Format(PATHMATERIAL, texture), typeof(CustomLayer) )));
}
else
{
entity.AddComponent(new MaterialsMap(new BasicMaterial(string.Format(PATHMATERIAL, texture), DefaultLayers.Additive)
{
DiffuseColor = new Color(0.6f, 0.6f, 0.6f)
}));
}
if (parent == null)
{
EntityManager.Add(entity);
}
else
{
parent.AddChild(entity);
}
return entity;
}
示例3: BuildEntity
/// <summary>
///
/// </summary>
/// <param name="e"></param>
/// <param name="args">args[0] = bool bigStar</param>
/// <returns></returns>
public Entity BuildEntity(Entity e, params object[] args)
{
e.Group = "Stars";
e.Tag = "Star" + stars.ToString();
++stars;
#region Sprite
if (args.Length == 0)
{
Vector2 loc = new Vector2(rbitch.Next(-ScreenHelper.Viewport.Width / 2, ScreenHelper.Viewport.Width / 2), rbitch.Next(-ScreenHelper.Viewport.Width / 2, ScreenHelper.Viewport.Width / 2));
Sprite s = new Sprite(spriteSheet, "redstar", 0f);
s.FrameIndex = rbitch.Next(0, 3);
s.Scale = (float)rbitch.NextDouble();
e.AddComponent<Sprite>(s);
Animation a = e.AddComponent<Animation>(new Animation(AnimationType.Bounce, 5));
Particle p = e.AddComponent<Particle>(new Particle(e, ConvertUnits.ToSimUnits(loc), (float)Math.Atan2(loc.Y, loc.X), Vector2.Zero, (float)rbitch.Next(-3, 3) * 0.01f));
}
else
{
Vector2 loc = Vector2.Zero;
Sprite s = new Sprite(spriteSheet, "nebula", 0f);
e.AddComponent<Sprite>(s);
Particle p = e.AddComponent<Particle>(new Particle(e, ConvertUnits.ToSimUnits(loc), 0f, Vector2.Zero, 0f));
}
#endregion Sprite
return e;
}
示例4: CreateScene
protected override void CreateScene()
{
//WaveServices.ScreenLayers.AddScene<GameScene>()
// .Apply("FromMultiplayer");
var Map_Bitmaps = new Entity("Whole_Map_global");
RenderManager.BackgroundColor = Color.CornflowerBlue;
Level_Classes.LevelManager Level1 = new Level_Classes.LevelManager();
var Mob_set = new Entity("juest_Player");
Map_Bitmaps.AddComponent(Level1);
Map_Bitmaps.AddComponent(Level1.Level);
EntityManager.Add(Level1.BaseMobEntity);
EntityManager.Add(Level1.BaseTowerEntity);
EntityManager.Add(Mob_set);
EntityManager.Add(Level1.Level.Map_Bitmaps);
EntityManager.Add(Map_Bitmaps);
EntityManager.Add(Level1.TowersBar);
EntityManager.Add(Level1.MonsterCounter);
EntityManager.Add(Level1.MoneyCounter);
EntityManager.Add(Level1.TimerCounter);
EntityManager.Add(Level1.ScreenLayout);
}
示例5: BuildEntity
public Entity BuildEntity(Entity entity, params object[] args)
{
entity.AddComponent<TransformComponent>();
entity.AddComponent<PaddleComponent>();
entity.AddComponent<PlayerInputComponent>();
return entity;
}
示例6: Body
public Body(EntityWorld world, Entity e)
: base(world, e)
{
//Add transform and velocity
e.AddComponent<ITransform>(this);
e.AddComponent<IVelocity>(this);
e.AddComponent<IDamping>(this);
}
示例7: BuildEntity
public Entity BuildEntity(Entity entity, params object[] args)
{
entity.AddComponent<TransformComponent>();
entity.AddComponent<BallComponent>();
entity.AddComponent<BallMovementComponent>();
return entity;
}
示例8: AllComponentsAreAddedWhenEntityIsAdded
public void AllComponentsAreAddedWhenEntityIsAdded()
{
var entity0 = new Entity(new VariableCollection());
entity0.AddComponent<FakeComp>();
entity0.AddComponent<FakeBehaviour>();
collection.Add(entity0);
}
示例9: CreatePointer
public void CreatePointer(Entity myStartingNode, Vector2 myOffset,Texture2D myTexture)
{
SpriteComponent sprite = myStartingNode.GetDrawable("SpriteComponent") as SpriteComponent;
pointerEntity = new Entity(1, State.ScreenState.WORLD_MAP);
pointerEntity.AddComponent(new SpriteComponent(true, sprite.position + myOffset, myTexture));
pointerEntity.AddComponent(new PointerComponent(myOffset));
EntityManager.AddEntity(pointerEntity);
}
示例10: CreateNode
public void CreateNode(string myLevelName, string myLevelID, Vector2 myPosition, List<string> myConnectedTo, NodeState myNodeState, Texture2D myTexture)
{
Entity nodeEntity = new Entity(5, State.ScreenState.WORLD_MAP);
nodeEntity.AddComponent(new SpriteComponent(true, myPosition, myTexture));
nodeEntity.AddComponent(new ClickableComponent(myPosition,myTexture.Width,myTexture.Height));
nodeEntity.AddComponent(new NodeComponent(myLevelName, myLevelID, myNodeState, myConnectedTo));
AddNode(nodeEntity);
EntityManager.AddEntity(nodeEntity);
}
示例11: MakeCard
public static Entity MakeCard(int cardID, string statsName)
{
Entity ret = new Entity();
ret.AddComponent(new Position(0,0,1));
ret.AddComponent(new BoundingRectangle(-cardSize.x / 2, -cardSize.y / 2, cardSize.x / 2, cardSize.y / 2));
ret.AddComponent(new CardType(ret, cardID, statsName));
return ret;
}
示例12: createBulletTemplate
private Entity createBulletTemplate(Game game)
{
Entity bullet = new Entity();
//Component: Damage entities.
DamageOnContactComponent damage = new DamageOnContactComponent();
damage.Damage = 1;
bullet.AddComponent(damage);
//Component: Has health. Used to simulate destruction on contact with an entity
HealthComponent health = new HealthComponent();
health.Health = 1;
bullet.AddComponent(health);
//Component: Has a texture
TextureComponent tex = new TextureComponent();
tex.Texture = game.Content.Load<Texture2D>("spaceArt/png/laserGreen");
tex.SourceRect = tex.Texture.Bounds;
bullet.AddComponent(tex);
//Component: Moves linearly
LinearMovementComponent movement = new LinearMovementComponent();
bullet.AddComponent(movement);
//Component: Moves at constant speed
MoveSpeedComponent speed = new MoveSpeedComponent();
speed.MoveSpeed = 18;
bullet.AddComponent(speed);
//Component: Has a bounding box
AABBComponent aabb = new AABBComponent();
aabb.Height = tex.SourceRect.Height;
aabb.Width = tex.SourceRect.Width;
bullet.AddComponent(aabb);
//Component: Is rendered at a specific layer - just above the enemies
RenderLayerComponent layer = new RenderLayerComponent();
layer.LayerID = 12;
bullet.AddComponent(layer);
//Component: Is destroyed when it ventures off the (right side of the) screen
DestroyedWhenOffScreenComponent destroyer = new DestroyedWhenOffScreenComponent();
bullet.AddComponent(destroyer);
//Component: Is destroyed when it runs out of health
DestroyedWhenNoHealthComponent destroyer2 = new DestroyedWhenNoHealthComponent();
bullet.AddComponent(destroyer2);
//Component: Plays a laser sound
SoundEffectComponent soundEffect = new SoundEffectComponent();
soundEffect.effect = game.Content.Load<SoundEffect>("sound/39459__the-bizniss__laser");
bullet.AddComponent(soundEffect);
return bullet;
}
示例13: Particle
public Particle(Entity e, Vector2 position, float rotation, Vector2 linearVelocity, float angularVelocity)
{
e.AddComponent<ITransform>(this);
e.AddComponent<IVelocity>(this);
e.AddComponent<IDamping>(this);
this.Position = position;
this.Rotation = rotation;
this.LinearVelocity = linearVelocity;
this.AngularVelocity = angularVelocity;
this.LinearDamping = 0.0f;
this.AngularDamping = 0.0f;
}
示例14: LevelEnd
public static Entity LevelEnd(int x, int y)
{
var entity = new Entity();
entity.Transform.Origin = new Vector2f(TILE_SIZE / 2f, TILE_SIZE / 2f);
entity.Transform.Position = new Vector2f(x * TILE_SIZE, y * TILE_SIZE);
var hitbox = new FloatRect(0, 0, TILE_SIZE, TILE_SIZE);
var colider = new ColiderComponent(hitbox);
var end = new LevelEnd();
entity.AddComponent(colider);
entity.AddComponent(end);
return entity;
}
示例15: BuildEntity
/// <summary>
///
/// </summary>
/// <param name="e"></param>
/// <param name="args">args[0] = Entity smasher, args[1] = Smasher loc</param>
/// <returns></returns>
public Entity BuildEntity(Entity e, params object[] args)
{
string spriteKey = "smasherball";
#region Body
Body bitch = e.AddComponent<Body>(new Body(_World, e));
FixtureFactory.AttachEllipse(ConvertUnits.ToSimUnits(_SpriteSheet[spriteKey][0].Width / 2), ConvertUnits.ToSimUnits(_SpriteSheet[spriteKey][0].Height / 2), 20, 1f, bitch);
Sprite s = new Sprite(_SpriteSheet, spriteKey, bitch, 1f, Color.White, 0.5f);
e.AddComponent<Sprite>(s);
bitch.BodyType = GameLibrary.Dependencies.Physics.Dynamics.BodyType.Dynamic;
bitch.CollisionCategories = GameLibrary.Dependencies.Physics.Dynamics.Category.Cat2 | GameLibrary.Dependencies.Physics.Dynamics.Category.Cat1;
bitch.CollidesWith = GameLibrary.Dependencies.Physics.Dynamics.Category.Cat6 | GameLibrary.Dependencies.Physics.Dynamics.Category.Cat1;
bitch.OnCollision += LambdaComplex.BossCollision();
++bitch.Mass;
Entity smasher = (args[0] as Entity);
float dist = ConvertUnits.ToSimUnits(20f);
Vector2 pos = smasher.GetComponent<Body>().Position + new Vector2(0, dist);
bitch.Position = pos;
#endregion Body
#region Animation
if (s.Source.Count() > 1)
e.AddComponent<Animation>(new Animation(AnimationType.Bounce, 10));
#endregion Animation
#region Health
e.AddComponent<Health>(new Health(1000000)).OnDeath +=
ent =>
{
Vector2 poss = e.GetComponent<ITransform>().Position;
_World.CreateEntityGroup("BigExplosion", "Explosions", poss, 10, e, e.GetComponent<IVelocity>().LinearVelocity);
int splodeSound = rbitch.Next(1, 5);
SoundManager.Play("Explosion" + splodeSound.ToString());
};
#endregion Health
e.AddComponent<Origin>(new Origin(smasher));
e.Group = "Enemies";
e.Tag = "SmasherBall";
return e;
}