Beispiel #1
0
        /// <summary>
        /// 异步搜索,需要等待回调
        /// </summary>
        public static void FindPathAsync(int _starTileX, int _starTileY,
                                         int _endTileX, int _endTileY,
                                         CEPathFindMapAgent _findEngine,
                                         Action <CEPathFindResult> _finishCallback)
        {
            if (mInstance == null)
            {
                mHoldGo = new GameObject("CEPathFind");
                DontDestroyOnLoad(mHoldGo);
                mInstance = mHoldGo.AddComponent <CEPathFind>();
            }

            var agentProxy = new CEPathFindAgentProxy {
                agent = new CEPathFindAgent()
            };

            agentProxy.agent.Reset(_findEngine, _starTileX, _starTileY, _endTileX, _endTileY);
            agentProxy.callback = _finishCallback;

            mInstance.AddAgentProxy(agentProxy);
        }
Beispiel #2
0
        /// <summary>
        /// 一次性返回搜索结果,用于小图搜索
        /// </summary>
        public static CEPathFindResult FindPath(int _starTileX, int _starTileY, int _endTileX, int _endTileY, CEPathFindMapAgent _findEngine)
        {
            if (mShareAgent == null)
            {
                mShareAgent = new CEPathFindAgent();
            }

            mShareAgent.Reset(_findEngine, _starTileX, _starTileY, _endTileX, _endTileY);
            CEPathFindResult result = null;
            var isFinish            = false;
            var searchTime          = 0;

            while (!isFinish)
            {
                mShareAgent.TickSearch(out isFinish, out result);
                searchTime++;
                if (searchTime >= MAX_SEARCH_TIME && !isFinish)
                {
                    isFinish = true;
                    result   = new CEPathFindResult {
                        isHavePath = false
                    };
                    Debug.LogError("Reach CEPathFind max loop");
                    mShareAgent.DebugOutput();
                }
            }

            return(result);
        }