Esempio n. 1
0
    public void DiscoverTiles(Location from, Location to)
    {
        //Debug.Log("from: " + from.ToString() + ", to: " + to.ToString());
        int heuristic    = 0;
        int viewDistance = AreaManager.Instance.playerViewDistance;
        var handledTiles = new HashSet <Location>();
        // Can improve animation here. Use for loop to control delay time.
        int weight = Nav.GetTileWeight(to);

        Nav.SetTileWeight(to, 1);
        foreach (var step in Nav.GetPath(from, to))
        {
            for (int x = -viewDistance; x < viewDistance + 1; x++)
            {
                for (int y = -viewDistance; y < viewDistance + 1; y++)
                {
                    Location tmp = new Location(step.x + x, step.y + y);
                    if (handledTiles.Contains(tmp))
                    {
                        continue;
                    }
                    heuristic = Mathf.Abs(x) + Mathf.Abs(y);
                    if (heuristic <= viewDistance)
                    {
                        if (TileDic.ContainsKey(tmp))
                        {
                            AddExploredTile(tmp);
                            TileDic[tmp].SetVisiable();
                            handledTiles.Add(tmp);
                        }
                    }
                }
            }
        }
        Nav.SetTileWeight(to, weight);
    }