本文整理汇总了C#中Entity.GetComponent方法的典型用法代码示例。如果您正苦于以下问题:C# Entity.GetComponent方法的具体用法?C# Entity.GetComponent怎么用?C# Entity.GetComponent使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Entity
的用法示例。
在下文中一共展示了Entity.GetComponent方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Awake
protected void Awake()
{
animator = GetComponent<Animator>();
entity = GetComponentInParent<Entity>();
agent = entity.GetComponent<NavMeshAgent>();
movement = entity.GetComponent<EntityMovement>();
}
示例2: UpdateThrusters
private void UpdateThrusters(Entity ship)
{
var shipComponent = ship.GetComponent<ShipComponent>();
var thrusters = shipComponent.Thrusters.Select(e => e.GetComponent<ThrusterComponent>());
var xform = ship.GetComponent<Transform>();
bool isShipTurning = Math.Abs(shipComponent.AngularTorque) > 0;
var isShipThrusting = shipComponent.LinearThrustVector.LengthSquared() > 0;
foreach (var thruster in thrusters)
{
if (thruster == null) continue;
bool isThrusting = false;
if (isShipThrusting)
{
var offset = Math.Abs(GetLesserAngleDifference(shipComponent.LinearThrustVector.GetAngleRadians() - MathHelper.Pi / 2f, thruster.Part.Transform.Rotation));
isThrusting = offset < 1;
}
if (isShipTurning)
{
var rotateDir = (AngularDirection)Math.Sign(shipComponent.AngularTorque);
//isThrusting = rotateDir == thruster.RotateDir;
isThrusting |= thruster.GetAngularThrustMult(rotateDir, Vector2.Zero) > 0;
}
thruster.IsThrusting = isThrusting;
if (isThrusting)
thruster.ThrustPercentage = MathHelper.Clamp(thruster.ThrustPercentage + 0.05f, 0, 1);
else
thruster.ThrustPercentage = MathHelper.Clamp(thruster.ThrustPercentage - 0.05f, 0, 1);
}
}
示例3: ClosestTarget
public Body ClosestTarget(Entity e)
{
AI a = e.GetComponent<AI>();
PhysicsBody pb = world.GetClosestBody(e.GetComponent<ITransform>().Position, a.HostileGroup);
Body b = new Body(world, pb.UserData as Entity);
return b;
}
示例4: Attach
public void Attach(Entity newMaster)
{
master = newMaster;
master.OnShutdown += master_OnShutdown;
master.GetComponent<TransformComponent>(ComponentFamily.Transform).OnMove += HandleOnMasterMove;
Translate(master.GetComponent<TransformComponent>(ComponentFamily.Transform).Position);
}
示例5: ProcessEntity
protected override void ProcessEntity(Engine engine, Entity entity)
{
// 2 per 1000 milliseconds
var amountPerSecond = 2;
var people = entity.GetComponent<PeopleComponent>().Value;
entity.GetComponent<GoldComponent>().Value += (engine.DeltaMs * amountPerSecond / 1000.0) * people;
}
示例6: Process
public override void Process(Entity entity, float dt)
{
var physics = entity.GetComponent<PhysicsComponent>();
var render = entity.GetComponent<RenderComponent>();
render.RenderPosition = physics.Position;
}
示例7: Process
public override void Process(Entity e)
{
Moving moving = e.GetComponent<Moving>();
Transform spatial = e.GetComponent<Transform>();
spatial.Position += moving.Velocity * EntityWorld.Delta / 10000000;
moving.Velocity += moving.Acceleration * EntityWorld.Delta / 10000000;
}
示例8: Process
public override void Process(Entity e)
{
Acting acting = e.GetComponent<Acting>();
if (acting.State != ActingState.SkillSelection)
return;
InputControlled inputControlled = e.GetComponent<InputControlled>();
if (String.IsNullOrEmpty(acting.SkillSelected.Name))
{
inputControlled.SkillMenu.Draw();
}
else
{
int count = acting.PossibleTargets.Count;
if (count > 0)
{
if (inputControlled.IsTargetingGroup)
{
foreach (Entity entity in acting.PossibleTargets)
{
if (entity.GetComponent<Transform>() != null)
{
Vector2 position = new Vector2(entity.GetComponent<Transform>().Center.X, entity.GetComponent<Transform>().Y - 10);
_spriteBatch.Draw(arrowTargeted, position, Color.White);
}
}
}
else
{
Entity TargetedEntity = acting.PossibleTargets[inputControlled.TargetIndex];
foreach (Entity entity in acting.PossibleTargets)
{
if (entity.GetComponent<Transform>() != null)
{
Vector2 position = new Vector2(entity.GetComponent<Transform>().Center.X, entity.GetComponent<Transform>().Y - 10);
if (entity == TargetedEntity)
{
_spriteBatch.Draw(arrowTargeted, position, Color.White);
}
else
{
_spriteBatch.Draw(arrowCanBeTargeted, position, Color.White);
}
}
}
}
}
else
{
foreach (Entity entity in acting.Targets)
{
if (entity.GetComponent<Transform>() != null)
{
Vector2 position = new Vector2(entity.GetComponent<Transform>().Center.X, entity.GetComponent<Transform>().Y - 10);
_spriteBatch.Draw(arrowTargeted, position, Color.White);
}
}
}
}
}
示例9: Process
public override void Process(Entity e)
{
if(e.GetComponent<Health>()!=null)
e.GetComponent<Health>().AddDamage(10);
if (e.GetComponent<Power2>() != null)
e.GetComponent<Power2>().POWER -=10;
}
示例10: PlaceItem
private void PlaceItem(Entity actor, Entity item)
{
var rnd = new Random();
actor.SendMessage(this, ComponentMessageType.DropItemInCurrentHand);
item.GetComponent<SpriteComponent>(ComponentFamily.Renderable).drawDepth = DrawDepth.ItemsOnTables;
//TODO Unsafe, fix.
item.GetComponent<TransformComponent>(ComponentFamily.Transform).TranslateByOffset(
new Vector2(rnd.Next(-28, 28), rnd.Next(-28, 15)));
}
示例11: DamageTarget
public static void DamageTarget(Entity user, Entity target, int damage, double hitSuccess = 1)
{
EntityCreator.CreateDamageInfo(target, damage, hitSuccess);
BattleStats stats = target.GetComponent<BattleStats>();
stats.Health.Decrease(damage);
if (stats.IsDead && !target.GetComponent<Group>().IsHero)
{
target.Delete();
}
}
示例12: 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;
}
示例13: 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;
}
示例14: Process
public override void Process (Entity entity)
{
var transform = entity.GetComponent<Transform>();
var renderer = entity.GetComponent<Texture2DRenderer>();
var spriteBatch = BlackBoard.GetEntry<SpriteBatch>("SpriteBatch");
var texture = BlackBoard.GetEntry<ContentManager>("ContentManager").Load<Texture2D>(renderer.TextureName);
spriteBatch.Draw(texture, transform.renderPosition, null, null, transform.globalOrigin, transform.renderRotation, transform.renderScale);
}
示例15: 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;
}