70 lines
2.2 KiB
C#
70 lines
2.2 KiB
C#
![]() |
using System.Collections;
|
||
|
using System.Collections.Generic;
|
||
|
using UnityEngine;
|
||
|
using UnityEngine.Events;
|
||
|
|
||
|
public class ActivatorManager : MonoBehaviour
|
||
|
{
|
||
|
public static ActivatorManager Instance;
|
||
|
|
||
|
[Tooltip("Events to run per step; index is the step number.")]
|
||
|
public List<UnityEvent> StepEvents;
|
||
|
public List<UnityEvent> TimeLineEvents;
|
||
|
|
||
|
[Min(0)] public int stepIndex = 0;
|
||
|
int loadedStepIndex;
|
||
|
private void Awake() => Instance = this;
|
||
|
|
||
|
/// <summary>Execute exactly one step by index (no bounds errors).</summary>
|
||
|
public void ExecuteStep(int index)
|
||
|
{
|
||
|
//if (StepEvents == null || StepEvents.Count == 0) return;
|
||
|
index = Mathf.Clamp(index, 0, TimeLineEvents.Count - 1);
|
||
|
//StepEvents[index]?.Invoke();
|
||
|
TimeLineEvents[index]?.Invoke();
|
||
|
//StartCoroutine(executeStepRoutine(index));
|
||
|
}
|
||
|
|
||
|
/// <summary>Advance to next step and execute its event.</summary>
|
||
|
public void AdvanceActivate()
|
||
|
{
|
||
|
stepIndex++;
|
||
|
//int next = Mathf.Clamp(stepIndex + 1, 0, Mathf.Max(0, (StepEvents?.Count ?? 1) - 1));
|
||
|
//stepIndex = next;
|
||
|
//ExecuteStep(stepIndex);
|
||
|
}
|
||
|
|
||
|
/// <summary>
|
||
|
/// Rebuild state after load: execute steps 0..target in order.
|
||
|
/// Call this from ES3 load after setting stepIndex.
|
||
|
/// </summary>
|
||
|
public void ReplayTo(int target)
|
||
|
{
|
||
|
StartCoroutine(ReplayToCoroutine(target));
|
||
|
////if (StepEvents == null || StepEvents.Count == 0) return;
|
||
|
//// target = Mathf.Clamp(target, 0, StepEvents.Count - 1);
|
||
|
//loadedStepIndex = stepIndex;
|
||
|
//if (stepIndex < 0) return;
|
||
|
//target = stepIndex;
|
||
|
//for (int i = 0; i <= target; i++) ExecuteStep(i);
|
||
|
//// stepIndex = target;
|
||
|
//stepIndex = loadedStepIndex;
|
||
|
}
|
||
|
IEnumerator ReplayToCoroutine(int target)
|
||
|
{
|
||
|
loadedStepIndex = stepIndex;
|
||
|
if (stepIndex > 0)
|
||
|
target = stepIndex;
|
||
|
for (int i = 0; i <= target; i++)
|
||
|
{
|
||
|
yield return new WaitForSeconds(0.03f);
|
||
|
ExecuteStep(i);
|
||
|
}
|
||
|
|
||
|
// stepIndex = target;
|
||
|
stepIndex = loadedStepIndex;
|
||
|
ES3SingleStore.LoadObjectives();
|
||
|
yield return null;
|
||
|
}
|
||
|
}
|