Ejemplo n.º 1
0
    public CEPathFindResult GetPathFindResult(CEPathFindNode _endNode)
    {
        var result = new CEPathFindResult();


        int maxNum = 1;
        var node   = _endNode;

        while (node.parent != null)
        {
            node = node.parent;
            maxNum++;
        }

        result.isHavePath = true;
        result.paths      = new CEIntVector2[maxNum];

        node = _endNode;
        while (node != null)
        {
            result.paths [maxNum - 1] = new CEIntVector2(node.x, node.y);
            node = node.parent;
            maxNum--;
        }

        return(result);
    }
Ejemplo n.º 2
0
 /// <summary>
 /// 取得某个节点的相关属性
 /// </summary>
 /// <param name="_tileX">Tile x.</param> 当前Tile的X
 /// <param name="_tileY">Tile y.</param> 当前Tile的Y
 /// <param name="_star">Star.</param> 搜索的起点
 /// <param name="_end">End.</param> 搜索的终点
 /// <param name="_isWalkable">Is walkable.</param> 当前Tile是否可以行走
 /// <param name="_score">Score. </param>  Tile的整体评分 (Tile本身分数+Tile距终点的评分(霍夫曼评分))
 public virtual void GetTileProperty(int _tileX, int _tileY,
                                     CEPathFindNode _star, CEPathFindNode _end,
                                     out bool _isWalkable, out int _score)
 {
     _isWalkable = true;
     _score      = 1;
 }
Ejemplo n.º 3
0
 public void Reset()
 {
     x          = y = -1;
     parent     = null;
     score      = 0;
     isWalkable = false;
 }
Ejemplo n.º 4
0
 private int SortListByScore(CEPathFindNode _a, CEPathFindNode _b)
 {
     if (_a.score == _b.score)
     {
         return(0);
     }
     else
     {
         return(_a.score > _b.score ? 1 : -1);
     }
 }
Ejemplo n.º 5
0
    private CEPathFindNode GetNewNode()
    {
        CEPathFindNode node = null;

        if (nodePool.Count > 0)
        {
            node = (CEPathFindNode)nodePool.Pop();
            node.Reset();
        }
        else
        {
            node = new CEPathFindNode();
        }
        return(node);
    }
Ejemplo n.º 6
0
    public void Reset(CEPathFindBasic _holder, int _startTileX, int _startTileY, int _endTileX, int _endTileY)
    {
        mHolder = _holder;

        mStarNode            = GetNewNode();
        mStarNode.x          = _startTileX;
        mStarNode.y          = _startTileY;
        mStarNode.isWalkable = mHolder.isTileWalkable(mStarNode.x, mStarNode.y);

        mEndNode            = GetNewNode();
        mEndNode.x          = _endTileX;
        mEndNode.y          = _endTileY;
        mEndNode.isWalkable = mHolder.isTileWalkable(mEndNode.x, mEndNode.y);

        mCurrentNode            = mStarNode;
        mCurrentNode.isWalkable = mHolder.isTileWalkable(mCurrentNode.x, mCurrentNode.y);
    }
Ejemplo n.º 7
0
    public void TickSearch(out bool _isFinish, out CEPathFindResult _reuslt)
    {
        //起始节点和结束节点本身就无法走
        if (!mStarNode.isWalkable || !mEndNode.isWalkable)
        {
            _isFinish          = true;
            _reuslt            = new CEPathFindResult();
            _reuslt.isHavePath = false;
            RecyleNodes();
            return;
        }


        for (var i = 0; i < EACH_TICK_SEARCH_NODE_NUM; i++)
        {
            if (mCurrentNode.x == mEndNode.x && mCurrentNode.y == mEndNode.y)
            {
                _isFinish = true;
                _reuslt   = GetPathFindResult(mCurrentNode);
                RecyleNodes();
                return;
            }

            mCloseList.Add(mCurrentNode);

            CheckCurrentSearchAroundTile();

            if (mOpenList.Count == 0)
            {
                //没有Open节点了,全部搜索过,但未找到路径
                _isFinish          = true;
                _reuslt            = new CEPathFindResult();
                _reuslt.isHavePath = false;
                RecyleNodes();
                return;
            }

            mOpenList.Sort(SortListByScore);
            mCurrentNode = mOpenList [0];
            mOpenList.RemoveAt(0);
        }
        _isFinish = false;
        _reuslt   = null;
        return;
    }
Ejemplo n.º 8
0
 private void SetNodeProperty(CEPathFindNode _node, int _tileX, int _tileY)
 {
     _node.x = _tileX;
     _node.y = _tileY;
     mHolder.GetTileProperty(_tileX, _tileY, mStarNode, mEndNode, out _node.isWalkable, out _node.score);
 }