/// <summary> /// /// </summary> /// <param name="_from"></param> /// <param name="_to"></param> public void DrawPath(Vector3Int _from, Vector3Int _to) { ClearPath(); // get path // path will either be a list of Points (x, y), or an empty list if no path is found. m_Paths = PathFind.FindPath( m_Grid, _from, _to, ePathFindDistanceType.Manhattan); Dictionary <Vector3Int, float> costs = new Dictionary <Vector3Int, float>(); foreach (Vector3Int point in m_Paths) { TileBase tile = GetTileAt(point); if (tile.m_Unit != null) { costs.Add(point, 0f); continue; } tile.m_Property.m_IsPath = true; tile.SetColor(eTileType.Movable); costs.Add(point, 1f); } m_Grid.UpdateGrid(costs); }
/// <summary> /// /// </summary> private void ClearPath() { if (m_Paths == null) { return; } if (m_Paths.Count == 0) { return; } Dictionary <Vector3Int, float> costs = new Dictionary <Vector3Int, float>(); foreach (Vector3Int point in m_Paths) { TileBase tile = GetTileAt(point); if (tile.m_Unit != null) { costs.Add(point, 0f); continue; } tile.m_Property.m_IsPath = false; tile.SetColor(eTileType.Movable); costs.Add(point, 1f); } m_Paths.Clear(); m_Paths = null; m_Grid.UpdateGrid(costs); }
/// <summary> /// initialize all tiles /// </summary> public void InitAllTiles() { Dictionary <Vector3Int, float> tilesCost = new Dictionary <Vector3Int, float>(); foreach (KeyValuePair <Vector3Int, TileBase> kv in m_Tiles) { TileBase tile = kv.Value; tile.Init(); tile.SetColor(tile.m_Property.m_Type); if (tile.m_Property.m_Type == eTileType.Movable) { if (tile.m_Unit == null) { tilesCost.Add(kv.Key, 1f); } else { tilesCost.Add(kv.Key, 0f); } } else { tilesCost.Add(kv.Key, 0f); } } m_Grid.UpdateGrid(tilesCost); m_MovableTiles.Clear(); m_AttackableTiles.Clear(); m_Paths.Clear(); }