本文整理汇总了C#中Entity.AddComponent方法的典型用法代码示例。如果您正苦于以下问题:C# Entity.AddComponent方法的具体用法?C# Entity.AddComponent怎么用?C# Entity.AddComponent使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Entity
的用法示例。
在下文中一共展示了Entity.AddComponent方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Initialize
public override void Initialize()
{
this.RegisterSystems();
FPSCamera camera = new FPSCamera(new Vector3(0f, 0f, 0f), Vector3.Zero,
Blackboard.Get<GraphicsDevice>("GraphicsDevice").Viewport.AspectRatio, 0.05f, 100f);
Entity fpscounter = new Entity();
fpscounter.AddComponent(new Transform2DComponent() { Position = new Vector2(5, 150) });
fpscounter.AddComponent(new FPSCounterComponent());
fpscounter.AddComponent(new GUITextComponent());
Entity pos = new Entity();
pos.AddComponent(new PositionalTrackingComponent() { Target = camera.Get<Transform3DComponent>() });
pos.AddComponent(new GUITextComponent());
pos.AddComponent(new Transform2DComponent() { Position = new Vector2(5, 180) });
Entity model = new Entity();
model.AddComponent(new Transform3DComponent(new Vector3(0f, -1f, 2f)));
model.Get<Transform3DComponent>().Rotation = new Vector3(0f, MathHelper.PiOver2, 3f*MathHelper.PiOver2);
Model m = Blackboard.Get<ContentManager>("ContentManager").Load<Model>("dragon");
model.AddComponent(new ModelComponent() { Model = m });
this.AddEntity(model);
this.AddEntity(pos);
this.AddEntity(fpscounter);
this.AddEntity(camera);
}
示例2: BuildEntity
public Entity BuildEntity(Entity e, params object[] args)
{
e.Tag = "Chassis";
#region Body
Body Chassis = e.AddComponent<Body>(new Body(_World, e));
{
Vertices vertices = new Vertices(8);
vertices.Add(new Vector2(-2.5f, 0.08f));
vertices.Add(new Vector2(-2.375f, -0.46f));
vertices.Add(new Vector2(-0.58f, -0.92f));
vertices.Add(new Vector2(0.46f, -0.92f));
vertices.Add(new Vector2(2.5f, -0.17f));
vertices.Add(new Vector2(2.5f, 0.205f));
vertices.Add(new Vector2(2.3f, 0.33f));
vertices.Add(new Vector2(-2.25f, 0.35f));
PolygonShape chassisShape = new PolygonShape(vertices, 2f);
Chassis.BodyType = BodyType.Dynamic;
Chassis.Position = new Vector2(0.0f, -1.0f);
Chassis.CreateFixture(chassisShape);
}
#endregion
#region Sprite
e.AddComponent<Sprite>(new Sprite(args[0] as Texture2D, (Rectangle)args[1],
Chassis, 1, Color.White, 0f));
#endregion
return e;
}
示例3: Before
public void Before() {
var pool = Helper.CreatePool();
_e = pool.CreateEntity();
_e.AddComponent(CP.ComponentA, new ComponentA());
_e.AddComponent(CP.ComponentB, new ComponentB());
_e.AddComponent(CP.ComponentC, new ComponentC());
}
示例4: BuildEntity
public Entity BuildEntity(Entity entity, EntityWorld entityWorld, params object[] args)
{
var shipDef = Game.WorldConfiguration.Ships[args[0] as string];
entity.AddComponent(new ModelComponent(shipDef.Model));
entity.AddComponent(new SceneGraphNode());
entity.AddComponent(shipDef);
return entity;
}
示例5: Before
public void Before()
{
var context = Helper.CreateContext();
_e = context.CreateEntity();
_e.AddComponent(CP.ComponentA, new ComponentA());
_e.AddComponent(CP.ComponentB, new ComponentB());
_e.AddComponent(CP.ComponentC, new ComponentC());
}
示例6: BuildEntity
public Entity BuildEntity(Entity e)
{
e.Group = "EFFECTS";
e.AddComponent(new Transform());
e.AddComponent(new SpatialForm());
e.AddComponent(new Expires());
e.GetComponent<SpatialForm>().SpatialFormFile = "BulletExplosion";
e.GetComponent<Expires>().LifeTime = 1000;
return e;
}
示例7: BuildEntity
public Entity BuildEntity(Entity e, EntityWorld world, params object[] args)
{
e.Group = "EFFECTS";
e.AddComponentFromPool<Transform>();
e.AddComponent(new SpatialForm());
e.AddComponent(new Expires());
e.GetComponent<SpatialForm>().SpatialFormFile = "ShipExplosion";
e.GetComponent<Expires>().LifeTime = 1000;
return e;
}
示例8: BuildEntity
public Entity BuildEntity(Entity e)
{
e.Group = "BULLETS";
e.AddComponent(new Transform());
e.AddComponent(new SpatialForm());
e.AddComponent(new Velocity());
e.AddComponent(new Expires());
e.GetComponent<SpatialForm>().SpatialFormFile = "Missile";
e.GetComponent<Expires>().LifeTime = 2000;
return e;
}
示例9: InitTestEntities
private static void InitTestEntities()
{
var e = new Entity("player");
//e.Transform.Scale = new Vector2(0.5f, 0.5f);
e.AddComponent(new SpriteComponent(e, Engine.Textures["crate"]));
//e.AddComponent(new PlayerInput(e));
e.AddComponent(new RectCollider(e) {Width = 96, Height = 96});
e.AddComponent(new RectRenderer(e, Rectangle.Empty, new Texture2D(Engine.Window.GraphicsDevice, 1, 1)));
Engine.Entities.AddEntity(e);
}
示例10: BuildEntity
public Entity BuildEntity(Entity e, EntityWorld world, params object[] args)
{
e.Group = "BULLETS";
e.AddComponentFromPool<Transform>();
e.AddComponent(new SpatialForm());
e.AddComponent(new Velocity());
e.AddComponent(new Expires());
e.GetComponent<SpatialForm>().SpatialFormFile = "Missile";
e.GetComponent<Expires>().LifeTime = 2000;
return e;
}
示例11: BuildEntity
public Entity BuildEntity(Entity e, EntityWorld world, params object[] args)
{
e.Group = "SHIPS";
e.AddComponentFromPool<Transform>();
e.AddComponent(new SpatialForm());
e.AddComponent(new Health());
e.AddComponent(new Weapon());
e.AddComponent(new Enemy());
e.AddComponent(new Velocity());
e.GetComponent<SpatialForm>().SpatialFormFile = "EnemyShip";
e.GetComponent<Health>().HP = 10;
return e;
}
示例12: Before
public void Before()
{
_context = Helper.CreateContext();
_context.GetGroup(Matcher.AllOf(new [] { CP.ComponentA }));
_e = _context.CreateEntity();
_e.AddComponent(CP.ComponentA, new ComponentA());
}
示例13: Before
public void Before() {
_pool = new Pool(CP.NumComponents);
_pool.GetGroup(Matcher.AllOf(new [] { CP.ComponentA }));
_pool.GetGroup(Matcher.AllOf(new [] { CP.ComponentB }));
_pool.GetGroup(Matcher.AllOf(new [] { CP.ComponentC }));
_pool.GetGroup(Matcher.AllOf(new [] {
CP.ComponentA,
CP.ComponentB
}));
_pool.GetGroup(Matcher.AllOf(new [] {
CP.ComponentA,
CP.ComponentC
}));
_pool.GetGroup(Matcher.AllOf(new [] {
CP.ComponentB,
CP.ComponentC
}));
_pool.GetGroup(Matcher.AllOf(new [] {
CP.ComponentA,
CP.ComponentB,
CP.ComponentC
}));
_e = new Entity(CP.NumComponents);
_e.AddComponent(CP.ComponentA, new ComponentA());
}
示例14: Before
public void Before() {
_pool = Helper.CreatePool();
_pool.GetGroup(Matcher.AllOf(new [] { CP.ComponentA }));
_pool.GetGroup(Matcher.AllOf(new [] { CP.ComponentB }));
_pool.GetGroup(Matcher.AllOf(new [] { CP.ComponentC }));
_pool.GetGroup(Matcher.AllOf(new [] {
CP.ComponentA,
CP.ComponentB
}));
_pool.GetGroup(Matcher.AllOf(new [] {
CP.ComponentA,
CP.ComponentC
}));
_pool.GetGroup(Matcher.AllOf(new [] {
CP.ComponentB,
CP.ComponentC
}));
_pool.GetGroup(Matcher.AllOf(new [] {
CP.ComponentA,
CP.ComponentB,
CP.ComponentC
}));
_e = _pool.CreateEntity();
_componentA = new ComponentA();
_e.AddComponent(CP.ComponentA, _componentA);
}
示例15: OnAdded
public override void OnAdded(Entity entity)
{
if (entity.HasComponent<ShipComponent>())
{
entity.AddComponent(new SpatialTokenComponent { Token = Ships.AllocateToken(entity) });
}
}