示例#1
0
    void Awake()
    {
        instance = this;

        EventManager.instance = new EventManager();

        pathplannerMap = LoadMap(mapFilePath);

        pathfinder = new pathPlanner.AStar((x, y) =>
        {
            return(Mathf.Sqrt(Mathf.Pow((float)(x.GetX() - y.GetX()), 2) + Mathf.Pow((float)(x.GetY() - y.GetY()), 2)));
        });
    }
示例#2
0
    public pathPlanner.GraphGridMap LoadMap(string filePath_)
    {
        string[] fin = ReadLines(filePath_);

        int height = int.Parse(fin[1].Split(' ')[1]);
        int width  = int.Parse(fin[2].Split(' ')[1]);

        pathPlanner.GraphGridMap map = new pathPlanner.GraphGridMap(width, height);

        for (int y = 4; y < fin.Length; ++y)
        {
            for (int x = 0; x < width; ++x)
            {
                char value = fin[y][x];
                switch (value)
                {
                case '.':
                case 'G':
                case 'S':
                    map.GetNodeByIndex(x, y - 4).SetTraversable(true);
                    break;

                case '@':
                case 'O':
                case 'W':
                case 'T':
                    map.GetNodeByIndex(x, y - 4).SetTraversable(false);
                    break;

                default:
                    Debug.Log("something went wrong in loading map: " + filePath_ + " : " + value);
                    break;
                }
            }
        }

        return(map);
    }