Ejemplo n.º 1
0
        /// <summary>
        /// Attempts to find a <see cref="Path"/> between the start and end points and returns the result on completion.
        /// </summary>
        /// <param name="start">The <see cref="Index"/> into the search space representing the start position</param>
        /// <param name="end">The <see cref="Index"/> into the search space representing the end position</param>
        /// <param name="diagonal">The diagonal mode used when finding paths</param>
        /// <returns>The <see cref="Path"/> that was found or null if the algorithm failed</returns>
        public Path findPathImmediate(Index start, Index end, DiagonalMode diagonal)
        {
            PathRequestStatus status = PathRequestStatus.InvalidIndex;

            // Call through
            return(findPathImmediate(start, end, out status, diagonal));
        }
Ejemplo n.º 2
0
 //
 public void RequestPath(Node _StartNode, Node _TargetNode, MovementCommand _MovCom)
 {
     if (CurrentPathStatus == PathRequestStatus.NoneRequested)
     {
         CurrentPathStatus = PathRequestStatus.RequestedAndWaiting;
         PathFinderManager.Instance.RequestPathFromNodes(_StartNode, _TargetNode, _MovCom);
     }
 }
Ejemplo n.º 3
0
 //
 public void RequestRandomPath()
 {
     if (CurrentPathStatus != PathRequestStatus.RequestedAndWaiting)
     {
         ResetPathing();
         CurrentPathStatus = PathRequestStatus.RequestedAndWaiting;
         //PathFinderManager.Instance.RequestRandomPathFromVec3(transform.position, ThisGCM);
     }
 }
Ejemplo n.º 4
0
 //
 public void RequestPath(Node _StartNode, Node _TargetNode, GunCrewMember _GCM, bool _SkipDiagnals)
 {
     if (CurrentPathStatus == PathRequestStatus.NoneRequested)
     {
         ResetPathing();
         CurrentPathStatus = PathRequestStatus.RequestedAndWaiting;
         //PathFinderManager.Instance.RequestPathFromNodes(_StartNode, _TargetNode, _GCM);
     }
 }
Ejemplo n.º 5
0
        public void SetPath(PotentialField completedPath, PathRequestStatus status)
        {
            switch (status)
            {
            case PathRequestStatus.Solved:
                var arrays = completedPath.PotentialArray.Arrays.Append(DynamicPotentialFieldComponent.PotentialField.Array);
                _path = new PotentialField(DynamicPotentialFieldComponent.PotentialField.GridTransformer, completedPath.TargetNode, arrays);
                break;

            case PathRequestStatus.NoPathFound:
                _path = new PotentialField(DynamicPotentialFieldComponent.PotentialField.GridTransformer, completedPath.TargetNode, DynamicPotentialFieldComponent.PotentialField.Array);
                break;
            }
        }
Ejemplo n.º 6
0
        /// <summary>
        /// Called by AStar2D when the algorithm has completed the request.
        /// Note that the methods can private or public.
        /// </summary>
        /// <param name="path"></param>
        /// <param name="status"></param>
        private void onPathFound(Path path, PathRequestStatus status)
        {
            // Check if the path contains any nodes. Typically this will only be true if the path has not yet been initialized or if a pathfinding request failed.
            if (path.IsEmpty == true)
            {
                Debug.Log("The path is empty path");
            }

            // Check if the path is reachable. A path is defined as reachable when the following conditions are true:
            //      The path contains one or more nodes.
            //      Every node within the path is walkable.
            if (path.IsReachable == true)
            {
                Debug.Log("The path is reachable");
            }
        }
Ejemplo n.º 7
0
 //
 public void RecivePathRequest(PathRequest _CPR)
 {
     if (_CPR.PathIsFound == false)
     {
         CurrentPathStatus = PathRequestStatus.NoneRequested;
         StartCoroutine(Wait(0.25f));
         RequestPath(_CPR.StartingNode, _CPR.TargetNode, _CPR.Requestee);
     }
     else
     {
         WayPoints             = _CPR.CompletedPath;
         CurrentWaypoint       = WayPoints[0];
         CurrentPathStatus     = PathRequestStatus.RecivedAndValid;
         CurrentMovementStatus = MovementStatus.MovingToNextWapoint;
     }
 }
Ejemplo n.º 8
0
        public void FindPath(Index start, Index end, DiagonalMode diagonal, BaseTraversal2D traversal2D, PathRequestDelegate callback)
        {
            if (!IsValid(start) || !IsValid(end))
            {
                return;
            }
            searchGrid.maxPathLength = maxPathLength;
            bool useThreading = allowThreading;

            if (useThreading == true)
            {
                AsyncPathRequest request = new AsyncPathRequest(searchGrid, start, end, diagonal, traversal2D, (Path path, PathRequestStatus status) =>
                {
                    PathView.setRenderPath(this, path);
                    callback(path, status);
                });
                ThreadManager.Active.asyncRequest(request);
            }
            else
            {
                PathRequestStatus status;
                Path result = FindPathImmediate(start, end, out status, diagonal);
                PathView.setRenderPath(this, result);
                callback(result, status);
            }

            Path FindPathImmediate(Index subStart, Index subEnd, out PathRequestStatus subStatus, DiagonalMode subDiagonal)
            {
                searchGrid.maxPathLength = maxPathLength;
                Path path = null;
                PathRequestStatus temp = PathRequestStatus.InvalidIndex;

                searchGrid.FindPath(subStart, subEnd, subDiagonal, traversal2D, (Path result, PathRequestStatus resultStatus) =>
                {
                    temp = resultStatus;
                    if (resultStatus == PathRequestStatus.PathFound)
                    {
                        path = result;
                        PathView.setRenderPath(this, path);
                    }
                });

                subStatus = temp;
                return(path);
            }
        }
Ejemplo n.º 9
0
        private void onPathFound(Path path, PathRequestStatus status)
        {
            if (status == PathRequestStatus.PathFound)
            {
                // Cache the path and change state
                this.path   = path;
                this.target = path.getNextNode();

                // Check if we are at the starting node - if so then skip
                if (currentIndex == target.Index)
                {
                    this.target = path.getNextNode();
                }

                changeState(AgentState.FollowingPath);
            }
            else if (status == PathRequestStatus.SameStartEnd)
            {
                // Make sure the agent moves to the current location (The agent may have already started moving away)
                Path temp = new Path();
                temp.push(searchGrid[currentIndex.X, currentIndex.Y], currentIndex);

                // Cache the path and change state
                this.path   = temp;
                this.target = temp.getNextNode();

                changeState(AgentState.FollowingPath);
            }
            else if (status == PathRequestStatus.PathNotFound)
            {
                // Trigger the message
                onDestinationUnreachable();

                // Go back to idle mode
                changeState(AgentState.Idle);
            }
            else
            {
                // Go back to idle mode
                changeState(AgentState.Idle);
            }
        }
Ejemplo n.º 10
0
        private void onPathFound(Path path, PathRequestStatus status)
        {
            if (status == PathRequestStatus.PathFound)
            {
                // Create the path session
                this.session = new PathSession(path);

                // Check if we are at the starting node - if so then skip
                if (currentIndex == session.Index)
                {
                    // Skip the starting node
                    session.advancePath();
                }

                changeState(AgentState.FollowingPath);
            }
            else if (status == PathRequestStatus.SameStartEnd)
            {
                // Make sure the agent moves to the current location (The agent may have already started moving away)
                Path temp = new Path(null);
                temp.push(searchGrid[currentIndex.X, currentIndex.Y], currentIndex);

                // Change state
                changeState(AgentState.FollowingPath);
            }
            else if (status == PathRequestStatus.PathNotFound)
            {
                // Trigger the message
                onDestinationUnreachable();

                // Go back to idle mode
                changeState(AgentState.Idle);
            }
            else
            {
                // Go back to idle mode
                changeState(AgentState.Idle);
            }
        }
Ejemplo n.º 11
0
 private void OnPathFound(Path path, PathRequestStatus status)
 {
     if (status == PathRequestStatus.PathFound)
     {
         this.Session = new PathSession(path);
         OnMoveStart();
         DoAdvanceNode();
         ChangeState(AgentState.FollowingPath);
     }
     else if (status == PathRequestStatus.SameStartEnd)
     {
         ChangeState(AgentState.Idle);
         OnSameStartEnd();
     }
     else if (status == PathRequestStatus.PathNotFound)
     {
         OnMoveUnreachable();
         ChangeState(AgentState.Idle);
     }
     else
     {
         ChangeState(AgentState.Idle);
     }
 }
Ejemplo n.º 12
0
        /// <summary>
        /// Attempts to find a <see cref="Path"/> between the start and end points and returns the result on completion.
        /// </summary>
        /// <param name="start">The <see cref="Index"/> into the search space representing the start position</param>
        /// <param name="end">The <see cref="Index"/> into the search space representing the end position</param>
        /// <param name="status">The <see cref="PathRequestStatus"/> describing the state of the result</param>
        /// <param name="diagonal">The diagonal mode used when finding a path</param>
        /// <returns>The <see cref="Path"/> that was found or null if the algorithm failed</returns>
        public Path findPathImmediate(Index start, Index end, out PathRequestStatus status, DiagonalMode diagonal)
        {
            // Make sure the grid is ready
            if (verifyReady() == false)
            {
                status = PathRequestStatus.GridNotReady;
                return(null);
            }

            // Update max path length
            searchGrid.maxPathLength = maxPathLength;

            // Store a temp path
            Path path = null;
            PathRequestStatus temp = PathRequestStatus.InvalidIndex;

            // Find a path
            searchGrid.findPath(start, end, diagonal, (Path result, PathRequestStatus resultStatus) =>
            {
                // Store the status
                temp = resultStatus;

                // Make sure the path was found
                if (resultStatus == PathRequestStatus.PathFound)
                {
                    path = result;

#if UNITY_EDITOR
                    PathView.setRenderPath(this, path);
#endif
                }
            });

            status = temp;
            return(path);
        }
Ejemplo n.º 13
0
 /// <summary>
 /// Attempts to find a <see cref="Path"/> between the start and end points and returns the result on completion.
 /// </summary>
 /// <param name="start">The <see cref="Index"/> into the search space representing the start position</param>
 /// <param name="end">The <see cref="Index"/> into the search space representing the end position</param>
 /// <param name="status">The <see cref="PathRequestStatus"/> describing the state of the result</param>
 /// <param name="diagonal">The diagonal mode used when finding paths</param>
 /// <returns>The <see cref="Path"/> that was found or null if the algorithm failed</returns>
 public abstract Path findPathImmediate(Index start, Index end, out PathRequestStatus status, DiagonalMode diagonal);
Ejemplo n.º 14
0
 // Constructor
 /// <summary>
 /// Parameter constructor.
 /// </summary>
 /// <param name="path">The resulting path</param>
 /// <param name="status">The status of the request</param>
 public MonoDelegateEvent(Path path, PathRequestStatus status)
 {
     this.path   = path;
     this.status = status;
 }
Ejemplo n.º 15
0
 //
 public void RecivePathRequest(List <Node> _NodePath)
 {
     WayPoints         = _NodePath;
     CurrentPathStatus = PathRequestStatus.Recived;
     //Debug.Log(gameObject.name + " Recived a Path! It is " + WayPoints.Count + " Nodes Long");
 }
Ejemplo n.º 16
0
        public void MoveAlongPath()
        {
            if (WayPoints == null)
            {
                return;
            }
            CurrentPathStatus = PathRequestStatus.NoneRequested;

            //if (CurrentMovementStatus == MovementStatus.Idle && CurrentWaypoint != null)
            //    CurrentMovementStatus = MovementStatus.MovingToNextWapoint;

            switch (CurrentMovementStatus)
            {
            case MovementStatus.Null:
                ThisRB.velocity = Vector3.zero;
                break;

            case MovementStatus.Idle:
                ThisRB.velocity = Vector3.zero;
                break;

            case MovementStatus.MovingToNextWapoint:

                CheckForWayPointExistance();
                float CurrentDisFromWaypoint = Vector3.Distance(transform.position, CurrentWaypoint.WorldPosition);
                if (CurrentDisFromWaypoint < 0.3f)
                {
                    if (CurrentWaypoint == TargetWaypoint)
                    {
                        CurrentMovementStatus = MovementStatus.ArrivedAtTargetNode;
                        ThisGCM.OccupiedNode  = CurrentWaypoint;
                        return;
                    }

                    ++CurrentWaypointIndex;
                    if (WayPoints[CurrentWaypointIndex] != null)
                    {
                        CurrentWaypoint       = WayPoints[CurrentWaypointIndex];
                        ThisGCM.OccupiedNode  = CurrentWaypoint;
                        CurrentMovementStatus = MovementStatus.MovingToNextWapoint;
                    }
                }

                else
                {
                    //THIS LOOK AT SHOULD BE 50% of the Collider height for the Y
                    Vector3 LookAtTarget = new Vector3(CurrentWaypoint.WorldPosition.x, 0.25f, CurrentWaypoint.WorldPosition.z);

                    float   step      = RotationSpeed * Time.deltaTime;
                    Vector3 targetDir = LookAtTarget - transform.position;
                    RotationToNextWaypoint = targetDir;
                    Vector3 newDir = Vector3.RotateTowards(transform.forward, targetDir, step, 0.0f);
                    transform.rotation = Quaternion.LookRotation(newDir);
                    ThisRB.velocity    = transform.forward * Speed;
                }
                break;

            case MovementStatus.ArrivedAtWaypoint:

                break;

            case MovementStatus.ArrivedAtTargetNode:
                ThisRB.velocity      = Vector3.zero;
                transform.rotation   = Quaternion.Euler(transform.forward);
                WayPoints            = null;
                CurrentWaypointIndex = 0;
                ThisGCM.OccupiedNode = CurrentWaypoint;
                //RequestRandomPath();
                CurrentMovementStatus = MovementStatus.Idle;
                break;
            }
        }
Ejemplo n.º 17
0
 // Constructor
 public AsyncPathResult(AsyncPathRequest request, Path result, PathRequestStatus status)
 {
     this.request = request;
     this.result  = result;
     this.status  = status;
 }