Пример #1
0
 public static void OnMovementFinishedInvoke(object sender = null)
 {
     if (OnMovementFinished != null)
     {
         OnMovementFinished.Invoke(null, EventArgs.Empty);
     }
 }
Пример #2
0
 private void MovementFinished(Cell newCell, bool updateAdjacentCells = true)
 {
     _unit.CurrentCell = newCell;
     OnMovementFinished?.Invoke();
     if (updateAdjacentCells)
     {
         UpdateAdjacentCells();
     }
 }
Пример #3
0
 public void Update()
 {
     if (shouldMove)
     {
         if ((target.position - transform.position).sqrMagnitude > squaredTerminationDistance)
         {
             transform.position =
                 Vector3.MoveTowards(transform.position, target.position, Time.deltaTime * moveSpeed);
         }
         else
         {
             shouldMove = false;
             OnMovementFinished?.Invoke();
         }
     }
 }
Пример #4
0
    IEnumerator SpinRoutine()
    {
        // local z forward
        Vector3 localForward = new Vector3(0f, 0f, Board.spacing);

        // the destination will always be one space directly behind
        destination = transform.TransformVector(localForward * -1f) + transform.position;

        // rotate 180 degrees
        FaceDestination();

        // wait until the end of the the rotation
        yield return(new WaitForSeconds(rotateTime));

        // broadcast the end of movement
        OnMovementFinished.Invoke();
    }
Пример #5
0
    IEnumerator PatrolRoutine()
    {
        // starting position cached
        Vector3 startPos = new Vector3(m_currentNode.Coordinate.x, 0f,
                                       m_currentNode.Coordinate.y);

        // one space ahead
        Vector3 newDest = startPos + transform.TransformVector(directionToMove);

        // two spaces ahead
        Vector3 nextDest = startPos + transform.TransformVector(directionToMove * 2f);

        // get to the new destination
        Move(newDest, 0f);

        // wait until movement has completed
        while (isMoving)
        {
            yield return(null);
        }

        // check for a dead end
        if (m_board != null)
        {
            // destination node
            Node newDestNode = m_board.FindNodeAt(newDest);

            // node two spaces away
            Node nextDestNode = m_board.FindNodeAt(nextDest);

            // if the Node two spaces away doesn't exist OR isn't connected to the destination Node
            if (nextDestNode == null || !newDestNode.LinkedNodes.Contains(nextDestNode))
            {
                // turn and face the original node and set it as the new destination
                destination = startPos;
                FaceDestination();

                // wait for rotation to end
                yield return(new WaitForSeconds(rotateTime));
            }
        }

        // broadcast the end of movement
        OnMovementFinished.Invoke();
    }