/// <summary> /// 外来原因中止移动 /// </summary> public void AbortMove() { m_result = FinishPathResultType.Aborted; m_status = PathFollowingStatus.Idle; m_wayPoints = null; if (m_onPathFinishedCallBack != null) { m_onPathFinishedCallBack(FinishPathResultType.Aborted); m_onPathFinishedCallBack = null; } }
IEnumerator FollowPath() { if (!wasInterrupted) { wayPoints = new Vector3[path.childCount]; for (int i = 0; i < wayPoints.Length; i++) { wayPoints[i] = path.GetChild(i).position; wayPoints[i] = new Vector3(wayPoints[i].x, wayPoints[i].y, wayPoints[i].z); } transform.position = wayPoints[0]; nextPointIndex = 1; nextPoint = wayPoints[nextPointIndex]; } while (true) { OnMovementStart.Invoke(); yield return(data.enemyMovementBehaviour.MoveTo(nextPoint, data.enemyMovementBehaviour.currentMoveSpeed)); OnMovementEnd.Invoke(); nextPointIndex = (nextPointIndex + 1) % wayPoints.Length; nextPoint = wayPoints[nextPointIndex]; //events if (nextPointIndex == wayPoints.Length - 1) { OnPathFinished.Invoke(); } else { OnWaypointReached.Invoke(); } if (rotatesToWaypoint) { yield return(data.enemyMovementBehaviour.TurnTo((nextPoint - data.graphics.position).normalized, rotationAnglePerSecond, RotationEndCallback)); } else { data.enemyMovementBehaviour.ResetMoveDirection(); data.enemyMovementBehaviour.ResetMoveSpeed(); yield return(new WaitForSeconds(waitTime)); } yield return(null); } }
void OnDestroy() { m_onPathFinishedCallBack = null; }
/// <summary> /// 请求移动, 然后回调. 回调是在结算完成时调用 /// 比如失败, 打断都会回调 /// </summary> /// <param name="wayPoints">基于col, row的路径列表</param> /// <param name="finishCallBack">完成的回调</param> public void RequestMove(CTilePathResult wayPoints, OnPathFinished finishCallBack) { m_onPathFinishedCallBack = finishCallBack; RequestMove(wayPoints, MoveType.Direct); }
private void FinishPath() { IsDrawing = false; lastPoint = null; OnPathFinished?.Invoke(path); }