/// <summary>
        /// Asks the object to move to the specified position, via a set of waypoints
        /// </summary>
        /// <param name="position">The position to move to.</param>
        /// <param name="via">A list of waypoints to visit along the route to position.</param>
        public void MoveTo(Vector3 position, IEnumerable <Vector3> via)
        {
            if (_blockMoveOrders)
            {
                return;
            }

            var from = _isPortaling ? _currentDestination.position : _transform.position;

            //Either we don't have a request or this is the first point in a way point route
            StopInternal();

            var firstWaypoint = position;

            if (via != null && via.Any())
            {
                firstWaypoint = via.First();
                _wayPoints.AddWaypoint(firstWaypoint, true);

                foreach (var wp in via.Skip(1))
                {
                    _wayPoints.AddWaypoint(wp);
                }

                _wayPoints.AddWaypoint(position);
            }
            else
            {
                _wayPoints.AddWaypoint(firstWaypoint, true);
            }

            _lastNavigationEvent = UnitNavigationEventMessage.Event.None;
            RequestPath(from, firstWaypoint, InternalPathRequest.Type.Normal);
        }
        private void SetManualPath(Path path, ReplanCallback onReplan)
        {
            if (path == null || path.count == 0)
            {
                StopInternal();
                return;
            }

            _stop         = false;
            _stopped      = false;
            _arrivalEvent = UnitNavigationEventMessage.Event.DestinationReached;
            _manualReplan = onReplan;

            int pathCount = path.count - 1;

            for (int i = 0; i < pathCount; i++)
            {
                var node = path[i];
                if (node is Waypoint)
                {
                    _wayPoints.AddWaypoint(node.position);
                }
            }

            _wayPoints.AddWaypoint(path.Last().position, true);

            SetPath(path, false);

            _lastPathRequestTime = Time.time;
        }
示例#3
0
        private bool ProcessAndValidateResult(PathResult result)
        {
            for (int i = 0; i < _resultProcessors.Length; i++)
            {
                if (_resultProcessors[i].HandleResult(result, this))
                {
                    return(result.status == PathingStatus.Complete);
                }
            }

            UnitNavigationEventMessage.Event msgEvent = UnitNavigationEventMessage.Event.None;

            switch (result.status)
            {
            case PathingStatus.Complete:
            {
                /* All is good, no more to do */
                return(true);
            }

            case PathingStatus.NoRouteExists:
            case PathingStatus.StartOutsideGrid:
            case PathingStatus.EndOutsideGrid:
            {
                msgEvent = UnitNavigationEventMessage.Event.StoppedNoRouteExists;
                break;
            }

            case PathingStatus.DestinationBlocked:
            {
                msgEvent = UnitNavigationEventMessage.Event.StoppedDestinationBlocked;
                break;
            }

            case PathingStatus.Decayed:
            {
                //We cannot reissue the request here, since we may be on a different thread, but then again why would we issue the request again if it had a decay threshold its no longer valid.
                msgEvent = UnitNavigationEventMessage.Event.StoppedRequestDecayed;
                break;
            }

            case PathingStatus.Failed:
            {
                Debug.LogError("Path request failed: " + result.errorInfo);
                break;
            }
            }

            var destination      = result.originalRequest.to;
            var pendingWaypoints = _wayPoints.count > 0 ? _wayPoints.ToArray() : Consts.EmptyVectorArray;

            StopInternal();

            if (msgEvent != UnitNavigationEventMessage.Event.None)
            {
                AnnounceEvent(msgEvent, destination, pendingWaypoints);
            }

            return(false);
        }
示例#4
0
 /// <summary>
 /// Announce a UnitNavigationEventMessage event.
 /// </summary>
 /// <param name="e">The event to announce.</param>
 /// <param name="destination">The current destination.</param>
 /// <param name="pendingWaypoints">The pending waypoints.</param>
 public void AnnounceEvent(UnitNavigationEventMessage.Event e, Vector3 destination, Vector3[] pendingWaypoints)
 {
     _navMessage.isHandled        = false;
     _navMessage.eventCode        = e;
     _navMessage.destination      = destination;
     _navMessage.pendingWaypoints = pendingWaypoints ?? Consts.EmptyVectorArray;
     GameServices.messageBus.Post(_navMessage);
 }
        /// <summary>
        /// Asks the object to move along the specified path.
        /// </summary>
        /// <param name="path">The path.</param>
        /// <param name="onReplan">The callback to call when replanning is needed.</param>
        public void MoveAlong(Path path, ReplanCallback onReplan)
        {
            Ensure.ArgumentNotNull(path, "path");

            StopInternal();

            _lastNavigationEvent = UnitNavigationEventMessage.Event.None;
            SetManualPath(path, onReplan);
        }
        private void AnnounceEvent(UnitNavigationEventMessage.Event e, Vector3 destination, Vector3[] pendingWaypoints)
        {
            _lastNavigationEvent = e;

            _navMessage.isHandled        = false;
            _navMessage.eventCode        = e;
            _navMessage.destination      = destination;
            _navMessage.pendingWaypoints = pendingWaypoints ?? Empty <Vector3> .array;
            GameServices.messageBus.Post(_navMessage);
        }
        /// <summary>
        /// Asks the object to move to the specified position
        /// </summary>
        /// <param name="position">The position to move to.</param>
        /// <param name="append">if set to <c>true</c> the destination is added as a way point.</param>
        public void MoveTo(Vector3 position, bool append)
        {
            if (_blockMoveOrders)
            {
                return;
            }

            //If this is a way point and we are already moving, just queue it up
            if (append && !_stopped)
            {
                _wayPoints.AddWaypoint(position);
                return;
            }

            var from = _isPortaling ? _currentDestination.position : _transform.position;

            //Either we don't have a request or this is the first point in a way point route
            StopInternal();

            _wayPoints.AddWaypoint(position, true);
            _lastNavigationEvent = UnitNavigationEventMessage.Event.None;
            RequestPath(from, position, InternalPathRequest.Type.Normal);
        }
        private bool ProcessAndValidateResult(PathResult result, bool isWaypoint)
        {
            _wayPoints.frozen = false;

            for (int i = 0; i < _resultProcessors.Length; i++)
            {
                if (_resultProcessors[i].HandleResult(result, this))
                {
                    return(result.status == PathingStatus.Complete);
                }
            }

            var  status    = result.status;
            bool isPartial = (status == PathingStatus.CompletePartial);

            if (isPartial)
            {
                status = result.innerResult.status;
            }

            switch (status)
            {
            case PathingStatus.Complete:
            {
                /* All is good, no more to do */
                _arrivalEvent = UnitNavigationEventMessage.Event.DestinationReached;
                return(true);
            }

            case PathingStatus.NoRouteExists:
            case PathingStatus.EndOutsideGrid:
            {
                _arrivalEvent = UnitNavigationEventMessage.Event.StoppedNoRouteExists;
                break;
            }

            case PathingStatus.StartOutsideGrid:
            {
                _arrivalEvent = UnitNavigationEventMessage.Event.StoppedUnitOutsideGrid;
                break;
            }

            case PathingStatus.DestinationBlocked:
            {
                _arrivalEvent = UnitNavigationEventMessage.Event.StoppedDestinationBlocked;
                break;
            }

            case PathingStatus.Decayed:
            {
                //We cannot reissue the request here, since we may be on a different thread, but then again why would we issue the request again if it had a decay threshold its no longer valid.
                _arrivalEvent = UnitNavigationEventMessage.Event.StoppedRequestDecayed;
                break;
            }

            case PathingStatus.Failed:
            {
                StopInternal();
                Debug.LogError("Path request failed: " + result.errorInfo);
                break;
            }
            }

            _wayPoints.frozen = true;

            if (isPartial)
            {
                return(true);
            }

            if (!isWaypoint)
            {
                //If we are not already moving stop and announce here
                StopAndAnnounceArrival();
            }

            return(false);
        }
 /// <summary>
 /// Stop following the path.
 /// </summary>
 public override void Stop()
 {
     _lastNavigationEvent = UnitNavigationEventMessage.Event.StoppedByRequest;
     _stop = true;
 }
        private bool ProcessAndValidateResult(PathResult result, bool isWaypoint)
        {
            _wayPoints.frozen = false;

            for (int i = 0; i < _resultProcessors.Length; i++)
            {
                if (_resultProcessors[i].HandleResult(result, this))
                {
                    return (result.status == PathingStatus.Complete);
                }
            }

            var status = result.status;
            bool isPartial = (status == PathingStatus.CompletePartial);
            if (isPartial)
            {
                status = result.innerResult.status;
            }

            switch (status)
            {
                case PathingStatus.Complete:
                {
                    /* All is good, no more to do */
                    _arrivalEvent = UnitNavigationEventMessage.Event.DestinationReached;
                    return true;
                }

                case PathingStatus.NoRouteExists:
                case PathingStatus.EndOutsideGrid:
                {
                    _arrivalEvent = UnitNavigationEventMessage.Event.StoppedNoRouteExists;
                    break;
                }

                case PathingStatus.StartOutsideGrid:
                {
                    _arrivalEvent = UnitNavigationEventMessage.Event.StoppedUnitOutsideGrid;
                    break;
                }

                case PathingStatus.DestinationBlocked:
                {
                    _arrivalEvent = UnitNavigationEventMessage.Event.StoppedDestinationBlocked;
                    break;
                }

                case PathingStatus.Decayed:
                {
                    //We cannot reissue the request here, since we may be on a different thread, but then again why would we issue the request again if it had a decay threshold its no longer valid.
                    _arrivalEvent = UnitNavigationEventMessage.Event.StoppedRequestDecayed;
                    break;
                }

                case PathingStatus.Failed:
                {
                    StopInternal();
                    Debug.LogError("Path request failed: " + result.errorInfo);
                    break;
                }
            }

            _wayPoints.frozen = true;

            if (isPartial)
            {
                return true;
            }

            if (!isWaypoint)
            {
                //If we are not already moving stop and announce here
                StopAndAnnounceArrival();
            }

            return false;
        }
        private void SetManualPath(Path path, ReplanCallback onReplan)
        {
            if (path == null || path.count == 0)
            {
                StopInternal();
                return;
            }

            _stop = false;
            _stopped = false;
            _arrivalEvent = UnitNavigationEventMessage.Event.DestinationReached;
            _manualReplan = onReplan;

            int pathCount = path.count - 1;
            for (int i = 0; i < pathCount; i++)
            {
                var node = path[i];
                if (node is Waypoint)
                {
                    _wayPoints.AddWaypoint(node.position);
                }
            }

            _wayPoints.AddWaypoint(path.Last().position, true);

            SetPath(path, false);

            _lastPathRequestTime = Time.time;
        }