using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.UI; public class BluetoothHolder : MonoBehaviour { bool debug = false; GameObject magEllipse; HashSet magEllipseViewers = new HashSet(); public static BluetoothHolder ins; public static void Init() { if (!BluetoothHolder.ins) { GameObject bluetoothHolder = Resources.Load("Prefabs/BluetoothHolder"); GameObject.Instantiate(bluetoothHolder); } } void Awake() { if (ins) { Destroy(this.gameObject); } else { ins = this; DontDestroyOnLoad(this.gameObject); } } void Start() { magEllipse = this.transform.Find("test-ellipse").gameObject; this.transform.Find("CanvasForOpenDebug").gameObject.SetActive(debug); CloseDebug(); } public void ShowMagEllipse(Object viewer) { magEllipseViewers.Add(viewer); if (magEllipseViewers.Count == 1) magEllipse.SetActive(true); } public void HideMagEllipse(Object viewer) { magEllipseViewers.Remove(viewer); if (magEllipseViewers.Count == 0) magEllipse.SetActive(false); } public void openDebug() { ShowMagEllipse(this); this.transform.Find("Canvas").gameObject.SetActive(true); this.transform.Find("Objects").gameObject.SetActive(true); } public void CloseDebug() { HideMagEllipse(this); this.transform.Find("Canvas").gameObject.SetActive(false); this.transform.Find("Objects").gameObject.SetActive(false); } }