private void CreateTypologyIcon(PlanningCell cell) { TypologyEntry typologyEntry = null; typologiesMap.TryGetValue(cell.typology.name, out typologyEntry); if (typologyEntry == null || cell.iconType == PlanningCell.IconType.Hidden) { return; } var typologyIconPrefab = typologyEntry.icon; Material material; if (!materialsMap.TryGetValue(cell.typology, out material)) { material = new Material(typologyIconPrefab.GetComponent <MeshRenderer>().sharedMaterial); material.color = cell.typology.color; material.SetFloat("_strength", typologyEntry.strength); materialsMap.Add(cell.typology, material); } var icon = Instantiate(typologyIconPrefab, iconContainer, true); icon.GetComponent <MeshRenderer>().material = material; cell.SetIcon(icon); cell.UpdateIconPosition(map); }
public PlanningCell FindCell(int index) { PlanningCell cell = null; planningCellsMap.TryGetValue(index, out cell); return(cell); }
private void AddCell(int index, int x, int y, Coordinate coords, int typologyIndex) { PlanningCell cell = new PlanningCell(typologies[typologyIndex], coords, index, x, y, grid); cell.UpdatePosition(map); CreateTypologyIcon(cell); planningCells.Add(cell); planningCellsMap.Add(index, cell); }
public void Deselect() { // Exit previously selected cell if (selectedCell != null) { // Hide cell flag selectedCell = null; // Hide group flag if (planningGroups.Count > maxVisibleGroups && selectedGroupIndex >= 0) { groupPins[selectedGroupIndex].Show(false); selectedGroupIndex = -1; } } }
public void SetSelected(PlanningCell cell) { if (selectedCell != cell) { // Setup new pin if (cell != null) { if (planningGroups[cell.group].cells.Count <= 1) { Deselect(); } // Show flag UpdateSelectedGroupSummary(cell.group); } else { Deselect(); } selectedCell = cell; } }
private PlanningGroup CreateGroup(PlanningCell cell, int groupId) { PlanningGroup group = new PlanningGroup(groupId, this); group.center = new Coordinate(); Queue <PlanningCell> queue = new Queue <PlanningCell>(); HashSet <PlanningCell> set = new HashSet <PlanningCell>(); queue.Enqueue(cell); set.Add(cell); int count = 0; while (queue.Count > 0) { cell = queue.Dequeue(); int index = cell.x + cell.y * grid.countX; count++; group.cells.Add(cell); group.center.Longitude += cell.coords.Longitude; group.center.Latitude += cell.coords.Latitude; cell.group = groupId; if (cell.x > 0) { // Left AddNeighbor(index - 1, queue, set); // Top-Left if (cell.y > 0) { AddNeighbor(index - 1 - grid.countX, queue, set); } // Bottom-Left if (cell.y < grid.countY - 1) { AddNeighbor(index - 1 + grid.countX, queue, set); } } if (cell.x < grid.countX - 1) { // Right AddNeighbor(index + 1, queue, set); // Top-Right if (cell.y > 0) { AddNeighbor(index + 1 - grid.countX, queue, set); } // Bottom-Right if (cell.y < grid.countY - 1) { AddNeighbor(index + 1 + grid.countX, queue, set); } } // Top if (cell.y > 0) { AddNeighbor(index - grid.countX, queue, set); } // Bottom if (cell.y < grid.countY - 1) { AddNeighbor(index + grid.countX, queue, set); } } double invCount = 1.0 / count; group.center.Longitude *= invCount; group.center.Latitude *= invCount; return(group); }