/// <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())); }
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(); }
/// <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(); } }
// Token: 0x06002A2D RID: 10797 RVA: 0x001C7382 File Offset: 0x001C5582 private IEnumerator MoveToNode(TurnBasedAI unit, GraphNode node) { ABPath path = ABPath.Construct(unit.transform.position, (Vector3)node.position, null); path.traversalProvider = unit.traversalProvider; AstarPath.StartPath(path, false); yield return(base.StartCoroutine(path.WaitForPath())); if (path.error) { Debug.LogError("Path failed:\n" + path.errorLog); this.state = TurnBasedManager.State.SelectTarget; this.GeneratePossibleMoves(this.selected); yield break; } unit.targetNode = path.path[path.path.Count - 1]; yield return(base.StartCoroutine(TurnBasedManager.MoveAlongPath(unit, path, this.movementSpeed))); unit.blocker.BlockAtCurrentPosition(); this.state = TurnBasedManager.State.SelectUnit; yield break; }