예제 #1
0
    void FindPath()
    {
        TileSystem tileSystem = TileSystem.Instance;

        while (0 != _pathfindingQueue.Count)
        {
            //제일 앞 타일을 하나 꺼낸다.
            sPathCommand command = _pathfindingQueue[0];
            _pathfindingQueue.RemoveAt(0);

            //방문한 타일인가?
            if (false == command.tileCell.IsVisit())
            {
                command.tileCell.Visit();

                if (_targetTileCell.GetTilePosition().Equals(command.tileCell.GetTilePosition()))
                {
                    _reverseTileCell = _targetTileCell;
                    return;
                }

                for (int direction = 0; direction < (int)eDirection.MAX; direction++)
                {
                    sTilePosition nextTilePos = new sTilePosition(command.tileCell.GetTileX(), command.tileCell.GetTileY());
                    TileHelper.GetNextTilePosByDirection((eDirection)direction, ref nextTilePos);
                    TileCell nextTileCell = tileSystem.GetTileCell(nextTilePos);

                    if (((true == tileSystem.CanMoveTileCell(nextTilePos.tileX, nextTilePos.tileY)) && false == nextTileCell.IsVisit()) ||
                        (nextTilePos.tileX == _targetTileCell.GetTileX() && nextTilePos.tileY == _targetTileCell.GetTileY()))
                    {
                        float newDistanceFromStart = command.tileCell.GetDistanceFromStart() + command.tileCell.GetDistanceWeight();
                        float newHeuristic         = CalcAstarHeuristic(newDistanceFromStart, nextTileCell, _targetTileCell);

                        if (null == nextTileCell.GetPrevCell())
                        {
                            nextTileCell.SetDistanceFromStart(newDistanceFromStart);
                            nextTileCell.SetPrevCell(command.tileCell);                                 //이전 타일 기억

                            sPathCommand newCommand = new sPathCommand();
                            newCommand.heuristic = newHeuristic;
                            newCommand.tileCell  = nextTileCell;
                            PushCommand(newCommand);
                        }
                    }
                }
            }
        }
    }
예제 #2
0
    void BuildPath()
    {
        while (null != _reverseTileCell)
        {
                        #if UNITY_EDITOR
            _reverseTileCell.DrawColor(_drawColor);
            _drawTilecell.Add(_reverseTileCell);
                        #endif


            _character.PushPathTileCell(_reverseTileCell);
            _reverseTileCell = _reverseTileCell.GetPrevCell();
        }

        if (_character.GetPathStack().Count != 0)
        {
            _character.GetPathStack().Pop();                    //자기 위치 타일 빼주기
        }
    }