EnergyEfficiencyManagement/Assets/SKFramework/Core/Task/TaskStep.cs

94 lines
2.2 KiB
C#

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<TaskStep> OnStepStarted;
public event Action<TaskStep> OnStepHint;
public event Action<TaskStep> OnStepCompleted;
public event Action<TaskStep> OnStepError;
public event Action<TaskStep> 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);
}
/// <summary>
/// 被 TaskData 调用,记录本 Step 的完成状态
/// </summary>
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;
}
}
}