using System; using UnityEngine; namespace SK.Framework { public enum StepResult { None, Correct, Error, Skipped } public class TaskStep { public int StepId; public string Description; public event Action OnStepStarted; public event Action OnStepHint; public event Action OnStepCompleted; public event Action OnStepError; public event Action OnStepSkipped; private bool _started; private bool _completed; private bool _isError; public bool IsError => _isError; public StepResult Result { get; private set; } = StepResult.None; public void Start(bool allowHint) { if (_started) return; _started = true; Debug.Log($"[Step] 开始 {StepId}: {Description}"); OnStepStarted?.Invoke(this); if (allowHint) OnStepHint?.Invoke(this); } /// /// 被 TaskData 调用,记录本 Step 的完成状态 /// public void Complete(bool isError) { if (_completed) return; _completed = true; _isError = isError; if (isError) { Debug.Log($"[Step] 错误 {StepId}"); CompleteInternal(StepResult.Error); OnStepError?.Invoke(this); } else { Debug.Log($"[Step] 正确 {StepId}"); CompleteInternal(StepResult.Correct); OnStepCompleted?.Invoke(this); } } public void Skip() { CompleteInternal(StepResult.Skipped); OnStepSkipped?.Invoke(this); } public void Reset() { _started = false; _completed = false; _isError = false; } private void CompleteInternal(StepResult result) { if (_completed) return; _completed = true; Result = result; } } }