本文整理汇总了C#中Direction.ToVector方法的典型用法代码示例。如果您正苦于以下问题:C# Direction.ToVector方法的具体用法?C# Direction.ToVector怎么用?C# Direction.ToVector使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Direction
的用法示例。
在下文中一共展示了Direction.ToVector方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Fire
public void Fire(StaticItem source, World world, FiringState firingState, Direction direction)
{
if (direction == Direction.None)
throw new ArgumentOutOfRangeException("direction");
if (firingState != FiringState.Pulse || source.Energy < 4)
return;
var startPos = source.TilePosition.ToPosition();
var shot = new StandardShot(world, startPos, direction, source.Energy >> 2, ShotType.Player);
if (!shot.CanMoveInDirection(direction))
return;
startPos += direction.ToVector() * Tile.Size / 2;
shot.SetPosition(startPos);
world.AddShot(shot);
world.Game.SoundPlayer.Play(GameSound.PlayerShoots);
_countOfShotsBeforeCostingEnergy--;
if (_countOfShotsBeforeCostingEnergy < 0)
{
_countOfShotsBeforeCostingEnergy = 3;
source.ReduceEnergy(1);
}
}
示例2: ArmAttack
void ArmAttack(Direction hitDirection)
{
var upIsBusy = Arms[Direction.Up][0].renderer.enabled || Arms[Direction.Up][1].renderer.enabled;
var downIsBusy = Arms[Direction.Down][0].renderer.enabled || Arms[Direction.Down][1].renderer.enabled;
Direction armHeight;
if (upIsBusy && downIsBusy) armHeight = Direction.None;
else if (!upIsBusy && !downIsBusy) armHeight = Direction.Down;
else if (upIsBusy) armHeight = Direction.Down;
else /* if (downIsBusy) */ armHeight = Direction.Up;
if (armHeight != Direction.None)
{
var armToUse = Arms[armHeight][hitDirection == Direction.Left ? 0 : 1];
if (armToUse.renderer.enabled) return;
var hitVector = Quaternion.AngleAxis(-transform.localRotation.eulerAngles.z, Vector3.forward) * hitDirection.ToVector();
var offset = new Vector3(0, armToUse.transform.localPosition.y, 0);
var impulse = ComputeForce(hitVector, offset);
DoHitFx(-transform.localRotation.eulerAngles.z + (hitDirection == Direction.Left ? 90 : -90), hitVector, offset);
rigidbody.AddForce(-hitVector * impulse, ForceMode.Impulse);
armToUse.renderer.enabled = true;
var initialOffset = new Vector3(hitDirection.ToVector().x * -1, 0, 0);
var origin = armToUse.transform.localPosition;
armToUse.transform.localPosition = origin + initialOffset;
Wait.Until(elapsed =>
{
var step = Easing.EaseOut(1 - Mathf.Clamp01(elapsed / Cooldown), EasingType.Cubic);
armToUse.transform.localPosition = origin + initialOffset * step;
return step == 0;
},
() => { armToUse.renderer.enabled = false; });
}
}
示例3: GetNext
/// <summary>
/// Returns the adjacent square in the given direction. If there is no
/// square in that direction (edge of the grid), this will return null.
/// </summary>
public IGridSquare GetNext(Direction direction)
{
Vector2 vec = new Vector2(x,y);
vec += direction.ToVector();
return grid.TryGet((int)vec.x, (int)vec.y);
}