/* 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);
        }
    }
Ejemplo n.º 2
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);
        }
    }
Ejemplo n.º 3
0
    public virtual void Repath()
    {
        // Check that there is a target somewhere and if not, try to find one
        if (target == null)
        {
            target = FindNearestHostile(tagOfHostiles);
        }

        // There is no target for now
        if (target == null)
        {
            animation.Play("idle");
        }

        // Nothing to do, just wait
        if (seeker == null || target == null || !seeker.IsDone())
        {
            return;
        }

        // Calculate a path from my current location to the target's location
        Path path = ABPath.Construct(transform.position, target.transform.position, null);

        // Start pathfinding
        seeker.StartPath(path, OnPathComplete);
    }
Ejemplo n.º 4
0
    /** Recalculates the path to #target.
     * Queries a path request to the Seeker, the path will not be calculated instantly, but will be put on a queue and calculated as fast as possible.
     * It will wait if the current path request by this seeker has not been completed yet.
     * \see Seeker.IsDone */
    public virtual void Repath()
    {
        lastPathSearch = Time.time;

        if (seeker == null || target == null || !canSearch || !seeker.IsDone())
        {
            StartCoroutine(WaitToRepath());
            return;
        }

        //for (int i=0;i<1000;i++) {
        //MultithreadPath mp = new MultithreadPath (transform.position,target.position,null);
        //Path p = new Path (transform.position,target.position,null);
        //	AstarPath.StartPath (mp);
        //}
        //Debug.Log (AstarPath.pathQueue.Count);

        //StartCoroutine (WaitToRepath ());

        /*ConstantPath cpath = new ConstantPath(transform.position,null);
         * //Must be set to avoid it from searching towards Vector3.zero
         * cpath.heuristic = Heuristic.None;
         * //Here you set how far it should search
         * cpath.maxGScore = 2000;
         * AstarPath.StartPath (cpath);*/
        //FloodPathTracer fpathTrace = new FloodPathTracer (transform.position,fpath,null);
        //seeker.StartPath (fpathTrace,OnPathComplete);

        Path p = ABPath.Construct(transform.position, target.position, null);

        seeker.StartPath(p, OnPathComplete);
        //Start a new path from transform.positon to target.position, return the result to the function OnPathComplete
        //seeker.StartPath (transform.position,target.position,OnPathComplete);
    }
Ejemplo n.º 5
0
    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();
    }
Ejemplo n.º 6
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());
            }
        }
    }
Ejemplo n.º 7
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;
        }
Ejemplo n.º 8
0
 public void MoveToPosWithPath_Impl(MoveWithPath item)
 {
     if (GlobalSettings.Instance.PvpSetting.isPlayerMoveBeforeServer && Singleton <PvpManager> .Instance.IsInPvp && this.self.isPlayer)
     {
         return;
     }
     if (item == null)
     {
         return;
     }
     this.moveWithPath         = item;
     this.self.serverTargetPos = MoveController.ServerPosInvalide;
     if (this.self.isMonster)
     {
         this.self.serverTargetPos = MoveController.SVectgor3ToVector3(item.toPos);
         this.path            = ABPath.Construct(this.self.transform.position, MoveController.SVectgor3ToVector3(item.toPos), null);
         this.path.vectorPath = new List <Vector3>();
         foreach (SVector3 current in item.path)
         {
             this.path.vectorPath.Add(MoveController.SVectgor3ToVector3(current));
         }
         this.navAgent.MoveWithPath(item.targetUnitId, MoveController.SVectgor3ToVector3(item.toPos), item.stopDistance, this.path);
         if (item.tick > this.lastServerTick)
         {
             this.lastServerTick = item.tick;
             this.lastServerPos  = MoveController.SVectgor3ToVector3(item.pos);
         }
     }
 }
Ejemplo n.º 9
0
    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);
    }
Ejemplo n.º 10
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()));
    }
Ejemplo n.º 11
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);
    }
Ejemplo n.º 12
0
    /** Returns a new path instance.
     * The path will be taken from the path pool if path recycling is turned on.\n
     * This path can be sent to #StartPath(Path,OnPathDelegate,int) with no change, but if no change is required #StartPath(Vector3,Vector3,OnPathDelegate) does just that.
     * \code var seeker = GetComponent<Seeker>();
     * Path p = seeker.GetNewPath (transform.position, transform.position+transform.forward*100);
     * // Disable heuristics on just this path for example
     * p.heuristic = Heuristic.None;
     * seeker.StartPath (p, OnPathComplete);
     * \endcode
     */
    public ABPath GetNewPath(Vector3 start, Vector3 end)
    {
        // Construct a path with start and end points
        ABPath p = ABPath.Construct(start, end, null);

        return(p);
    }
Ejemplo n.º 13
0
 private void OnPathCalculationDone(Path path)
 {
     if (path.PipelineState == PathState.Returned)
     {
         AILerp.SetPath(path);
     }
     else if (path.CompleteState == PathCompleteState.Error)
     {
         if (randomStart < startingPoints.Length)
         {
             randomStart++;
         }
         else if (randomStart > 0)
         {
             randomStart--;
         }
         if (randomEnd < endingPoints.Length)
         {
             randomEnd++;
         }
         else if (randomStart > 0)
         {
             randomEnd--;
         }
         Path nextPath = ABPath.Construct(startingPoints[randomStart].Vector3FromCoordinates, endingPoints[randomEnd].Vector3FromCoordinates, OnPathCalculationDone);
         AILerp.SetPath(path);
     }
 }
Ejemplo n.º 14
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);
            }
        }
    }
Ejemplo n.º 15
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++;
            }
            //}
        }
    }
        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;
        }
    /** 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;
        }
    }
Ejemplo n.º 18
0
    private void RandomlyChoosePath(Tile[] startingPoints, Tile[] endingPoints)
    {
        randomStart         = UnityEngine.Random.Range(0, startingPoints.Length);
        randomEnd           = UnityEngine.Random.Range(0, endingPoints.Length);
        this.startingPoints = startingPoints;
        this.endingPoints   = endingPoints;
        Path path = ABPath.Construct(startingPoints[randomStart].Vector3FromCoordinates, endingPoints[randomEnd].Vector3FromCoordinates, OnPathCalculationDone);

        AILerp.SetPath(path);
    }
Ejemplo n.º 19
0
	public virtual void Repath()
	{
		this.lastPathSearch = Time.time;
		if (this.seeker == null || this.target == null || !this.canSearch || !this.seeker.IsDone())
		{
			base.StartCoroutine(this.WaitToRepath());
			return;
		}
		Path p = ABPath.Construct(base.transform.position, this.target.position, null);
		this.seeker.StartPath(p, new OnPathDelegate(this.OnPathComplete), -1);
	}
Ejemplo n.º 20
0
        private void SearchPath()
        {
            _pathTimer.Activate();
            _waitingForPathCalculation = true;
            _seeker.CancelCurrentPathRequest();
            var p = ABPath.Construct(Tr.position, MoveTarget);

            p.traversalProvider = _traversal;
            _seeker.StartPath(p);
            //_seeker.StartPath(Tr.position, MoveTarget);
        }
Ejemplo n.º 21
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;
            }
        }
Ejemplo n.º 22
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;
        }
Ejemplo n.º 23
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;
            }
        }
Ejemplo n.º 24
0
    public void ShowPath()
    {
        Path p = null;

        p = ABPath.Construct(start.position, end.position, OnPathComplete);

        if (p != null)
        {
            AstarPath.StartPath(p);
            lastPath = p;
        }
    }
Ejemplo n.º 25
0
    /// <summary>
    /// This method calculate the path that will be taken by the unit and also shows the path nodes that will be used.
    /// </summary>
    /// <param name="node"></param>
    /// <returns></returns>
    private IEnumerator HandlePathSelection(GraphNode node, System.Action actionCompleted = null)
    {
        moveCompleted = false;

        ABPath path = ABPath.Construct(selected.transform.position, (Vector3)node.position);

        path.traversalProvider = selected.traversalProvider;

        AstarPath.StartPath(path);

        while (path.vectorPath.Count == 0)
        {
            StartCoroutine(path.WaitForPath());
        }

        if (path.error)
        {
            Debug.LogError("Path failed:\n" + path.errorLog);
            GeneratePossibleMoves();
            yield break;
        }

        for (int i = 0; i < path.vectorPath.Count; i++)
        {
            AddCurrentPathToOverlay(path.vectorPath[i]);
        }

        movementCost = GridManager.PathNodesOverlayTiles.Count - 1;
        GridManager.DrawCurrentPathNodes();

        /// check for the input behaviours when the AI is playing
        if ((InputManager.Instance.canUseInputs && Input.GetMouseButtonDown(0)) ^ (selected is AIEnemy))
        {
            /// Disable Inputs for player
            DisableInputs(selected, false);
            /// Select target node for AStar
            selected.targetNode = path.path[path.path.Count - 1];
            /// Clear Overlay Tiles
            GridManager.ClearTiles();
            /// Destroy Previous Tiles Overlay
            DestroyPossibleMoves();
            /// Move along path AStar
            yield return(StartCoroutine(MoveAlongPath(selected, path, movementSpeed)));

            /// Enable Inputs
            DisableInputs(selected, true);
            /// Deselect AStar Unit
            Deselect();
            /// Confirm that the move is complete
            moveCompleted = true;
            actionCompleted?.Invoke();
        }
    }
Ejemplo n.º 26
0
        public void CalculatePath()
        {
            path = ABPath.Construct(go.transform.position, targetPosition.Value, OnPathComplete); // create path from current position to closest/first node
            AstarPath.StartPath(path);                                                            //make the actual vector3 path which we'll use lateron.

            if (LogEvents.Value)
            {
                Debug.Log("Start Position" + go.transform.position + "End Position" + targetPosition.Value);
            }

            return;
        }
Ejemplo n.º 27
0
    public virtual void Repath()
    {
        lastPathSearch = Time.time;

        if (seeker == null || target == null || !canSearch || !seeker.IsDone())
        {
            StartCoroutine(WaitToRepath());
            return;
        }

        Path p = ABPath.Construct(transform.position, target.position, null);

        seeker.StartPath(p, OnPathComplete);
    }
Ejemplo n.º 28
0
    private Path GetPath(HexTile startingCell, HexTile targetCell, OnPathDelegate onComplete)
    {
        if (AstarPath.active == null)
        {
            Debug.LogError("Astar not active", this);
            return(null);
        }

        var p = ABPath.Construct(startingCell.transform.position, targetCell.transform.position, onComplete);

        AstarPath.StartPath(p);

        return(p);
    }
Ejemplo n.º 29
0
        //计算AB路径
        public ABPath StartABPath(Vector3 start, Vector3 end, ITraversalProvider traversalProvider, OnPathDelegate callback)
        {
            var path = ABPath.Construct(start, end, callback);

            path.traversalProvider = traversalProvider;
            if (callback != null)
            {
            }
            else
            {
                path.BlockUntilCalculated();
            }
            AstarPath.StartPath(path);
            return(path);
        }
Ejemplo n.º 30
0
    /// <summary>
    /// 判断路径是否有效
    /// </summary>
    /// <param name="startPosition"></param>
    /// <param name="endPosition"></param>
    /// <returns></returns>
    public static bool CheckPath(Vector3 startPosition, Vector3 endPosition)
    {
        ABPath path = ABPath.Construct(startPosition, endPosition);

        path.calculatePartial = true;
        AstarPath.StartPath(path);
        AstarPath.BlockUntilCalculated(path);
        if (path.originalEndPoint == path.endPoint)
        {
            return(true);
        }
        else
        {
            return(false);
        }
    }