43 lines
1.1 KiB
C#
43 lines
1.1 KiB
C#
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
|
|
namespace ShrinkTutorial
|
|
{
|
|
public static class ShrinkTutorialAnchorRegistry
|
|
{
|
|
private static readonly Dictionary<string, ShrinkTutorialAnchor> Anchors = new();
|
|
|
|
public static void Register(ShrinkTutorialAnchor anchor)
|
|
{
|
|
if (!anchor || string.IsNullOrWhiteSpace(anchor.AnchorId))
|
|
return;
|
|
|
|
Anchors[anchor.AnchorId] = anchor;
|
|
}
|
|
|
|
public static void Unregister(ShrinkTutorialAnchor anchor)
|
|
{
|
|
if (!anchor || string.IsNullOrWhiteSpace(anchor.AnchorId))
|
|
return;
|
|
|
|
if (Anchors.TryGetValue(anchor.AnchorId, out var current) && current == anchor)
|
|
Anchors.Remove(anchor.AnchorId);
|
|
}
|
|
|
|
public static Transform Get(string anchorId)
|
|
{
|
|
if (string.IsNullOrWhiteSpace(anchorId))
|
|
return null;
|
|
|
|
return Anchors.TryGetValue(anchorId, out var anchor) && anchor
|
|
? anchor.transform
|
|
: null;
|
|
}
|
|
|
|
public static void Reset()
|
|
{
|
|
Anchors.Clear();
|
|
}
|
|
}
|
|
}
|