EnergyEfficiencyManagement/Assets/Zion/Scripts/TSQManager/EquipmentProcessExample_TSQ.cs

186 lines
7.1 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using SK.Framework;
using UnityEngine.UI;
/// <summary>
/// 操作流程
/// </summary>
public class EquipmentProcessExample_TSQ : MonoSingleton<EquipmentProcessExample_TSQ>
{
public TaskData EquipmentProcess_Task;
public EquipmentIIntroduction_TSQ currentEquipment;
/// <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();
InitButtonAction();
}
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;
}
private void InitButtonAction()
{
UIView.Get<EquipmentSimulationView>().variables.Get<Button>("启动运行-冷却塔风机1").onClick.AddListener(() => { SetStep(true); });
UIView.Get<EquipmentSimulationView>().variables.Get<Button>("停止运行-冷却塔风机1").onClick.AddListener(() => { SetStep(false); });
UIView.Get<EquipmentSimulationView>().variables.Get<Button>("启动运行-风机盘管1").onClick.AddListener(() => { SetStep(true); });
UIView.Get<EquipmentSimulationView>().variables.Get<Button>("停止运行-风机盘管1").onClick.AddListener(() => { SetStep(false); });
UIView.Get<EquipmentSimulationView>().variables.Get<Button>("启动运行-风机盘管2").onClick.AddListener(() => { SetStep(true); });
UIView.Get<EquipmentSimulationView>().variables.Get<Button>("停止运行-风机盘管2").onClick.AddListener(() => { SetStep(false); });
UIView.Get<EquipmentSimulationView>().variables.Get<Button>("启动运行-冷却泵2").onClick.AddListener(() => { SetStep(true); });
UIView.Get<EquipmentSimulationView>().variables.Get<Button>("停止运行-冷却泵2").onClick.AddListener(() => { SetStep(false); });
UIView.Get<EquipmentSimulationView>().variables.Get<Button>("启动运行-冷却泵1").onClick.AddListener(() => { SetStep(true); });
UIView.Get<EquipmentSimulationView>().variables.Get<Button>("停止运行-冷却泵1").onClick.AddListener(() => { SetStep(false); });
UIView.Get<EquipmentSimulationView>().variables.Get<Button>("启动运行-冷却塔风机2").onClick.AddListener(() => { SetStep(true); });
UIView.Get<EquipmentSimulationView>().variables.Get<Button>("停止运行-冷却塔风机2").onClick.AddListener(() => { SetStep(false); });
UIView.Get<EquipmentSimulationView>().variables.Get<Button>("启动运行-中央空调主机").onClick.AddListener(() => { SetStep(true); });
UIView.Get<EquipmentSimulationView>().variables.Get<Button>("停止运行-中央空调主机").onClick.AddListener(() => { SetStep(false); });
}
private void SetStep(bool state)
{
if (EquipmentProcessExample_TSQ.Instance._expectStepIndex > EquipmentProcessExample_TSQ.Instance.EquipmentProcess_Task.Steps.Count) return;
bool isError = currentEquipment.currentStep != EquipmentProcessExample_TSQ.Instance._expectStepIndex;
TaskManager.Instance.ReportCurrentStepResult(isError);
ScoreManager.Instance.GetScoreBaseBySchemeID(GameManager.RunModelMgr.schemeID).steps[EquipmentProcessExample_TSQ.Instance._expectStepIndex].SetScore(!isError);
EquipmentProcessExample_TSQ.Instance._expectStepIndex++;
currentEquipment.currentStep = currentEquipment.secondStep;
currentEquipment.currentState = state;
}
}