Add tracking pins for offscreen targets
This commit is contained in:
43
Assets/Scripts/UI/Tracking/TrackingDistanceSource.cs
Normal file
43
Assets/Scripts/UI/Tracking/TrackingDistanceSource.cs
Normal file
@@ -0,0 +1,43 @@
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user