private void Start() { var unit = this.GetUnitFacade(); Action <PathResult> callback = (result) => { //Here we treat partial completion the same as full completion, you may want to treat partials differently if (!(result.status == PathingStatus.Complete || result.status == PathingStatus.CompletePartial)) { return; } unit.MoveAlong(result.path); }; var req = new CallbackPathRequest(callback) { from = unit.position, to = this.target.position, requesterProperties = unit, pathFinderOptions = unit.pathFinderOptions }; GameServices.pathService.QueueRequest(req); }
/// <summary> /// Convenience method for queuing up path requests. /// </summary> /// <param name="fromPos">From position.</param> /// <param name="toPos">To position.</param> /// <param name="unitData">The unit UnitFacade.</param> /// <param name="callback">The path request callback.</param> private void QueuePathRequest(Vector3 fromPos, Vector3 toPos, IUnitFacade unitData, Action <PathResult> callback) { _requestedPath = true; // request a path... var req = new CallbackPathRequest(callback) { from = fromPos, to = toPos, requesterProperties = unitData, pathFinderOptions = unitData.pathFinderOptions, }; GameServices.pathService.QueueRequest(req, unitData.pathFinderOptions.pathingPriority); }
public void RegisterItem(PickupItem item) { //The result callback for use with our path request Action <PathResult> callback = (result) => { //If a path was not found, that means the item is inaccessible if (result.status != PathingStatus.Complete) { return; } //Once a result is received, the item is added to the priority queue, with the cost of the path as the priority. //This ensures that the items closest to the master will be at the font of the queue, and hence will be the first to be picked up. //Since this example shows two possible options on how to use a manual request, the item is stored with its path var entry = new ItemEntry { item = item, pathToItem = result.path }; //Since the callback is marshalled onto the main thread, there is no need to synchronize access _itemsForPickup.Enqueue(entry, result.pathCost); }; //The radius should of course be taken off the unit type that is doing the pick-up, but keeping it simple... var req = new CallbackPathRequest(callback) { from = this.transform.position, to = item.transform.position, type = this.requestType, requesterProperties = _workerModel, pathFinderOptions = _workerModel.pathFinderOptions }; GameServices.pathService.QueueRequest(req); }
/// <summary> /// Check path(from a vectore to another) validity /// </summary> /// <param name="from">From.</param> /// <param name="to">To.</param> /// <param name="unit">Unit.</param> // private void QueuePathRequest (Vector3 from, Vector3 to, IUnitFacade unit) public void IsPathValid(Vector3 from, Vector3 to) { Action <PathResult> callback = (result) => { if (result.status == PathingStatus.Complete) { // Path Exists... print("Path Validity : Complete"); } else { print("Path Validity : Something else : " + result.status.ToString()); } }; var request = new CallbackPathRequest(callback) { from = from, to = to, requesterProperties = _unitFacade, pathFinderOptions = _unitFacade.pathFinderOptions }; GameServices.pathService.QueueRequest(request); }