StartPath() public static méthode

public static StartPath ( Path p ) : void
p Path
Résultat void
Exemple #1
0
    //Call this function to start calculating a path
    public AstarPath.Path StartPath(Vector3 start, Vector3 end)
    {
        //Cancel the previous path
        if (path != null)
        {
            path.error = true;
        }

        endpos   = end;
        startpos = start;

        //Shall we search all grids or only the one specified in the "grid" variable
        if (gridSelection == GridSelection.Auto)
        {
            path = new AstarPath.Path(this, start, end, maxAngle, angleCost, stepByStep);        //Create a new Path instance
        }
        else
        {
            path = new AstarPath.Path(this, start, end, maxAngle, angleCost, stepByStep, grid);       //Create a new Path instance
        }

        isDone = false;

        /*if (multithread) {
         *      AstarPath.StartPathPreThread(path,this);
         *      StartCoroutine (MultithreadingCompleteCheck ());
         * } else {*/
        AstarPath.StartPath(path);                //Send a call to the pathfinding system to calculate the path
        //}

        return(path);
    }
Exemple #2
0
    public void Update()
    {
        // Create a new Path object
        var path = ABPath.Construct(transform.position, target.position, null);

        // Make the path use a specific traversal provider
        path.traversalProvider = traversalProvider;

        // Calculate the path synchronously
        AstarPath.StartPath(path);
        path.BlockUntilCalculated();

        if (path.error)
        {
            Debug.Log("No path was found");
        }
        else
        {
            Debug.Log("A path was found with " + path.vectorPath.Count + " nodes");

            // Draw the path in the scene view
            for (int i = 0; i < path.vectorPath.Count - 1; i++)
            {
                Debug.DrawLine(path.vectorPath[i], path.vectorPath[i + 1], Color.red);
            }
        }
    }
Exemple #3
0
    /** Internal method to start a path and mark it as the currently active path */
    void StartPathInternal(Path p, OnPathDelegate callback)
    {
        // Cancel a previously requested path is it has not been processed yet and also make sure that it has not been recycled and used somewhere else
        if (path != null && path.PipelineState <= PathState.Processing && path.CompleteState != PathCompleteState.Error && lastPathID == path.pathID)
        {
            path.Error();
            path.LogError("Canceled path because a new one was requested.\n" +
                          "This happens when a new path is requested from the seeker when one was already being calculated.\n" +
                          "For example if a unit got a new order, you might request a new path directly instead of waiting for the now" +
                          " invalid path to be calculated. Which is probably what you want.\n" +
                          "If you are getting this a lot, you might want to consider how you are scheduling path requests.");
            // No callback will be sent for the canceled path
        }

        // Set p as the active path
        path            = p;
        tmpPathCallback = callback;

        // Save the path id so we can make sure that if we cancel a path (see above) it should not have been recycled yet.
        lastPathID = path.pathID;

        // Pre process the path
        RunModifiers(ModifierPass.PreProcess, path);

        // Send the request to the pathfinder
        AstarPath.StartPath(path);
    }
Exemple #4
0
        IEnumerator DemoMultiTargetPath()
        {
            MultiTargetPath mp = MultiTargetPath.Construct(multipoints.ToArray(), end.position, null, null);

            lastPath = mp;
            AstarPath.StartPath(mp);
            yield return(StartCoroutine(mp.WaitForPath()));

            List <GameObject> unused = new List <GameObject>(lastRender);

            lastRender.Clear();

            for (int i = 0; i < mp.vectorPaths.Length; i++)
            {
                if (mp.vectorPaths[i] == null)
                {
                    continue;
                }

                List <Vector3> vpath = mp.vectorPaths[i];

                GameObject ob = null;
                if (unused.Count > i && unused[i].GetComponent <LineRenderer>() != null)
                {
                    ob = unused[i];
                    unused.RemoveAt(i);
                }
                else
                {
                    ob = new GameObject("LineRenderer_" + i, typeof(LineRenderer));
                }

                LineRenderer lr = ob.GetComponent <LineRenderer>();
                lr.sharedMaterial = lineMat;
#if UNITY_5_5_OR_NEWER
                lr.startWidth = lineWidth;
                lr.endWidth   = lineWidth;
#if UNITY_2017_1_OR_NEWER
                lr.positionCount = vpath.Count;
#else
                lr.numPositions = vpath.Count;
#endif
#else
                lr.SetWidth(lineWidth, lineWidth);
                lr.SetVertexCount(vpath.Count);
#endif

                for (int j = 0; j < vpath.Count; j++)
                {
                    lr.SetPosition(j, vpath[j] + pathOffset);
                }

                lastRender.Add(ob);
            }

            for (int i = 0; i < unused.Count; i++)
            {
                Destroy(unused[i]);
            }
        }
Exemple #5
0
    public void AttemptMove()
    {
        if (turnSpeed != turnSpeedCounter)
        {
            turnSpeedCounter++;
            return;
        }

        turnSpeedCounter = 1;

        CalculateObstacles();
        path = ABPath.Construct(movingToPoint.position, target.position, null);
        path.traversalProvider = traversalProvider;

        AstarPath.StartPath(path);
        path.BlockUntilCalculated();

        if (!path.error)
        {
            if (path.vectorPath.Count > 2)
            {
                movingToPoint.position = path.vectorPath[1];
                blocker.BlockAt(path.vectorPath[1]);
                path.vectorPath.RemoveAt(0);
            }
            else if (path.vectorPath.Count <= 2 && target == FindObjectOfType <PlayerMovePoint>().transform)
            {
                //ATTACK PLAYER
                Health playerHealth = FindObjectOfType <PlayerMovement>().GetComponent <Health>();
                playerHealth.DecreaseHealth(GetComponent <DamageDealer>().GetDamage());
            }
        }
    }
Exemple #6
0
        void GeneratePossibleMoves(TurnBasedAI unit)
        {
            var path = ConstantPath.Construct(unit.transform.position, unit.movementPoints * 1000 + 1);

            path.traversalProvider = unit.traversalProvider;

            // Schedule the path for calculation
            AstarPath.StartPath(path);

            // Force the path request to complete immediately
            // This assumes the graph is small enough that
            // this will not cause any lag
            path.BlockUntilCalculated();

            foreach (var node in path.allNodes)
            {
                if (node != path.startNode)
                {
                    // Create a new node prefab to indicate a node that can be reached
                    // NOTE: If you are going to use this in a real game, you might want to
                    // use an object pool to avoid instantiating new GameObjects all the time
                    var go = GameObject.Instantiate(nodePrefab, (Vector3)node.position, Quaternion.identity) as GameObject;
                    possibleMoves.Add(go);

                    go.GetComponent <Astar3DButton>().node = node;
                }
            }
        }
Exemple #7
0
    /// <summary>
    /// 初始化AI数据
    /// </summary>
    /// <param name="player"></param>
    public void OnInit(Monster monster)
    {
        m_Monster = monster;
        Path p = ABPath.Construct(m_Monster.m_Pos.ToVector3(), m_Monster.m_MonsterData.m_NaviPos.ToVector3(), OnPathComplete);

        AstarPath.StartPath(p);
    }
    void UpdatePath()
    {
        //如果当前正在计算任何路径,则取消它们以避免浪费处理能力
        if (lastPaths != null)
        {
            for (int i = 0; i < lastPaths.Length; i++)
            {
                lastPaths[i].Error();
            }
        }

        //如果需要,创建一个新的lastPaths数组
        if (lastPaths == null || lastPaths.Length != targets.Length)
        {
            lastPaths = new Path[targets.Length];
        }

        bestPath     = null;
        numCompleted = 0;

        //遍历目标点并生成到其路径数组
        for (int i = 0; i < targets.Length; i++)
        {
            //创建一条新的路径到当前目标点
            ABPath p = ABPath.Construct(transform.position, targets[i].position, OnTestPathComplete);

            lastPaths[i] = p;

            //请求要计算的路径,可能需要几帧
            //这将在完成时调用OnTestPathComplete
            AstarPath.StartPath(p);
        }
        //if (seeker.IsDone())
        //  seeker.StartPath(rb.position, Target.position,OnPathComplete);
    }
    /// <summary>
    /// This method generates all the nodes available for the pathfinding (no visual overlays).
    /// </summary>
    private void GeneratePossibleMoves()
    {
        GraphNodes.Clear();

        ConstantPath path = ConstantPath.Construct(selected.transform.position, selected.unitData.stats.Ap * 750);

        path.traversalProvider = selected.traversalProvider;

        AstarPath.StartPath(path);

        path.BlockUntilCalculated();

        foreach (GraphNode node in path.allNodes)
        {
            if (node != path.startNode)
            {
                GameObject go = Instantiate(nodePrefab, (Vector3)node.position, Quaternion.identity);
                possibleMoves.Add(go);

                go.GetComponent <AStarNode>().node = node;
                node.position.z = 0;

                GraphNodes.Add((Vector3)node.position);
            }
        }
    }
    public IEnumerator GetPathCost(Unit unit, Vector3Int targetPosition)
    {
        selected = unit;
        GeneratePossibleMoves();
        Vector3 start = GridManager.GetTileToCellFromWorld(unit.positionGrid);
        Vector3 end   = GridManager.GetTileToCellFromWorld(targetPosition);
        ABPath  path  = ABPath.Construct(unit.transform.position, end);

        path.traversalProvider = unit.traversalProvider;
        AstarPath.StartPath(path);
        while (path.vectorPath.Count == 0)
        {
            StartCoroutine(path.WaitForPath());
        }
        //yield return StartCoroutine(path.WaitForPath());
        if (path.error)
        {
            Debug.LogError("Path failed:\n" + path.errorLog);
            GeneratePossibleMoves();
            yield break;
        }
        movementCost = path.vectorPath.Count - 1;
        //Debug.Log(unit.gameObject.name + " postion: " + unit.positionGrid + " target postion: " + targetPosition + " cost: " + (path.vectorPath.Count - 1));
        DestroyPossibleMoves();
    }
Exemple #11
0
        IEnumerator MoveToNode(TurnBasedAI unit, GraphNode node)
        {
            var path = ABPath.Construct(unit.transform.position, (Vector3)node.position);

            path.traversalProvider = unit.traversalProvider;

            // Schedule the path for calculation
            AstarPath.StartPath(path);

            // Wait for the path calculation to complete
            yield return(StartCoroutine(path.WaitForPath()));

            if (path.error)
            {
                // Not obvious what to do here, but show the possible moves again
                // and let the player choose another target node
                // Likely a node was blocked between the possible moves being
                // generated and the player choosing which node to move to
                Debug.LogError("Path failed:\n" + path.errorLog);
                state = State.SelectTarget;
                GeneratePossibleMoves(selected);
                yield break;
            }

            // Set the target node so other scripts know which
            // node is the end point in the path
            unit.targetNode = path.path[path.path.Count - 1];

            yield return(StartCoroutine(MoveAlongPath(unit, path, movementSpeed)));

            unit.blocker.BlockAtCurrentPosition();

            // Select a new unit to move
            state = State.SelectUnit;
        }
    /* Call to update the bestPath with the closest path one of the targets.
     * It will take a few frames for this to be calculated, the bestPath variable will be null in the meantime
     */
    public void SearchClosest()
    {
        //If any paths are currently being calculated, cancel them to avoid wasting processing power
        if (lastPaths != null)
        {
            for (int i = 0; i < lastPaths.Length; i++)
            {
                lastPaths[i].Error();
            }
        }
        //Create a new lastPaths array if necessary (can reuse the old one?)
        if (lastPaths == null || lastPaths.Length != targets.Length)
        {
            lastPaths = new Path[targets.Length];
        }
        //Reset variables
        bestPath     = null;
        numCompleted = 0;
        //Loop through the targets
        for (int i = 0; i < targets.Length; i++)
        {
            //Create a new path to the target
            ABPath p = ABPath.Construct(transform.position, targets[i].position, OnTestPathComplete);

            /* Before version 3.2
             * Path p = new Path (transform.position,targets[i].position, OnTestPathComplete);
             */
            lastPaths[i] = p;
            //Request the path to be calculated, might take a few frames
            //This will call OnTestPathComplete when completed
            AstarPath.StartPath(p);
        }
    }
Exemple #13
0
    /** Call this function to start calculating a path.
     *
     * \param p			The path to start calculating
     * \param callback	The function to call when the path has been calculated
     * \param graphMask	Mask used to specify which graphs should be searched for close nodes. See Pathfinding.NNConstraint.graphMask.
     *
     * \a callback will be called when the path has completed.
     * \a Callback will not be called if the path is canceled (e.g when a new path is requested before the previous one has completed)
     */
    public Path StartPath(Path p, OnPathDelegate callback = null, int graphMask = -1)
    {
        p.enabledTags  = traversableTags;
        p.tagPenalties = tagPenalties;

        // Cancel a previously requested path is it has not been processed yet and also make sure that it has not been recycled and used somewhere else
        if (path != null && path.GetState() <= PathState.Processing && lastPathID == path.pathID)
        {
            path.Error();
            path.LogError("Canceled path because a new one was requested.\n" +
                          "This happens when a new path is requested from the seeker when one was already being calculated.\n" +
                          "For example if a unit got a new order, you might request a new path directly instead of waiting for the now" +
                          " invalid path to be calculated. Which is probably what you want.\n" +
                          "If you are getting this a lot, you might want to consider how you are scheduling path requests.");
            // No callback should be sent for the canceled path
        }

        path           = p;
        path.callback += onPathDelegate;

        path.nnConstraint.graphMask = graphMask;

        tmpPathCallback = callback;

        // Save the path id so we can make sure that if we cancel a path (see above) it should not have been recycled yet.
        lastPathID = path.pathID;

        // Pre process the path
        RunModifiers(ModifierPass.PreProcess, path);

        // Send the request to the pathfinder
        AstarPath.StartPath(path);

        return(path);
    }
Exemple #14
0
    // Update is called once per frame
    protected void Update()
    {
        //base.Update();

        path = ABPath.Construct(this.transform.position, this.GetComponent <EnemyAI>().target.position, null);

        path.traversalProvider = traversalProvider;

        AstarPath.StartPath(path);

        path.BlockUntilCalculated();

        path.Claim(this);


        if (path.error == true)
        {
            Debug.Log("No Path Was Found.");
        }
        else
        {
            Debug.Log("A Path Was Found With: " + path.vectorPath.Count + " Nodes");

            for (int i = 0; i < path.vectorPath.Count - 1; i++)
            {
                Debug.DrawLine(path.vectorPath[i], path.vectorPath[i + 1], Color.red);
            }

            this.GetComponent <Seeker>().StartPath(path.startPoint, path.endPoint, OnPathCompleteCallback);
        }
    }
Exemple #15
0
    /// <summary>
    /// 判断路径是否有效
    /// </summary>
    /// <param name="startPosition"></param>
    /// <param name="endPosition"></param>
    /// <returns></returns>
    public IEnumerator CheckPath(Vector3 startPosition, Vector3 endPosition)
    {
        ABPath path = ABPath.Construct(startPosition, endPosition);

        AstarPath.StartPath(path);
        yield return(StartCoroutine(path.WaitForPath()));
    }
Exemple #16
0
    private void CalculateAllPathsInfo(List <Building> bds)
    {
        //If any paths are currently being calculated, cancel them to avoid wasting processing power
        if (mLastPaths != null)
        {
            //mLastPaths = null;
            for (int i = 0; i < mLastPaths.Length; i++)
            {
                mLastPaths [i].Error();
            }
        }

        //Create a new lastPaths array if necessary (can reuse the old one?)
        int validbuildingnumbers    = 0;      //= MapManager.mMapInstance.NullWallBuildingNumber;
        int nullwallbuildingnumbers = bds.Count;

        foreach (Building nwbd in bds)
        {
            if (nwbd.mBI.IsDestroyed != true)
            {
                validbuildingnumbers++;
            }
        }
        if (mLastPaths == null || mLastPaths.Length != validbuildingnumbers)
        {
            mLastPaths = new Path[validbuildingnumbers];
        }

        Building bd        = null;
        int      pathindex = 0;

        for (int i = 0; i < nullwallbuildingnumbers; i++)
        {
            //foreach (Building bd in MapManager.mMapInstance.BuildingsInfoInGame) {
            //bd = MapManager.mMapInstance.BuildingsInfoInGame[i];

            /*
             * if( bd.mBI.IsDestroyed || bd.mBI.mBT == BuildingType.E_WALL)
             * {
             *      //Debug.Log("IsDestroyed = " + bd.mBI.IsDestroyed);
             *      continue;
             * }
             * else
             * {
             */
            Debug.Log("CalculateAllPathsInfo() called");
            bd = bds[i];
            if (bd.mBI.IsDestroyed != true)
            {
                Debug.Log("transform.position = " + transform.position);
                Debug.Log("bd.transform.position = " + bd.transform.position);
                ABPath p = ABPath.Construct(transform.position, bd.transform.position, OnPathInfoComplete);
                mLastPaths[pathindex] = p;
                AstarPath.StartPath(p);
                pathindex++;
            }
            //}
        }
    }
Exemple #17
0
    /** Call this function to start calculating a path.
     * \param p			The path to start calculating
     * \param callback	The function to call when the path has been calculated
     * \param graphMask	Mask used to specify which graphs should be searched for close nodes. See Pathfinding.NNConstraint.graphMask. \astarproParam
     *
     * \a callback will be called when the path has completed.
     * \a Callback will not be called if the path is canceled (e.g when a new path is requested before the previous one has completed) */
    public Path StartPath(Path p, OnPathDelegate callback = null, int graphMask = -1)
    {
        p.enabledTags  = traversableTags.tagsChange;
        p.tagPenalties = tagPenalties;

#if !AstarFree && FALSE
        //In case a multi target path has been specified, call special logic
        if (p.GetType() == typeof(MultiTargetPath))
        {
            return(StartMultiTargetPath(p as MultiTargetPath, callback));
        }
#endif
        //Cancel a previously requested path is it has not been processed yet and also make sure that it has not been recycled and used somewhere else
        if (path != null && path.GetState() <= PathState.Processing && lastPathID == path.pathID)
        {
            path.Error();
            path.LogError("Canceled path because a new one was requested.\n" +
                          "This happens when a new path is requested from the seeker when one was already being calculated.\n" +
                          "For example if a unit got a new order, you might request a new path directly instead of waiting for the now" +
                          " invalid path to be calculated. Which is probably what you want.\n" +
                          "If you are getting this a lot, you might want to consider how you are scheduling path requests.");
            //No callback should be sent for the canceled path
        }

        path           = p;
        path.callback += onPathDelegate;
        path.nnConstraint.graphMask = graphMask;

        tmpPathCallback = callback;

        //Set the Get Nearest Node hints if they have not already been set

        /*if (path.startHint == null)
         *      path.startHint = startHint;
         *
         * if (path.endHint == null)
         *      path.endHint = endHint;
         */

        //Save the path id so we can make sure that if we cancel a path (see above) it should not have been recycled yet.
        lastPathID = path.pathID;

        //Delay the path call by one frame if it was sent the same frame as the previous call

        /*if (lastPathCall == Time.frameCount) {
         *      StartCoroutine (DelayPathStart (path));
         *      return path;
         * }*/

        //lastPathCall = Time.frameCount;

        //Pre process the path
        RunModifiers(ModifierPass.PreProcess, path);

        //Send the request to the pathfinder
        AstarPath.StartPath(path);

        return(path);
    }
Exemple #18
0
		public IEnumerator CalculateConstantPath()
		{
			ConstantPath constPath = ConstantPath.Construct(this.end.position, this.searchLength, new OnPathDelegate(this.OnPathComplete));
			AstarPath.StartPath(constPath, false);
			this.lastPath = constPath;
			yield return constPath.WaitForPath();
			yield break;
		}
Exemple #19
0
    public IEnumerator CalculateConstantPath()
    {
        ConstantPath constPath = ConstantPath.Construct(end.position, searchLength, OnPathComplete);

        AstarPath.StartPath(constPath);
        lastPath = constPath;
        yield return(constPath.WaitForPath());
    }
        public void CalculatePath()
        {
            var pos = (target == null) ? targetPosition : (target.transform.position + targetPosition);

            p = ABPath.Construct(go.transform.position, pos, OnPathComplete); // create path from current position to closest/first node
            AstarPath.StartPath(p);                                           //make the actual vector3 path which we'll use lateron.
            pUpdate = 0;
        }
Exemple #21
0
    public IEnumerator DelayPathStart(Path p)
    {
        yield return(null);

        this.RunModifiers(Seeker.ModifierPass.PreProcess, p);
        AstarPath.StartPath(p, false);
        yield break;
    }
	public IEnumerator DelayPathStart (Path p) {
		yield return null;
		//lastPathCall = Time.frameCount;
		
		RunModifiers (ModifierPass.PreProcess, p);
		
		AstarPath.StartPath (p);
	}
    /** Starts a path specified by PathTypesDemo.activeDemo */
    public void DemoPath()
    {
        Path p = null;

        if (activeDemo == 0)
        {
            p = ABPath.Construct(start.position, end.position, OnPathComplete);
        }
        else if (activeDemo == 1)
        {
            MultiTargetPath mp = MultiTargetPath.Construct(multipoints.ToArray(), end.position, null, OnPathComplete);
            p = mp;
        }
        else if (activeDemo == 2)
        {
            RandomPath rp = RandomPath.Construct(start.position, searchLength, OnPathComplete);
            rp.spread        = spread;
            rp.aimStrength   = aimStrength;
            rp.aim           = end.position;
            rp.replaceChance = replaceChance;

            p = rp;
        }
        else if (activeDemo == 3)
        {
            FleePath fp = FleePath.Construct(start.position, end.position, searchLength, OnPathComplete);
            fp.aimStrength   = aimStrength;
            fp.replaceChance = replaceChance;
            fp.spread        = spread;

            p = fp;
        }
        else if (activeDemo == 4)
        {
            ConstantPath constPath = ConstantPath.Construct(end.position, searchLength, OnPathComplete);

            p = constPath;
        }
        else if (activeDemo == 5)
        {
            FloodPath fp = FloodPath.Construct(end.position, null);
            lastFlood = fp;
            p         = fp;
        }
        else if (activeDemo == 6 && lastFlood != null)
        {
            FloodPathTracer fp = FloodPathTracer.Construct(end.position, lastFlood, OnPathComplete);


            p = fp;
        }

        if (p != null)
        {
            AstarPath.StartPath(p);
            lastPath = p;
        }
    }
    public IEnumerator Constant()
    {
        ConstantPath constPath = ConstantPath.Construct(CoverTarget.transform.position, 5 * 3000, OnConstantPathComplete);

        AstarPath.StartPath(constPath);
        yield return(constPath.WaitForPath());

        Debug.Log(constPath.pathID + " " + constPath.allNodes.Count);
    }
    public IEnumerator Constant()
    {
        ConstantPath constPath = ConstantPath.Construct(end.position, searchLength, OnPathComplete);

        AstarPath.StartPath(constPath);
        lastPath = constPath;
        yield return(constPath.WaitForPath());

        Debug.Log(constPath.pathID + " " + constPath.allNodes.Count);
    }
Exemple #26
0
    public IEnumerator Constant()
    {
        mAstarPath.astarData.gridGraph.GetNearest(transform.position).node.Walkable = true;
        ConstantPath constPath = ConstantPath.Construct((transform.position - new Vector3(0, 1, 0)), (MoveSpeed / 3) * 3000, OnConstantPathComplete);

        AstarPath.StartPath(constPath);
        yield return(constPath.WaitForPath());

        Debug.Log(constPath.pathID + " " + constPath.allNodes.Count);
    }
Exemple #27
0
    /** Call this function to start calculating a path.
     * \param p			The path to start calculating
     * \param callback	The function to call when the path has been calculated
     * \param graphMask	Mask used to specify which graphs should be searched for close nodes. See Pathfinding::NNConstraint::graphMask. \astarproParam
     *
     * \a callback will be called when the path has completed.
     * \a Callback will not be called if the path is canceled (e.g when a new path is requested before the previous one has completed) */
    public Path StartPath(Path p, OnPathDelegate callback = null, int graphMask = -1)
    {
        p.enabledTags  = traversableTags.tagsChange;
        p.tagPenalties = tagPenalties;

        //In case a multi target path has been specified, call special logic
        if (p.GetType() == typeof(MultiTargetPath))
        {
            return(StartMultiTargetPath(p as MultiTargetPath, callback));
        }
        //Cancel a previously requested path is it has not been processed yet and also make sure that it has not been recycled and used somewhere else
        if (path != null && !path.processed && lastPathID == path.pathID)
        {
            path.errorLog += "Canceled path because a new one was requested\nGameObject: " + gameObject.name;
            path.error     = true;
            //No callback should be sent for the canceled path
        }

        path           = p;
        path.callback += OnPathComplete;
        path.nnConstraint.graphMask = graphMask;

        tmpPathCallback = callback;

        //Set the Get Nearest Node hints if they have not already been set
        if (path.startHint == null)
        {
            path.startHint = startHint;
        }

        if (path.endHint == null)
        {
            path.endHint = endHint;
        }

        //Save the path id so we can make sure that if we cancel a path (see above) it should not have been recycled yet.
        lastPathID = path.pathID;

        //Delay the path call by one frame if it was sent the same frame as the previous call

        /*if (lastPathCall == Time.frameCount) {
         *      StartCoroutine (DelayPathStart (path));
         *      return path;
         * }*/

        //lastPathCall = Time.frameCount;

        //Pre process the path
        RunModifiers(ModifierPass.PreProcess, path);

        //Send the request to the pathfinder
        AstarPath.StartPath(path);

        return(path);
    }
Exemple #28
0
        public void CalculatePath()
        {
            if (moveMode != MoveMode.follow && moveMode != MoveMode.followTo && moveMode != MoveMode.fleeContinuously)
            {
                path = null;
            }                          // do this to avoid instant finishing if the action had been called before and if the actor didn't move

            Vector3 targetPos;

            if (target.Value != null)
            {
                targetPos = target.Value.transform.position + targetPosition.Value;
            }
            else
            {
                targetPos = targetPosition.Value;
            }

            if (path != null && path.vectorPath.Count > 0 && (moveMode == MoveMode.follow || moveMode == MoveMode.followTo))
            {
                p = ABPath.Construct(nextPos, targetPos, OnPathComplete);
            }                                                                          // create path from next waypoint (to avoid jitter due to sudden direction change on path update) to closest/first node
            else if (moveMode != MoveMode.fleeContinuously && moveMode != MoveMode.flee && moveMode != MoveMode.randomPath)
            {
                p = ABPath.Construct(go.transform.position, targetPos, OnPathComplete);
            }                                                                                        // create path from current position to closest/first node

            else if (moveMode == MoveMode.fleeContinuously || moveMode == MoveMode.flee)
            {
                if (AstarPath.HasPro)
                {
                    p = FleePath.Construct(go.transform.position, targetPos, (int)(length.Value * 1000f), OnPathComplete);
                }                                                                                                                          // create path from current position to closest/first node
                else
                {
                    p = ABPath.Construct(go.transform.position, go.transform.position + (go.transform.position - targetPos).normalized * length.Value, OnPathComplete);
                }
            }
            else if (moveMode == MoveMode.randomPath)
            {
                if (AstarPath.HasPro)
                {
                    p = RandomPath.Construct(go.transform.position, (int)(length.Value * 1000f), OnPathComplete);
                }                    // create path from current position to closest/first node
                else                 // random direction! This is just a cheap immitation of the real randompath!
                {
                    p = ABPath.Construct(go.transform.position, go.transform.position + new Vector3(UnityEngine.Random.Range(-1f, 1f), 0f, UnityEngine.Random.Range(-1f, 1f)).normalized *length.Value, OnPathComplete);
                }
            }

            AstarPath.StartPath(p);              //make the actual vector3 path which we'll use lateron.
            time = Time.time;
            return;
        }
Exemple #29
0
        // Token: 0x060029EC RID: 10732 RVA: 0x001C21BC File Offset: 0x001C03BC
        private void DemoPath()
        {
            Path path = null;

            switch (this.activeDemo)
            {
            case PathTypesDemo.DemoMode.ABPath:
                path = ABPath.Construct(this.start.position, this.end.position, new OnPathDelegate(this.OnPathComplete));
                break;

            case PathTypesDemo.DemoMode.MultiTargetPath:
                base.StartCoroutine(this.DemoMultiTargetPath());
                break;

            case PathTypesDemo.DemoMode.RandomPath:
            {
                RandomPath randomPath = RandomPath.Construct(this.start.position, this.searchLength, new OnPathDelegate(this.OnPathComplete));
                randomPath.spread      = this.spread;
                randomPath.aimStrength = this.aimStrength;
                randomPath.aim         = this.end.position;
                path = randomPath;
                break;
            }

            case PathTypesDemo.DemoMode.FleePath:
            {
                FleePath fleePath = FleePath.Construct(this.start.position, this.end.position, this.searchLength, new OnPathDelegate(this.OnPathComplete));
                fleePath.aimStrength = this.aimStrength;
                fleePath.spread      = this.spread;
                path = fleePath;
                break;
            }

            case PathTypesDemo.DemoMode.ConstantPath:
                base.StartCoroutine(this.DemoConstantPath());
                break;

            case PathTypesDemo.DemoMode.FloodPath:
                path = (this.lastFloodPath = FloodPath.Construct(this.end.position, null));
                break;

            case PathTypesDemo.DemoMode.FloodPathTracer:
                if (this.lastFloodPath != null)
                {
                    path = FloodPathTracer.Construct(this.end.position, this.lastFloodPath, new OnPathDelegate(this.OnPathComplete));
                }
                break;
            }
            if (path != null)
            {
                AstarPath.StartPath(path, false);
                this.lastPath = path;
            }
        }
Exemple #30
0
        /// <summary>Starts a path specified by PathTypesDemo.activeDemo</summary>
        void DemoPath()
        {
            Path p = null;

            switch (activeDemo)
            {
            case DemoMode.ABPath:
                p = ABPath.Construct(start.position, end.position, OnPathComplete);
                break;

            case DemoMode.MultiTargetPath:
                StartCoroutine(DemoMultiTargetPath());
                break;

            case DemoMode.ConstantPath:
                StartCoroutine(DemoConstantPath());
                break;

            case DemoMode.RandomPath:
                RandomPath rp = RandomPath.Construct(start.position, searchLength, OnPathComplete);
                rp.spread      = spread;
                rp.aimStrength = aimStrength;
                rp.aim         = end.position;

                p = rp;
                break;

            case DemoMode.FleePath:
                FleePath fp = FleePath.Construct(start.position, end.position, searchLength, OnPathComplete);
                fp.aimStrength = aimStrength;
                fp.spread      = spread;

                p = fp;
                break;

            case DemoMode.FloodPath:
                p = lastFloodPath = FloodPath.Construct(end.position, null);
                break;

            case DemoMode.FloodPathTracer:
                if (lastFloodPath != null)
                {
                    FloodPathTracer fpt = FloodPathTracer.Construct(end.position, lastFloodPath, OnPathComplete);
                    p = fpt;
                }
                break;
            }

            if (p != null)
            {
                AstarPath.StartPath(p);
                lastPath = p;
            }
        }