public MoveDirector(GameObject target, Vector2 offset, float turnAroundDelay) { _currentPath = new MovePath(); _target = target; _offset = offset; _turnAroundDelay = turnAroundDelay; }
public bool LookAt(Direction direction, float waitTime) { if (Moving || (direction == _currentPath.Direction)) { return(false); } _currentDelay = waitTime; _currentPath = DirectionToPath(direction); _target.SendMessage("OnMoveDirectionChangeStart", _currentPath, SendMessageOptions.DontRequireReceiver); return(true); }
public bool Move(MovePath newPath) { if (Moving) { _target.SendMessage("OnMoveCancel", newPath, SendMessageOptions.DontRequireReceiver); return(false); } _target.SendMessage("OnMoveBeforeStart", newPath, SendMessageOptions.DontRequireReceiver); if (newPath.Direction != _currentPath.Direction) { // Should turn around without moving return(LookAt(newPath.Direction, _turnAroundDelay)); } if (newPath.HasCollision(1)) // min hit distance = 1 tile { _target.SendMessage( "OnMoveCollide", newPath.Hit, SendMessageOptions.DontRequireReceiver ); Stop(); return(false); } if (!newPath.IsMoving()) { // Nothing to move (steps = 0 or speed = 0) _target.SendMessage("OnMoveCancel", newPath, SendMessageOptions.DontRequireReceiver); return(false); } _currentPath = newPath; _target.SendMessage("OnMoveStart", newPath, SendMessageOptions.DontRequireReceiver); return(true); }
public bool Move(Direction direction, Vector2 destination) { var path = new MovePath(_target.transform.position, new Move(direction, 0, 0), _offset, destination); return(Move(path)); }
public void OnMoveBeforeStart(MovePath path) { var direction = path.Move.GetDirectionVector(); Animation.UpdateAnimation(direction, direction, path.Move.CalculateAnimationSpeed()); }