예제 #1
0
    private void TT(Vector3 startPoint, Vector3 endPoint)
    {
        if (sPoint == null)
        {
            sPoint = new Point(0, 0);
        }
        if (ePoint == null)
        {
            ePoint = new Point(0, 0);
        }
        Vector2 s1 = sceneInfo.PixelToGrid(startPoint.x, startPoint.z);
        Vector2 s2 = sceneInfo.PixelToGrid(endPoint.x, endPoint.z);

        sPoint.X = (int)s1.x;
        sPoint.Y = (int)s1.y;
        ePoint.X = (int)s2.x;
        ePoint.Y = (int)s2.y;

        // 1为可行走点 0为阻挡点
        PathFinder mPathFinder = new PathFinder(sceneInfo.Grids);

        mPathFinder.Formula               = HeuristicFormula.Manhattan;
        mPathFinder.Diagonals             = true;
        mPathFinder.HeavyDiagonals        = false;
        mPathFinder.HeuristicEstimate     = 2;
        mPathFinder.PunishChangeDirection = false;
        mPathFinder.TieBreaker            = false;
        mPathFinder.SearchLimit           = 50000;
        mPathFinder.ReopenCloseNodes      = true;
        List <PathFinderNode> path = mPathFinder.FindPath(sPoint, ePoint);

        if (path != null && path.Count > 0)
        {
            Debug.Log(path.Count);
            int length = path.Count;
            for (int i = 0; i < length; ++i)
            {
                PathFinderNode pathFinderNode = path[i];

                Debug.Log(pathFinderNode.X + "/" + pathFinderNode.Y);
            }
            if (walker == null)
            {
                walker = new Walker();
            }
            walker.player    = testPlayer;
            walker.path      = path;
            walker.sceneInfo = sceneInfo;
            walker.DoWalk();
        }
    }