Example #1
0
        public bool Move(Rectangle area, float distance, object data, OnMovementFinished onMovementFinished, OnMovementCancelled onMovementCancelled)
        {
            AbortCurrentMovement();

            this.data = data;
            this.onMovementFinished  = onMovementFinished;
            this.onMovementCancelled = onMovementCancelled;

            if (area.Contains(representable.getPosition(), 0))
            {
                if (onMovementFinished != null)
                {
                    onMovementFinished(data);
                }
                return(true);
            }

            var accesible = TrajectoryHandler.GetAccessibleTrajectory(representable.getPosition(), FindObjectOfType <SceneMB>().Trajectory);

            Vector2[] intersections;
            if (TrajectoryHandler.TrajectoryRectangleIntersections(area, accesible, out intersections))
            {
                var route = accesible.route(representable.getPosition(), intersections);
                if (route != null && route.Length > 0)
                {
                    toArea         = area;
                    distanceToArea = distance;
                    MoveRoute(route);
                    return(true);
                }
            }
            return(false);
        }
Example #2
0
        public bool MoveFreely(Vector2 point, object data, OnMovementFinished onMovementFinished, OnMovementCancelled onMovementCancelled)
        {
            AbortCurrentMovement();

            this.data = data;
            this.onMovementFinished  = onMovementFinished;
            this.onMovementCancelled = onMovementCancelled;

            MovementPoint[] route =
            {
                new MovementPoint()
                {
                    destination = point,
                    distance    = (this.representable.getPosition() - origin).magnitude,
                    scale       = this.representable.Context.getScale()
                }
            };

            if (route != null && route.Length > 0)
            {
                toArea = null;
                MoveRoute(route);
                return(true);
            }
            return(false);
        }
Example #3
0
 public static void OnMovementFinishedInvoke(object sender = null)
 {
     if (OnMovementFinished != null)
     {
         OnMovementFinished.Invoke(null, EventArgs.Empty);
     }
 }
Example #4
0
 private void MovementFinished(Cell newCell, bool updateAdjacentCells = true)
 {
     _unit.CurrentCell = newCell;
     OnMovementFinished?.Invoke();
     if (updateAdjacentCells)
     {
         UpdateAdjacentCells();
     }
 }
Example #5
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();
         }
     }
 }
Example #6
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();
    }
Example #7
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();
    }
Example #8
0
        public bool Move(Vector2 point, object data, OnMovementFinished onMovementFinished, OnMovementCancelled onMovementCancelled)
        {
            AbortCurrentMovement();

            this.data = data;
            this.onMovementFinished  = onMovementFinished;
            this.onMovementCancelled = onMovementCancelled;

            var accesible = TrajectoryHandler.GetAccessibleTrajectory(representable.getPosition(), FindObjectOfType <SceneMB>().Trajectory);
            var route     = accesible.route(representable.getPosition(), point);

            if (route != null && route.Length > 0)
            {
                toArea = null;
                MoveRoute(route);
                return(true);
            }
            return(false);
        }
Example #9
0
        // Private movement management methods

        private void AbortCurrentMovement()
        {
            toArea = null;
            if (moving)
            {
                representable.Play("stand");
                // Clear the main variables
                moving   = false;
                progress = 0.0f;
                moves.Clear();
                // Notify the chidls
                if (onMovementCancelled != null)
                {
                    onMovementCancelled(data);
                }

                onMovementCancelled = null;
                onMovementFinished  = null;
                data = null;
            }
        }