using GorillaCaptions.Classes; using System.Collections.Generic; using TMPro; using UnityEngine; namespace GorillaCaptions.Managers; public class BubbleManager : MonoBehaviour { public static BubbleManager instance { get; private set; } private GameObject BubbleAsset; public void Awake() { instance = this; BubbleAsset = AssetManager.LoadAsset("SpeechBubble"); } private Dictionary SpeechBubbles = new(); public void SpawnBubble(VRRig Rig, string Text) { if (SpeechBubbles.TryGetValue(Rig, out GameObject ExistingBubble)) DestroyBubble(ExistingBubble); GameObject TargetBubble = Instantiate(BubbleAsset); TargetBubble.transform.SetParent(Rig.headMesh.transform, false); TargetBubble.transform.Find("Canvas/Background/Text") .GetComponent().text = Text; TargetBubble.AddComponent().Owner = Rig; SpeechBubbles.Add(Rig, TargetBubble); } public void DestroyBubble(GameObject TargetBubble) { foreach (KeyValuePair SpeechBubble in SpeechBubbles) { if (SpeechBubble.Value == TargetBubble) { SpeechBubbles.Remove(SpeechBubble.Key); Destroy(SpeechBubble.Value); break; } } } }