This commit is contained in:
@@ -0,0 +1,49 @@
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
namespace ShrinkTutorial
|
||||
{
|
||||
public class ShrinkTutorialTrigger : MonoBehaviour
|
||||
{
|
||||
private static readonly HashSet<string> FiredSessionKeys = new();
|
||||
|
||||
[SerializeField] private string tutorialId = string.Empty;
|
||||
[SerializeField] private bool fireOnEnable = true;
|
||||
[SerializeField] private bool onlyOncePerSession = true;
|
||||
[SerializeField] private bool onlyIfNotCompleted = true;
|
||||
|
||||
private void OnEnable()
|
||||
{
|
||||
if (fireOnEnable)
|
||||
Fire();
|
||||
}
|
||||
|
||||
public void Fire()
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(tutorialId))
|
||||
return;
|
||||
|
||||
var sessionKey = $"{gameObject.scene.path}:{gameObject.GetInstanceID()}:{tutorialId}";
|
||||
if (onlyOncePerSession && !FiredSessionKeys.Add(sessionKey))
|
||||
return;
|
||||
|
||||
var manager = ShrinkTutorialManager.Instance;
|
||||
if (!manager)
|
||||
{
|
||||
Debug.LogWarning($"[ShrinkTutorial] 触发器 {name} 找不到 TutorialManager。");
|
||||
return;
|
||||
}
|
||||
|
||||
if (onlyIfNotCompleted && manager.HasCompleted(tutorialId))
|
||||
return;
|
||||
|
||||
manager.StartTutorial(tutorialId);
|
||||
}
|
||||
|
||||
[RuntimeInitializeOnLoadMethod(RuntimeInitializeLoadType.SubsystemRegistration)]
|
||||
private static void ResetSessionState()
|
||||
{
|
||||
FiredSessionKeys.Clear();
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user