using UnityEngine; using SK.Framework; using System; using System.Collections.Generic; public class TaskExample_Bool : MonoBehaviour { private TaskData _task; List testList=new List(); /// /// 当前期望输入的 Step 索引(0-based) /// 仅用于示例判断“是否按对”,不控制流程 /// public int _expectStepIndex = 0; List objs= new List(); void Start() { //gameObject.Activate(); //gameObject.Deactivate(); //objs.ForEach((value) => { value.Deactivate(); }); ///transform.SetEulerAngles(0, 0, 0); this.Concurrent() .Event(() => Debug.Log("Begin")) .Delay(1f, () => Debug.Log("1f")) .Delay(2f, () => Debug.Log("2f")) .Delay(3f, () => Debug.Log("3f")) .Until(() => Input.GetKeyDown(KeyCode.A)) .OnStop(() => Debug.Log("Completed")) .Begin(); _task = new TaskData { TaskId = "Task_01", TaskName = "状态驱动示例任务", TaskDescription = "按下数字键1-5依次完成五个操作步骤" }; AddStep(1, "步骤1 down"); AddStep(2, "步骤2 down"); AddStep(3, "步骤3 down"); AddStep(4, "步骤4 down"); AddStep(5, "步骤5 down"); _task.OnTaskStarted += OnTaskStarted; TaskManager.Instance.SetMode(TaskMode.Exam); TaskManager.Instance.AddTask(_task); TaskManager.Instance.Start(); } /// /// 添加 Step /// private void AddStep(int stepId, string desc) { var step = new TaskStep { StepId = stepId, Description = desc }; step.OnStepStarted += s => { Debug.Log($"【Step 开始】{s.Description}"); }; step.OnStepHint += s => { Debug.Log($"【提示】{s.Description}"); }; step.OnStepCompleted += s => { Debug.Log($"【Step 正确完成】{s.Description}"); }; step.OnStepError += s => { Debug.LogWarning($"【Step 错误完成】{s.Description}"); }; step.OnStepSkipped += s => { Debug.LogWarning($"【Step 跳过】{s.Description}"); }; _task.Steps.Add(step); } /// /// 任务开始时重置示例状态 /// private void OnTaskStarted(TaskData task) { Debug.Log("任务开始,等待操作输入"); _expectStepIndex = 0; } void Update() { // Task 系统 Tick(目前只是占位) TaskManager.Instance.Tick(); CheckInput(KeyCode.Alpha1, 0); CheckInput(KeyCode.Alpha2, 1); CheckInput(KeyCode.Alpha3, 2); CheckInput(KeyCode.Alpha4, 3); CheckInput(KeyCode.Alpha5, 4); } /// /// 检查输入并汇报 Step 结果 /// private void CheckInput(KeyCode key, int inputStepIndex) { if (!Input.GetKeyDown(key)) return; bool isError = inputStepIndex != _expectStepIndex; if (isError) { Debug.LogWarning( $"输入错误:期望步骤 {_expectStepIndex + 1},却按下了 {inputStepIndex + 1}"); } else { Debug.Log($"输入正确:步骤 {_expectStepIndex + 1}"); } //发送当前 Step 结果(并自动进入下一个) TaskManager.Instance.ReportCurrentStepResult(isError); // 示例逻辑:变更判定条件,开始判定下一个 _expectStepIndex++; } }