using UnityEngine; using System.Collections.Generic; using UnityEngine.UI; using Util; public class PortSelector : MonoBehaviour, IResettable { public ModelManager modelManager; public GameObject prefab; public Vector3 offset = new Vector3(0,48,0); public List portGOs = new List(); public List listPSB = new List(); public Dictionary mapPSB = new Dictionary(); //Gets called from BaseModelSelector public void GenerateButtons() { ResetThis(); int i = 0; int index = 0; foreach (Port port in modelManager.BaseModel.Ports) { if (!port.Chooseable) { Debug.Log($"Skipping port {port.PortID} for Selection..."); index++; continue; } Vector3 off = i * offset; Debug.Log($"Adding Port {port.PortName} : {port.PortID} to Selection with {off.x}, {off.y}, {off.z}"); var go = Spawn.GO(prefab, transform, off, port.PortID + i); portGOs.Add(go); go.SetActive(true); var text = go.GetComponentInChildren(); if (text == null) { Debug.LogWarning($"No TextMeshProUGUI found in {go.name}, cannot set text."); } text.text = port.PortName; var psb = go.GetComponent(); psb.PortID = port.PortID; psb.PortIndex = index; psb.marker = go.GetComponentInChildren(true).gameObject; psb.RemoveOtherMarkers = RemoveOtherMarkers; listPSB.Add(psb); mapPSB.Add(index, psb); index++; i++; } } private void RemoveOtherMarkers() { foreach (var psb in listPSB) { psb.marker.SetActive(false); } } public void ResetThis() { Debug.Log($"Resetting {this.name}"); foreach (var port in portGOs) { Debug.Log($"Destroying {port}"); Destroy(port); } portGOs.Clear(); foreach (var psb in listPSB) { Debug.Log($"Destroying {psb}"); Destroy(psb); } listPSB.Clear(); } }