154 lines
4.2 KiB
C#
154 lines
4.2 KiB
C#
using System.Collections;
|
||
using System.Collections.Generic;
|
||
using UnityEngine;
|
||
using SK.Framework;
|
||
|
||
/// <summary>
|
||
/// 操作流程
|
||
/// </summary>
|
||
public class EquipmentProcessExample_TSQ : MonoSingleton<EquipmentProcessExample_TSQ>
|
||
{
|
||
public TaskData EquipmentProcess_Task;
|
||
/// <summary>
|
||
/// 当前期望输入的 Step 索引(0-based)
|
||
/// 仅用于示例判断“是否按对”,不控制流程
|
||
/// </summary>
|
||
public int _expectStepIndex = 1;
|
||
public 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();
|
||
|
||
EquipmentProcess_Task = new TaskData
|
||
{
|
||
TaskId = "Task_01",
|
||
TaskName = "原则:先让水循环起来,最后启动压缩机",
|
||
TaskDescription = "1、冷却塔风机。先开启冷却塔风机,为后续的冷却水循环建立散热条件。如果冷却塔有多个风扇,通常按需逐台开启"
|
||
};
|
||
|
||
|
||
foreach (var item in GetComponentsInChildren<EquipmentIIntroduction_TSQ>())
|
||
{
|
||
foreach (var itemstep in item.taskStep)
|
||
{
|
||
AddStep(itemstep);
|
||
}
|
||
}
|
||
BubbleSortList();
|
||
|
||
|
||
EquipmentProcess_Task.OnTaskStarted += OnTaskStarted;
|
||
|
||
TaskManager.Instance.SetMode(TaskMode.Exam);
|
||
TaskManager.Instance.AddTask(EquipmentProcess_Task);
|
||
TaskManager.Instance.Start();
|
||
|
||
}
|
||
void BubbleSortList()
|
||
{
|
||
for (int i = 0; i < EquipmentProcess_Task.Steps.Count - 1; i++)
|
||
{
|
||
for (int j = 0; j < EquipmentProcess_Task.Steps.Count - 1 - i; j++)
|
||
{
|
||
if (EquipmentProcess_Task.Steps[j].StepId > EquipmentProcess_Task.Steps[j + 1].StepId)
|
||
{
|
||
TaskStep temp = EquipmentProcess_Task.Steps[j];
|
||
EquipmentProcess_Task.Steps[j] = EquipmentProcess_Task.Steps[j + 1];
|
||
EquipmentProcess_Task.Steps[j + 1] = temp;
|
||
}
|
||
}
|
||
}
|
||
}
|
||
|
||
/// <summary>
|
||
/// 添加 Step
|
||
/// </summary>
|
||
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}");
|
||
};
|
||
EquipmentProcess_Task.Steps.Add(step);
|
||
}
|
||
/// <summary>
|
||
/// 添加 Step
|
||
/// </summary>
|
||
private void AddStep(TaskStep step)
|
||
{
|
||
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}");
|
||
};
|
||
EquipmentProcess_Task.Steps.Add(step);
|
||
}
|
||
|
||
|
||
/// <summary>
|
||
/// 任务开始时重置示例状态
|
||
/// </summary>
|
||
private void OnTaskStarted(TaskData task)
|
||
{
|
||
Debug.Log("任务开始,等待操作输入");
|
||
_expectStepIndex = 1;
|
||
}
|
||
}
|