44 lines
1.3 KiB
C#
44 lines
1.3 KiB
C#
|
|
using UnityEngine;
|
|||
|
|
|
|||
|
|
namespace UI.Tracking
|
|||
|
|
{
|
|||
|
|
/// <summary>
|
|||
|
|
/// Marks a GameObject as the source point for distance calculations in the tracking system.
|
|||
|
|
/// Typically attached to the player or camera. Only one should be active at a time.
|
|||
|
|
/// </summary>
|
|||
|
|
public class TrackingDistanceSource : MonoBehaviour
|
|||
|
|
{
|
|||
|
|
private static TrackingDistanceSource _instance;
|
|||
|
|
|
|||
|
|
/// <summary>
|
|||
|
|
/// The currently active distance source (typically the player)
|
|||
|
|
/// </summary>
|
|||
|
|
public static TrackingDistanceSource Instance => _instance;
|
|||
|
|
|
|||
|
|
/// <summary>
|
|||
|
|
/// The world position of this distance source
|
|||
|
|
/// </summary>
|
|||
|
|
public Vector3 WorldPosition => transform.position;
|
|||
|
|
|
|||
|
|
private void OnEnable()
|
|||
|
|
{
|
|||
|
|
// Set as the active instance
|
|||
|
|
if (_instance != null && _instance != this)
|
|||
|
|
{
|
|||
|
|
Debug.LogWarning($"[TrackingDistanceSource] Multiple distance sources detected. Overwriting previous instance ({_instance.name}) with {name}");
|
|||
|
|
}
|
|||
|
|
_instance = this;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
private void OnDisable()
|
|||
|
|
{
|
|||
|
|
// Clear instance if this was the active one
|
|||
|
|
if (_instance == this)
|
|||
|
|
{
|
|||
|
|
_instance = null;
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
|