private void Init() { if (unit == null) { Debug.LogWarning("The Path Finder Visualizer must have a unit set."); return; } _unit = this.unit.GetUnitFacade(); var g = GridManager.instance.GetGrid(_unit.position); _cellSize = g.cellSize; _gizmoSize = new Vector3(_cellSize, 0.2f, _cellSize); IMoveCost moveCostProvider; if (this.moveCost == CostProviderType.Custom) { var moveCostProviderFactory = this.As <IMoveCostFactory>(); if (moveCostProviderFactory == null) { moveCostProvider = new DiagonalDistance(10); Debug.LogWarning("Path Service Component: Cost Provider set to Custom but no Cost Provider Factory found!."); } else { moveCostProvider = moveCostProviderFactory.CreateMoveCostProvider(); } } else { switch (this.moveCost) { case CostProviderType.Euclidean: { moveCostProvider = new EuclideanDistance(10); break; } case CostProviderType.Cardinal: { moveCostProvider = new CardinalDistance(10); break; } case CostProviderType.Manhattan: { moveCostProvider = new ManhattanDistance(10); break; } default: { moveCostProvider = new DiagonalDistance(10); break; } } } var preProcessors = this.GetComponents(typeof(IRequestPreProcessor)).Cast <IRequestPreProcessor>().OrderByDescending(p => p.priority).ToArray(); //Setup the pathing engine to use if (this.engineType == PathingEngineType.Astar) { _engine = new VisualizedAStar(this.initialHeapSize, moveCostProvider, GameServices.cellCostStrategy, new PathSmoother(), preProcessors); } else { _engine = new VisualizedJPS(this.initialHeapSize, moveCostProvider, GameServices.cellCostStrategy, new PathSmoother(), preProcessors); } var tmp = new BasicPathRequest { requester = this, requesterProperties = _unit, pathFinderOptions = _unit.pathFinderOptions }; if (_req != null) { tmp.from = _req.from; tmp.to = _req.to; } _req = tmp; }
/// <summary> /// Called on awake. /// </summary> protected sealed override void OnAwake() { //Determine the cost and path smoothing providers to use ISmoothPaths pathSmoother; var pathSmoothProvider = this.As <IPathSmootherFactory>(); if (pathSmoothProvider == null) { pathSmoother = new PathSmoother(); } else { pathSmoother = pathSmoothProvider.CreateSmoother(); } IMoveCost moveCostProvider; var moveCostProviderFactory = this.As <IMoveCostFactory>(); if (moveCostProviderFactory == null) { if (this.moveCost == CostProviderType.Custom) { this.moveCost = CostProviderType.Diagonal; } switch (this.moveCost) { case CostProviderType.Euclidean: { moveCostProvider = new EuclideanDistance(10); break; } case CostProviderType.Cardinal: { moveCostProvider = new CardinalDistance(10); break; } case CostProviderType.Manhattan: { moveCostProvider = new ManhattanDistance(10); break; } default: { moveCostProvider = new DiagonalDistance(10); break; } } } else { this.moveCost = CostProviderType.Custom; moveCostProvider = moveCostProviderFactory.CreateMoveCostProvider(); } var preProcessors = this.GetComponents(typeof(IRequestPreProcessor)).Cast <IRequestPreProcessor>().OrderByDescending(p => p.priority).ToArray(); //Setup the pathing engine to use IPathingEngine engine; if (this.engineType == PathingEngineType.Astar) { engine = new PathingAStar(this.initialHeapSize, moveCostProvider, GameServices.cellCostStrategy, pathSmoother, preProcessors); } else { engine = new PathingJumpPointSearch(this.initialHeapSize, moveCostProvider, GameServices.cellCostStrategy, pathSmoother, preProcessors); } _pathService = new PathService(engine, new ThreadFactory(), this.useThreadPoolForAsyncOperations); _pathService.runAsync = this.runAsync; GameServices.pathService = _pathService; }