コード例 #1
0
        /// <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();
            }

            //Setup the pathing engine to use
            IPathingEngine engine;

            if (this.engineType == PathingEngineType.Astar)
            {
                engine = new PathingAStar(this.initialHeapSize, moveCostProvider, GameServices.cellCostStrategy, pathSmoother);
            }
            else
            {
                engine = new PathingJumpPointSearch(this.initialHeapSize, moveCostProvider, GameServices.cellCostStrategy, pathSmoother);
            }

            _pathService             = new PathService(engine, new ThreadFactory(), this.useThreadPoolForAsyncOperations);
            _pathService.runAsync    = this.runAsync;
            GameServices.pathService = _pathService;
        }
コード例 #2
0
        /// <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;

            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
            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;
        }