コード例 #1
0
ファイル: MoveDirector.cs プロジェクト: smallant/newbark
 public MoveDirector(GameObject target, Vector2 offset, float turnAroundDelay)
 {
     _currentPath     = new MovePath();
     _target          = target;
     _offset          = offset;
     _turnAroundDelay = turnAroundDelay;
 }
コード例 #2
0
ファイル: MoveDirector.cs プロジェクト: smallant/newbark
        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);
        }
コード例 #3
0
ファイル: MoveDirector.cs プロジェクト: smallant/newbark
        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);
        }
コード例 #4
0
ファイル: MoveDirector.cs プロジェクト: smallant/newbark
        public bool Move(Direction direction, Vector2 destination)
        {
            var path = new MovePath(_target.transform.position, new Move(direction, 0, 0), _offset, destination);

            return(Move(path));
        }
コード例 #5
0
        public void OnMoveBeforeStart(MovePath path)
        {
            var direction = path.Move.GetDirectionVector();

            Animation.UpdateAnimation(direction, direction, path.Move.CalculateAnimationSpeed());
        }