private void UpdatePanelContent(ElectricNetwork network, ElectricNetworkPanel networkPanel) { CreateNodePanelsForPanelIfNecessary(network, networkPanel); RemoveNodePanelsForPanelIfNecessary(network, networkPanel); CreateEdgePanelsForPanelIfNecessary(network, networkPanel); RemoveEdgePanelsForPanelIfNecessary(network, networkPanel); UpdateNodesAndEdgesCount(network, networkPanel); }
private void RemoveEdgePanelsForPanelIfNecessary(ElectricNetwork network, ElectricNetworkPanel networkPanel) { List <ElectricNetworkEdge> possiblyOutdatedEdges = new List <ElectricNetworkEdge>(networkPanel.elementPanelsByEdge.Keys); foreach (ElectricNetworkEdge possiblyOutdatedEdge in possiblyOutdatedEdges) { if (network.edges.Contains(possiblyOutdatedEdge)) { continue; } Destroy(networkPanel.elementPanelsByEdge[possiblyOutdatedEdge].gameObject); networkPanel.elementPanelsByEdge.Remove(possiblyOutdatedEdge); } }
private void CreateNewPanelsIfNecessary() { foreach (ElectricNetwork network in electricNetworkManager.electricNetworks) { if (panelsByNetwork.ContainsKey(network)) { continue; } GameObject networkPanelGameObject = Instantiate(networkPanelPrefab); networkPanelGameObject.transform.SetParent(networkPanelContainer.transform); ElectricNetworkPanel networkPanel = networkPanelGameObject.GetComponent <ElectricNetworkPanel>(); networkPanel.SetTitle("Network " + network.id); panelsByNetwork.Add(network, networkPanel); newlyCreatednetworkPanels.Add(networkPanel); } }
private void CreateNodePanelsForPanelIfNecessary(ElectricNetwork network, ElectricNetworkPanel networkPanel) { // Create Nodes (if necessary) foreach (ElectricNetworkNode node in network.nodes) { if (networkPanel.elementPanelsByNode.Keys.Contains(node)) { continue; } // Create Node-ElementPanel entry GameObject elementPanelGameObject = Instantiate(networkElementPrefab); elementPanelGameObject.transform.SetParent(networkPanel.networkNodesContainer.transform); ElectricNetworkElementPanel elementPanel = elementPanelGameObject.GetComponent <ElectricNetworkElementPanel>(); elementPanel.SetText("N " + node.connector.Id); elementPanel.type = ElectricNetworkElementPanel.Type.Node; networkPanel.elementPanelsByNode.Add(node, elementPanel); } }
private void CreateEdgePanelsForPanelIfNecessary(ElectricNetwork network, ElectricNetworkPanel networkPanel) { // Create Edges (if necessary) foreach (ElectricNetworkEdge edge in network.edges) { if (networkPanel.elementPanelsByEdge.Keys.Contains(edge)) { continue; } // Create Edge-ElementPanel entry GameObject elementPanelGameObject = Instantiate(networkElementPrefab); elementPanelGameObject.transform.SetParent(networkPanel.networkEdgesContainer.transform); ElectricNetworkElementPanel elementPanel = elementPanelGameObject.GetComponent <ElectricNetworkElementPanel>(); elementPanel.SetText("E " + edge.cable.Id); elementPanel.type = ElectricNetworkElementPanel.Type.Edge; networkPanel.elementPanelsByEdge.Add(edge, elementPanel); } }
private void UpdateNodesAndEdgesCount(ElectricNetwork network, ElectricNetworkPanel networkPanel) { networkPanel.nodesTitleLabel.text = $"Nodes ({network.nodes.Count})"; networkPanel.edgesTitleLabel.text = $"Edges ({network.edges.Count})"; }