using System.Collections.Generic; using UnityEngine; using Unheimlich.Features.Dialogue.UI; namespace Unheimlich.Features.Hallucination { /// /// Static registry that FloatingLabel instances self-register into on OnEnable/OnDisable. /// Lets HallucinationManager iterate active labels in a radius without any FindObjectsOfType. /// public static class HallucinationLabelRegistry { private static readonly HashSet _labels = new(); public static void Register(FloatingLabel label) => _labels.Add(label); public static void Unregister(FloatingLabel label) => _labels.Remove(label); /// /// Returns all registered labels whose transform is within /// of . Results are written into /// (which is cleared first) to avoid allocations per call. /// public static void GetLabelsInRadius(Vector3 center, float radius, List results) { results.Clear(); float sqrRadius = radius * radius; foreach (FloatingLabel label in _labels) { if (label == null) continue; if ((label.transform.position - center).sqrMagnitude <= sqrRadius) results.Add(label); } } } }