using UnityEngine; namespace UI.Tracking { /// /// Component that marks a GameObject as trackable by the OffScreenTrackerManager. /// Automatically registers/unregisters with the manager when enabled/disabled. /// public class TrackableTarget : MonoBehaviour { [Header("Configuration")] [Tooltip("Icon to display in the off-screen tracking pin")] [SerializeField] private Sprite icon; [Tooltip("Should this target display distance to the TrackingDistanceSource (e.g., player)?")] [SerializeField] private bool trackDistance = false; /// /// The icon to display in the tracking pin /// public Sprite Icon => icon; /// /// Should this target track and display distance? /// public bool TrackDistance => trackDistance; /// /// The world position of this target /// public Vector3 WorldPosition => transform.position; /// /// Get the screen-space bounds of this target's visual representation. /// Checks for Renderer or Collider2D to determine size. /// public Bounds GetWorldBounds() { // Try to get bounds from Renderer first (most accurate for visuals) Renderer renderer = GetComponentInChildren(); if (renderer != null) { return renderer.bounds; } // Fallback to Collider2D Collider2D collider = GetComponent(); if (collider != null) { return collider.bounds; } // Last resort: just return position with minimal bounds return new Bounds(transform.position, Vector3.one * 0.1f); } private void OnEnable() { // Register with the manager when enabled if (OffScreenTrackerManager.Instance != null) { OffScreenTrackerManager.Instance.RegisterTarget(this); } } private void OnDisable() { // Unregister from the manager when disabled if (OffScreenTrackerManager.Instance != null) { OffScreenTrackerManager.Instance.UnregisterTarget(this); } } /// /// Allow runtime icon changes /// public void SetIcon(Sprite newIcon) { icon = newIcon; } } }