/// <summary> /// Returns a group containing the given cell group minus this one. /// </summary> public CellGroup <T> Invert(CellGroup <T> original) { Dictionary <Vector2Int, Cell <T> > cells = new Dictionary <Vector2Int, Cell <T> >(original.Cells); CellGroup <T> inverted = new CellGroup <T>(cells); inverted = inverted.Minus(this); return(inverted); }
/// <summary> /// Using the original cell group, returns a new group containing this cell group with its sides expanded. /// </summary> public CellGroup <T> ExpandGroupRecursive(int steps, CellGroup <T> originalCellGroup) { CellGroup <T> finalGroup = new CellGroup <T>(new Dictionary <Vector2Int, Cell <T> >()); foreach (KeyValuePair <Vector2Int, Cell <T> > cell in m_Cells) { finalGroup = finalGroup.Plus(originalCellGroup.GetCellDiamond(cell.Key.x, cell.Key.y, steps)); } return(finalGroup); }
/// <summary> /// Returns a group containing this cell group minus the given one. /// </summary> public CellGroup <T> Minus(CellGroup <T> toRemove) { Dictionary <Vector2Int, Cell <T> > cells = new Dictionary <Vector2Int, Cell <T> >(m_Cells); foreach (Vector2Int cell in toRemove.Cells.Keys) { if (cells.ContainsKey(cell)) { cells.Remove(cell); } } return(new CellGroup <T>(cells)); }
/// <summary> /// Returns a group containing both cell groups. /// </summary> public CellGroup <T> Plus(CellGroup <T> toAdd) { Dictionary <Vector2Int, Cell <T> > cells = new Dictionary <Vector2Int, Cell <T> >(m_Cells); foreach (KeyValuePair <Vector2Int, Cell <T> > cell in toAdd.Cells) { if (!cells.ContainsKey(cell.Key)) { cells.Add(cell); } } return(new CellGroup <T>(cells)); }
public void GenerateGrid(int width, int height) { Dictionary <Vector2Int, Cell <T> > cells = new Dictionary <Vector2Int, Cell <T> >(); for (int x = 0; x < width; x++) { for (int y = 0; y < height; y++) { cells.Add(new Vector2Int(x, y), new Cell <T>(new T())); } } m_Group = new CellGroup <T>(cells); }
public void GenerateGridFromTexture(Texture2D texture, Dictionary <Color, T> data) { Dictionary <Vector2Int, Cell <T> > cells = new Dictionary <Vector2Int, Cell <T> >(); for (int x = 0; x < texture.width; x++) { for (int y = 0; y < texture.height; y++) { Color pixel = texture.GetPixel(x, y); if (data.ContainsKey(pixel)) { cells.Add(new Vector2Int(x, y), new Cell <T>(data[pixel])); } else { Debug.LogWarning("Grid : Obtained unknown color from texture during texture generation."); cells.Add(new Vector2Int(x, y), new Cell <T>(default(T))); } } } m_Group = new CellGroup <T>(cells); }