1508 lines
57 KiB
C#
1508 lines
57 KiB
C#
using DG.Tweening;
|
||
using OfficeOpenXml.FormulaParsing.Excel.Functions.Logical;
|
||
using SK.Framework;
|
||
using System;
|
||
using System.Collections;
|
||
using System.Collections.Generic;
|
||
using UnityEngine;
|
||
using UnityEngine.UI;
|
||
using XCharts.Runtime;
|
||
|
||
/// <summary>
|
||
/// 设备模拟界面,用于展示设备运行工况参数、高能耗场景参数和改造方案参数,并提供参数输入功能。
|
||
/// </summary>
|
||
public class EquipmentSimulationView : UIView
|
||
{
|
||
public Variables variables;
|
||
//设备模型
|
||
private List<GameObject> devices = new List<GameObject>();
|
||
//设备运行工况参数面板
|
||
private List<GameObject> equipmentRuningInfo = new List<GameObject>();
|
||
//设备高能耗场景参数面板
|
||
private List<GameObject> equipmentUsingInfo = new List<GameObject>();
|
||
//设备改造方案参数面板
|
||
private List<GameObject> equipmentRepareInfo = new List<GameObject>();
|
||
//参数面板
|
||
private List<GameObject> parameterInfo = new List<GameObject>();
|
||
//空调参数输入框
|
||
private List<InputField> inputFields_ac = new List<InputField>();
|
||
//水泵参数输入框
|
||
private List<InputField> inputFields_pump = new List<InputField>();
|
||
//空压机参数输入框
|
||
private List<InputField> inputFields_acp = new List<InputField>();
|
||
|
||
private string repare_ac_name = "";
|
||
private string repare_pump_name = "";
|
||
private string repare_acp_name = "";
|
||
|
||
public List<Button> deviceBtns = new List<Button>();
|
||
[System.Serializable]
|
||
public class ButtonData
|
||
{
|
||
public Sprite normalSprite;
|
||
public Sprite selectedSprite;
|
||
}
|
||
public List<ButtonData> buttonData = new List<ButtonData>();
|
||
// 运行时使用的字典
|
||
private Dictionary<Button, ButtonData> buttonDictionary = new Dictionary<Button, ButtonData>();
|
||
private Button _currentSelectedButton;
|
||
|
||
private EnhancedModelViewerOrbitCamera enhancedModelViewerOrbitCamera;
|
||
|
||
public List<ButtonData> modeData = new List<ButtonData>();
|
||
|
||
#region 打字动画
|
||
//打字动画协程句柄,防止重复打字导致打字动画卡顿问题
|
||
private Coroutine typingCoroutine;
|
||
//打字动画速度,单位:秒/字符
|
||
private float typingSpeed = 0.05f;
|
||
#endregion
|
||
|
||
/// <summary>
|
||
/// 设备开启面板
|
||
/// </summary>
|
||
public List<RectTransform> AllPanel;
|
||
/// <summary>
|
||
/// 判断当前状态是打开还是关闭
|
||
/// </summary>
|
||
public List<bool> Stepbools;
|
||
protected override void OnInit(IViewData data)
|
||
{
|
||
base.OnInit(data);
|
||
variables.Set<EquipmentSimulationView>("my_EquipmentSimulation", this);
|
||
|
||
enhancedModelViewerOrbitCamera = Camera.main.GetComponent<EnhancedModelViewerOrbitCamera>();
|
||
|
||
devices.Clear();
|
||
GameObject trans = GameObject.Find("AllModels");
|
||
if (trans != null)
|
||
{
|
||
for (int i = 0; i < trans.transform.childCount; i++)
|
||
{
|
||
devices.Add(trans.transform.GetChild(i).gameObject);
|
||
devices[i].SetActive(false);
|
||
}
|
||
}
|
||
|
||
devices.RemoveAt(0);
|
||
devices[0].Activate();
|
||
|
||
InitLeftBtns();
|
||
SetSelectedButton(deviceBtns[0]);
|
||
|
||
ListInit();
|
||
DropdownInit();
|
||
//SimulationSelectInit();
|
||
BtnClickInit();
|
||
ToggleInit();
|
||
lineChart = variables.Get<RectTransform>("LineChart").GetComponent<LineChart>();
|
||
}
|
||
|
||
/// <summary>
|
||
/// 列表初始化,暂时没用到,留着以防万一
|
||
/// </summary>
|
||
private void ListInit()
|
||
{
|
||
equipmentRuningInfo.Clear();
|
||
equipmentUsingInfo.Clear();
|
||
equipmentRepareInfo.Clear();
|
||
parameterInfo.Clear();
|
||
|
||
equipmentRuningInfo.Add(variables.Get<GameObject>("参数面板-空调"));
|
||
equipmentRuningInfo.Add(variables.Get<GameObject>("参数面板-水泵"));
|
||
equipmentRuningInfo.Add(variables.Get<GameObject>("参数面板-空压机"));
|
||
|
||
equipmentUsingInfo.Add(variables.Get<GameObject>("空调-高能耗"));
|
||
equipmentUsingInfo.Add(variables.Get<GameObject>("水泵-高能耗"));
|
||
equipmentUsingInfo.Add(variables.Get<GameObject>("空压机-高能耗"));
|
||
|
||
equipmentRepareInfo.Add(variables.Get<GameObject>("改造方案-空调"));
|
||
equipmentRepareInfo.Add(variables.Get<GameObject>("改造方案-水泵"));
|
||
equipmentRepareInfo.Add(variables.Get<GameObject>("改造方案-空压机"));
|
||
|
||
parameterInfo.Add(variables.Get<GameObject>("运行工况参数面板"));
|
||
parameterInfo.Add(variables.Get<GameObject>("高耗能场景参数面板"));
|
||
parameterInfo.Add(variables.Get<GameObject>("改造方案"));
|
||
|
||
|
||
inputFields_ac.Clear();
|
||
inputFields_pump.Clear();
|
||
inputFields_acp.Clear();
|
||
|
||
inputFields_ac.Add(variables.Get<InputField>("堵塞输入框"));
|
||
inputFields_ac.Add(variables.Get<InputField>("泄露输入框"));
|
||
inputFields_ac.Add(variables.Get<InputField>("故障输入框"));
|
||
|
||
inputFields_pump.Add(variables.Get<InputField>("预设阀门异常输入框"));
|
||
inputFields_pump.Add(variables.Get<InputField>("叶轮磨损输入框"));
|
||
inputFields_pump.Add(variables.Get<InputField>("管路堵塞输入框"));
|
||
|
||
inputFields_acp.Add(variables.Get<InputField>("压力输入框"));
|
||
inputFields_acp.Add(variables.Get<InputField>("泄漏量输入框"));
|
||
inputFields_acp.Add(variables.Get<InputField>("电机过载输入框"));
|
||
}
|
||
|
||
/// <summary>
|
||
/// 设备选择初始化
|
||
/// </summary>
|
||
private void DropdownInit()
|
||
{
|
||
//variables.Get<Dropdown>("设备列表").onValueChanged.AddListener((index) => OnEquipmentSelectChanged(index));
|
||
variables.Get<Dropdown>("下拉框-空调-运行工况").onValueChanged.AddListener((index) => AcRuningDpValueChanged(index));
|
||
variables.Get<Dropdown>("下拉框-空调-高能耗").onValueChanged.AddListener((index) => AcUsingDpValueChanged(index, inputFields_ac));
|
||
variables.Get<Dropdown>("下拉框-水泵-高能耗").onValueChanged.AddListener((index) => AcUsingDpValueChanged(index, inputFields_pump));
|
||
variables.Get<Dropdown>("下拉框-空压机-高能耗").onValueChanged.AddListener((index) => AcUsingDpValueChanged(index, inputFields_acp));
|
||
variables.Get<Dropdown>("下拉框-空调-改造方案").onValueChanged.AddListener((index) => OnRepareCheck(index, 0));
|
||
variables.Get<Dropdown>("下拉框-水泵-改造方案").onValueChanged.AddListener((index) => OnRepareCheck(index, 1));
|
||
variables.Get<Dropdown>("下拉框-空压机-改造方案").onValueChanged.AddListener((index) => OnRepareCheck(index, 2));
|
||
}
|
||
|
||
/// <summary>
|
||
/// 模拟场景选择初始化
|
||
/// </summary>
|
||
private void SimulationSelectInit()
|
||
{
|
||
/*
|
||
Toggle[] toggles = variables.Get<ToggleGroup>("模式选择").GetComponentsInChildren<Toggle>();
|
||
for (int i = 0; i < toggles.Length; i++)
|
||
{
|
||
int index = i;
|
||
toggles[i].onValueChanged.AddListener((isOn) => OnSimulationSelectChanged(isOn, index));
|
||
}*/
|
||
}
|
||
|
||
/// <summary>
|
||
/// 模拟场景选择改变事件回调函数
|
||
/// </summary>
|
||
/// <param name="index"></param>
|
||
private void OnSimulationSelectChanged(int index)
|
||
{
|
||
//if (isOn)
|
||
{
|
||
//Debug.Log($"{index},{parameterInfo.Count}");
|
||
for (int i = 0; i < parameterInfo.Count; i++)
|
||
{
|
||
if (i == index)
|
||
{
|
||
parameterInfo[i].Activate();
|
||
}
|
||
else
|
||
{
|
||
parameterInfo[i].Deactivate();
|
||
}
|
||
}
|
||
}
|
||
}
|
||
|
||
/// <summary>
|
||
/// 设备选择改变事件回调函数,根据选择的设备显示对应的参数面板和改造方案信息面板。
|
||
/// </summary>
|
||
/// <param name="index"></param>
|
||
private void OnEquipmentSelectChanged(int index)
|
||
{
|
||
if (index < 0 || index > equipmentRuningInfo.Count)
|
||
{
|
||
ShowWarming($"数组越界异常!请检查设备列表索引是否正确!{index}_{equipmentRuningInfo.Count}");
|
||
return;
|
||
}
|
||
for (int i = 0; i < equipmentRuningInfo.Count; i++)
|
||
{
|
||
if (i == index)
|
||
{
|
||
equipmentRuningInfo[i].Activate();
|
||
equipmentUsingInfo[i].Activate();
|
||
equipmentRepareInfo[i].Activate();
|
||
}
|
||
else
|
||
{
|
||
equipmentRuningInfo[i].Deactivate();
|
||
equipmentUsingInfo[i].Deactivate();
|
||
equipmentRepareInfo[i].Deactivate();
|
||
}
|
||
}
|
||
}
|
||
|
||
|
||
#region 切换设备
|
||
|
||
void InitLeftBtns()
|
||
{
|
||
|
||
// 初始化字典
|
||
for (int i = 0; i < deviceBtns.Count; i++)
|
||
{
|
||
buttonDictionary[deviceBtns[i]] = buttonData[i];
|
||
|
||
SetNormal(deviceBtns[i], buttonData[i]);
|
||
|
||
// 添加点击事件
|
||
int index = i; // 闭包需要
|
||
deviceBtns[i].onClick.AddListener(() => OnButtonSelected(deviceBtns[index], index));
|
||
}
|
||
|
||
// 设置默认选中
|
||
if (deviceBtns.Count > 0)
|
||
{
|
||
SetSelectedButton(deviceBtns[0]);
|
||
}
|
||
}
|
||
|
||
private void OnButtonSelected(Button selectedButton, int index)
|
||
{
|
||
if (_currentSelectedButton == selectedButton) return;
|
||
|
||
// 取消上一个按钮的选中
|
||
if (_currentSelectedButton != null && buttonDictionary.ContainsKey(_currentSelectedButton))
|
||
{
|
||
SetNormal(_currentSelectedButton, buttonDictionary[_currentSelectedButton]);
|
||
}
|
||
|
||
OnEquipmentSelectChanged(index);
|
||
|
||
for (int i = 0; i < devices.Count; i++)
|
||
{
|
||
if (i == index)
|
||
{
|
||
devices[i].Activate();
|
||
Debug.Log("_____________+_____________");
|
||
ShowPanel(selectedButton.name);
|
||
enhancedModelViewerOrbitCamera.SetTarget(devices[i].transform);
|
||
}
|
||
else
|
||
{
|
||
devices[i].Deactivate();
|
||
Debug.Log("+++++++++++++++");
|
||
|
||
// 设置新按钮的选中
|
||
SetSelectedButton(selectedButton);
|
||
}
|
||
}
|
||
}
|
||
|
||
public void ShowPanel(string BtnName)
|
||
{
|
||
switch (BtnName)
|
||
{
|
||
case "空调":
|
||
UIView.Get<EquipmentSimulationView>().variables.Get<RectTransform>("楼层").Activate();
|
||
UIView.Get<EquipmentSimulationView>().variables.Get<RectTransform>("参数面板空调").Activate();
|
||
UIView.Get<EquipmentSimulationView>().variables.Get<RectTransform>("参数面板水泵").Deactivate();
|
||
UIView.Get<EquipmentSimulationView>().variables.Get<RectTransform>("空调操作步骤").Activate();
|
||
UIView.Get<EquipmentSimulationView>().variables.Get<GameObject>("togglegroup").Deactivate();
|
||
UIView.Get<EquipmentSimulationView>().variables.Get<RectTransform>("参数面板空调").Activate();
|
||
UIView.Get<EquipmentSimulationView>().variables.Get<GameObject>("一键启停-空压机").Deactivate();
|
||
UIView.Get<EquipmentSimulationView>().variables.Get<GameObject>("一键启停-泵").Deactivate();
|
||
break;
|
||
case "泵":
|
||
UIView.Get<EquipmentSimulationView>().variables.Get<RectTransform>("楼层").Deactivate();
|
||
UIView.Get<EquipmentSimulationView>().variables.Get<RectTransform>("参数面板空调").Deactivate();
|
||
UIView.Get<EquipmentSimulationView>().variables.Get<RectTransform>("参数面板水泵").Deactivate();
|
||
UIView.Get<EquipmentSimulationView>().variables.Get<RectTransform>("空调操作步骤").Deactivate();
|
||
UIView.Get<EquipmentSimulationView>().variables.Get<GameObject>("togglegroup").Activate();
|
||
UIView.Get<EquipmentSimulationView>().variables.Get<RectTransform>("参数面板空调").Deactivate();
|
||
UIView.Get<EquipmentSimulationView>().variables.Get<GameObject>("一键启停-空压机").Deactivate();
|
||
UIView.Get<EquipmentSimulationView>().variables.Get<GameObject>("一键启停-泵").Activate();
|
||
BengPanel();
|
||
break;
|
||
case "空压机":
|
||
UIView.Get<EquipmentSimulationView>().variables.Get<RectTransform>("楼层").Deactivate();
|
||
UIView.Get<EquipmentSimulationView>().variables.Get<RectTransform>("参数面板空调").Deactivate();
|
||
UIView.Get<EquipmentSimulationView>().variables.Get<RectTransform>("参数面板水泵").Deactivate();
|
||
UIView.Get<EquipmentSimulationView>().variables.Get<RectTransform>("空调操作步骤").Deactivate();
|
||
UIView.Get<EquipmentSimulationView>().variables.Get<GameObject>("togglegroup").Activate();
|
||
UIView.Get<EquipmentSimulationView>().variables.Get<RectTransform>("参数面板空调").Deactivate();
|
||
UIView.Get<EquipmentSimulationView>().variables.Get<GameObject>("一键启停-空压机").Activate();
|
||
UIView.Get<EquipmentSimulationView>().variables.Get<GameObject>("一键启停-泵").Deactivate();
|
||
FengJiPanel();
|
||
break;
|
||
default:
|
||
break;
|
||
}
|
||
}
|
||
public void SetSelectedButton(Button button)
|
||
{
|
||
if (!buttonDictionary.ContainsKey(button))
|
||
{
|
||
Debug.LogWarning($"按钮 {button.name} 不在管理列表中");
|
||
return;
|
||
}
|
||
|
||
_currentSelectedButton = button;
|
||
|
||
SetHightlight(button, buttonDictionary[button]);
|
||
}
|
||
|
||
#endregion
|
||
|
||
/// <summary>
|
||
/// 空调运行工况下拉框改变事件回调函数,根据选择的运行模式显示对应的输入框。
|
||
/// </summary>
|
||
/// <param name="index"></param>
|
||
private void AcRuningDpValueChanged(int index)
|
||
{
|
||
if (index == 2)
|
||
{
|
||
variables.Get<InputField>("风速输入框").Activate();
|
||
variables.Get<InputField>("温度输入框").Deactivate();
|
||
}
|
||
else
|
||
{
|
||
variables.Get<InputField>("风速输入框").Deactivate();
|
||
variables.Get<InputField>("温度输入框").Activate();
|
||
}
|
||
}
|
||
|
||
/// <summary>
|
||
/// 空调高能耗下拉框改变事件回调函数
|
||
/// </summary>
|
||
/// <param name="index"></param>
|
||
private void AcUsingDpValueChanged(int index, List<InputField> target)
|
||
{
|
||
if (index < 0 || index > target.Count)
|
||
{
|
||
ShowWarming("索引越界");
|
||
//Debug.LogError($"索引越界_{index}_{target.Count}");
|
||
return;
|
||
}
|
||
for (int i = 0; i < target.Count; i++)
|
||
{
|
||
if (target[i] != null)
|
||
{
|
||
if (i == index)
|
||
target[i].Activate();
|
||
else
|
||
target[i].Deactivate();
|
||
}
|
||
}
|
||
}
|
||
|
||
/// <summary>
|
||
/// 改造方案下拉框改变事件回调函数,获取选择的改造方案名称
|
||
/// </summary>
|
||
/// <param name="index"></param>
|
||
private void OnRepareCheck(int index, int type)
|
||
{
|
||
switch (type)
|
||
{
|
||
case 0:
|
||
repare_ac_name = variables.Get<Dropdown>("下拉框-空调-改造方案").options[index].text;
|
||
break;
|
||
case 1:
|
||
repare_pump_name = variables.Get<Dropdown>("下拉框-水泵-改造方案").options[index].text;
|
||
break;
|
||
case 2:
|
||
repare_acp_name = variables.Get<Dropdown>("下拉框-空压机-改造方案").options[index].text;
|
||
break;
|
||
}
|
||
}
|
||
|
||
/// <summary>
|
||
/// 按钮点击事件初始化
|
||
/// </summary>
|
||
private void BtnClickInit()
|
||
{
|
||
/**/
|
||
variables.Get<Button>("运行工况模拟").onClick.AddListener(delegate
|
||
{
|
||
SetHightlight(variables.Get<Button>("运行工况模拟"), modeData[0]);
|
||
SetNormal(variables.Get<Button>("高耗能场景模拟"), modeData[1]);
|
||
SetNormal(variables.Get<Button>("节能改造实操"), modeData[2]);
|
||
|
||
OnSimulationSelectChanged(0);
|
||
//OnEquipmentSelectChanged(0);
|
||
});
|
||
variables.Get<Button>("高耗能场景模拟").onClick.AddListener(delegate
|
||
{
|
||
SetNormal(variables.Get<Button>("运行工况模拟"), modeData[0]);
|
||
SetHightlight(variables.Get<Button>("高耗能场景模拟"), modeData[1]);
|
||
SetNormal(variables.Get<Button>("节能改造实操"), modeData[2]);
|
||
OnSimulationSelectChanged(1);
|
||
//OnEquipmentSelectChanged(1);
|
||
});
|
||
variables.Get<Button>("节能改造实操").onClick.AddListener(delegate
|
||
{
|
||
SetNormal(variables.Get<Button>("运行工况模拟"), modeData[0]);
|
||
SetNormal(variables.Get<Button>("高耗能场景模拟"), modeData[1]);
|
||
SetHightlight(variables.Get<Button>("节能改造实操"), modeData[2]);
|
||
OnSimulationSelectChanged(2);
|
||
//OnEquipmentSelectChanged(2);
|
||
});
|
||
SetHightlight(variables.Get<Button>("运行工况模拟"), modeData[0]);
|
||
variables.Get<Button>("启动运行-空调-运行工况").onClick.AddListener(delegate
|
||
{
|
||
AcRuning();
|
||
});
|
||
variables.Get<Button>("启动运行-空调-高能耗").onClick.AddListener(delegate
|
||
{
|
||
RuningCheck(inputFields_ac);
|
||
});
|
||
variables.Get<Button>("启动运行-水泵-高能耗").onClick.AddListener(delegate
|
||
{
|
||
RuningCheck(inputFields_pump);
|
||
});
|
||
variables.Get<Button>("启动运行-空压机-高能耗").onClick.AddListener(delegate
|
||
{
|
||
RuningCheck(inputFields_acp);
|
||
});
|
||
variables.Get<Button>("启动改造-空调-改造方案").onClick.AddListener(delegate
|
||
{
|
||
RepareCheck(0);
|
||
});
|
||
variables.Get<Button>("启动改造-水泵-改造方案").onClick.AddListener(delegate
|
||
{
|
||
RepareCheck(1);
|
||
});
|
||
variables.Get<Button>("启动改造-空压机-改造方案").onClick.AddListener(delegate
|
||
{
|
||
RepareCheck(2);
|
||
});
|
||
|
||
|
||
variables.Get<Button>("关闭界面").onClick.AddListener(delegate
|
||
{
|
||
Unload();
|
||
Load<TypicalEnergyHomeView>();
|
||
});
|
||
//开启
|
||
variables.Get<Button>("启动运行-冷却塔风机1").onClick.AddListener(delegate
|
||
{
|
||
Stepbools[0] = true;
|
||
SBStartOperation("开启冷却塔风机1成功");
|
||
StartCoroutine(EquipmentIIntroduction_TSQ.instance.AutoHide(4, "参数面板-冷却塔风机1"));
|
||
});
|
||
variables.Get<Button>("启动运行-冷却塔风机2").onClick.AddListener(delegate
|
||
{
|
||
Stepbools[1] = true;
|
||
SBStartOperation("开启冷却塔风机2成功");
|
||
StartCoroutine(EquipmentIIntroduction_TSQ.instance.AutoHide(4, "参数面板-冷却塔风机2"));
|
||
});
|
||
|
||
variables.Get<Button>("启动运行-冷却泵1").onClick.AddListener(delegate
|
||
{
|
||
if (variables.Get<Toggle>("水流开关1").isOn == true)
|
||
{
|
||
Stepbools[2] = true;
|
||
SBStartOperation("启动运行-冷却泵成功");
|
||
StartCoroutine(EquipmentIIntroduction_TSQ.instance.AutoHide(4, "参数面板-冷却泵1"));
|
||
}
|
||
else
|
||
{
|
||
ShowWarming("启动水泵前请打开水流开关");
|
||
}
|
||
|
||
});
|
||
variables.Get<Button>("启动运行-冷却泵2").onClick.AddListener(delegate
|
||
{
|
||
if (variables.Get<Toggle>("水流开关2").isOn == true)
|
||
{
|
||
Stepbools[3] = true;
|
||
SBStartOperation("启动运行-冷却泵成功");
|
||
StartCoroutine(EquipmentIIntroduction_TSQ.instance.AutoHide(4, "参数面板-冷却泵2"));
|
||
}
|
||
else
|
||
{
|
||
ShowWarming("启动水泵前请打开水流开关");
|
||
}
|
||
});
|
||
variables.Get<Button>("启动运行-风机盘管1").onClick.AddListener(delegate
|
||
{
|
||
if (variables.Get<Toggle>("水流开关1").isOn == true && variables.Get<Toggle>("水流开关2").isOn == true)
|
||
{
|
||
Stepbools[4] = true;
|
||
SBStartOperation("启动风机盘管成功");
|
||
StartCoroutine(EquipmentIIntroduction_TSQ.instance.AutoHide(4, "参数面板-风机盘管1"));
|
||
}
|
||
else
|
||
{
|
||
ShowWarming("启动风机盘管前请打开冷冻泵");
|
||
}
|
||
});
|
||
variables.Get<Button>("启动运行-风机盘管2").onClick.AddListener(delegate
|
||
{
|
||
if (variables.Get<Toggle>("水流开关1").isOn == true && variables.Get<Toggle>("水流开关2").isOn == true)
|
||
{
|
||
Stepbools[5] = true;
|
||
SBStartOperation("启动风机盘管成功");
|
||
StartCoroutine(EquipmentIIntroduction_TSQ.instance.AutoHide(4, "参数面板-风机盘管2"));
|
||
}
|
||
else
|
||
{
|
||
ShowWarming("启动风机盘管前请打开冷冻泵");
|
||
}
|
||
});
|
||
variables.Get<Button>("启动运行-中央空调主机").onClick.AddListener(delegate
|
||
{
|
||
Stepbools[6] = true;
|
||
SBStartOperation("开启中央空调主机成功");
|
||
StartCoroutine(EquipmentIIntroduction_TSQ.instance.AutoHide(4, "参数面板-中央空调主机"));
|
||
});
|
||
//关闭
|
||
variables.Get<Button>("停止运行-冷却塔风机1").onClick.AddListener(delegate
|
||
{
|
||
Stepbools[0] = false;
|
||
SBStartOperation("关闭冷却塔风机1成功");
|
||
StartCoroutine(EquipmentIIntroduction_TSQ.instance.AutoHide(4, "参数面板-冷却塔风机1"));
|
||
});
|
||
variables.Get<Button>("停止运行-冷却塔风机2").onClick.AddListener(delegate
|
||
{
|
||
Stepbools[1] = false;
|
||
SBStartOperation("关闭冷却塔风机2成功");
|
||
StartCoroutine(EquipmentIIntroduction_TSQ.instance.AutoHide(4, "参数面板-冷却塔风机2"));
|
||
});
|
||
variables.Get<Button>("停止运行-冷却泵1").onClick.AddListener(delegate
|
||
{
|
||
if (variables.Get<Toggle>("水流开关1").isOn == false)
|
||
{
|
||
Stepbools[2] = false;
|
||
SBStartOperation("停止运行冷却泵1成功");
|
||
StartCoroutine(EquipmentIIntroduction_TSQ.instance.AutoHide(4, "参数面板-冷却泵1"));
|
||
}
|
||
else
|
||
{
|
||
ShowWarming("停止水泵1前请关闭水流开关");
|
||
}
|
||
|
||
});
|
||
variables.Get<Button>("停止运行-冷却泵2").onClick.AddListener(delegate
|
||
{
|
||
if (variables.Get<Toggle>("水流开关2").isOn == false)
|
||
{
|
||
Stepbools[3] = false;
|
||
SBStartOperation("停止运行冷却泵2成功");
|
||
StartCoroutine(EquipmentIIntroduction_TSQ.instance.AutoHide(4, "参数面板-冷却泵2"));
|
||
}
|
||
else
|
||
{
|
||
ShowWarming("停止水泵2前请关闭水流开关");
|
||
}
|
||
});
|
||
variables.Get<Button>("停止运行-风机盘管1").onClick.AddListener(delegate
|
||
{
|
||
if (variables.Get<Toggle>("水流开关1").isOn == false && variables.Get<Toggle>("水流开关2").isOn == false)
|
||
{
|
||
Stepbools[4] = false;
|
||
SBStartOperation("停止风机盘管成功");
|
||
StartCoroutine(EquipmentIIntroduction_TSQ.instance.AutoHide(4, "参数面板-风机盘管1"));
|
||
}
|
||
else
|
||
{
|
||
ShowWarming("关闭风机盘管前请关闭冷冻泵");
|
||
}
|
||
});
|
||
variables.Get<Button>("停止运行-风机盘管2").onClick.AddListener(delegate
|
||
{
|
||
if (variables.Get<Toggle>("水流开关1").isOn == false && variables.Get<Toggle>("水流开关2").isOn == false)
|
||
{
|
||
Stepbools[5] = false;
|
||
SBStartOperation("停止风机盘管成功");
|
||
StartCoroutine(EquipmentIIntroduction_TSQ.instance.AutoHide(4, "参数面板-风机盘管2"));
|
||
}
|
||
else
|
||
{
|
||
ShowWarming("关闭风机盘管前请关闭冷冻泵");
|
||
}
|
||
});
|
||
variables.Get<Button>("停止运行-中央空调主机").onClick.AddListener(delegate
|
||
{
|
||
Stepbools[6] = false;
|
||
SBStartOperation("关闭中央空调主机成功");
|
||
StartCoroutine(EquipmentIIntroduction_TSQ.instance.AutoHide(4, "参数面板-中央空调主机"));
|
||
});
|
||
variables.Get<Button>("启动运行-泵").onClick.AddListener(delegate
|
||
{
|
||
Stepbools[7] = true;
|
||
GameMangner_TSQ.instance.bengStartOrStop(true);
|
||
SBStartOperation("开启泵成功");
|
||
UIView.Get<EquipmentSimulationView>().variables.Get<Text>("泵机Text").text = "关闭泵";
|
||
UIView.Get<EquipmentSimulationView>().variables.Get<Button>("启动运行-泵").Deactivate();
|
||
UIView.Get<EquipmentSimulationView>().variables.Get<Button>("停止运行-泵").Activate();
|
||
//StartCoroutine(EquipmentIIntroduction_TSQ.instance.AutoHide(4, "参数面板-中央空调主机"));
|
||
});
|
||
variables.Get<Button>("停止运行-泵").onClick.AddListener(delegate
|
||
{
|
||
Stepbools[7] = false;
|
||
SBStartOperation("关闭泵成功");
|
||
GameMangner_TSQ.instance.bengStartOrStop(false);
|
||
UIView.Get<EquipmentSimulationView>().variables.Get<Text>("泵机Text").text = "开启泵";
|
||
UIView.Get<EquipmentSimulationView>().variables.Get<Button>("启动运行-泵").Activate();
|
||
UIView.Get<EquipmentSimulationView>().variables.Get<Button>("停止运行-泵").Deactivate();
|
||
//StartCoroutine(EquipmentIIntroduction_TSQ.instance.AutoHide(4, "参数面板-中央空调主机"));
|
||
});
|
||
variables.Get<Button>("启动运行-空压机").onClick.AddListener(delegate
|
||
{
|
||
Stepbools[8] = true;
|
||
SBStartOperation("开启空压机成功");
|
||
GameMangner_TSQ.instance.FengJiStartOrStop(true);
|
||
UIView.Get<EquipmentSimulationView>().variables.Get<Text>("空压机主机Text").text = "关闭空压机";
|
||
UIView.Get<EquipmentSimulationView>().variables.Get<Button>("启动运行-空压机").Deactivate();
|
||
UIView.Get<EquipmentSimulationView>().variables.Get<Button>("停止运行-空压机").Activate();
|
||
//StartCoroutine(EquipmentIIntroduction_TSQ.instance.AutoHide(4, "参数面板-中央空调主机"));
|
||
});
|
||
variables.Get<Button>("停止运行-空压机").onClick.AddListener(delegate
|
||
{
|
||
Stepbools[8] = false;
|
||
SBStartOperation("关闭空压机成功");
|
||
GameMangner_TSQ.instance.FengJiStartOrStop(false);
|
||
UIView.Get<EquipmentSimulationView>().variables.Get<Text>("空压机主机Text").text = "开启空压机";
|
||
UIView.Get<EquipmentSimulationView>().variables.Get<Button>("启动运行-空压机").Activate();
|
||
UIView.Get<EquipmentSimulationView>().variables.Get<Button>("停止运行-空压机").Deactivate();
|
||
//StartCoroutine(EquipmentIIntroduction_TSQ.instance.AutoHide(4, "参数面板-中央空调主机"));
|
||
});
|
||
|
||
variables.Get<Button>("启动改造-空压机-改造方案").onClick.AddListener(delegate
|
||
{
|
||
RepareCheck(2);
|
||
});
|
||
variables.Get<Button>("启动改造-空压机-改造方案").onClick.AddListener(delegate
|
||
{
|
||
RepareCheck(2);
|
||
});
|
||
}
|
||
|
||
/// <summary>
|
||
/// 空调运行工况模拟按钮点击事件回调函数
|
||
/// </summary>
|
||
private void AcRuning()
|
||
{
|
||
//TODO:根据不同温度,风速,运行时长,显示不同的timeline动画
|
||
if (variables.Get<InputField>("温度输入框").gameObject.activeSelf)
|
||
{
|
||
if (string.IsNullOrEmpty(variables.Get<InputField>("温度输入框").text.Trim()))
|
||
{ //TODO:提醒用户输入温度
|
||
ShowWarming("请输入温度值!");
|
||
return;
|
||
}
|
||
else if (!(string.IsNullOrEmpty(variables.Get<InputField>("运行时长输入框").text.Trim())))
|
||
{
|
||
InitializeChart("运行工况", "时间", 5, "温度");
|
||
GenerateTemperatureChart(float.Parse(variables.Get<InputField>("运行时长输入框").text), float.Parse(variables.Get<InputField>("温度输入框").text));
|
||
}
|
||
}
|
||
if (variables.Get<InputField>("风速输入框").gameObject.activeSelf)
|
||
{
|
||
if (string.IsNullOrEmpty(variables.Get<InputField>("风速输入框").text.Trim()))
|
||
{
|
||
//TODO:提醒用户输入风速
|
||
ShowWarming("请输入风速值!");
|
||
return;
|
||
}
|
||
else if (!(string.IsNullOrEmpty(variables.Get<InputField>("运行时长输入框").text.Trim())))
|
||
{
|
||
InitializeChart("运行工况", "时间", 5, "风速");
|
||
GenerateTemperatureChart(float.Parse(variables.Get<InputField>("运行时长输入框").text), float.Parse(variables.Get<InputField>("风速输入框").text));
|
||
}
|
||
}
|
||
if (string.IsNullOrEmpty(variables.Get<InputField>("运行时长输入框").text.Trim()))
|
||
{
|
||
//TODO:提醒用户输入运行时长
|
||
ShowWarming("请输入运行时长!");
|
||
return;
|
||
}
|
||
//TODO:根据输入的参数,播放对应的timeline动画
|
||
|
||
}
|
||
|
||
/// <summary>
|
||
/// 启动检查
|
||
/// </summary>
|
||
/// <param name="target"></param>
|
||
private void RuningCheck(List<InputField> target)
|
||
{
|
||
bool isEnterValue = false;
|
||
foreach (InputField field in target)
|
||
{
|
||
if (field.gameObject.activeSelf)
|
||
{
|
||
if (!string.IsNullOrEmpty(field.text) && !string.IsNullOrWhiteSpace(field.text))
|
||
{
|
||
Debug.Log($"{field.text}");
|
||
isEnterValue = true;
|
||
InitializeChart("能耗变化", "异常参数", 10, "能耗");
|
||
HighenErgyConsumptionChart(float.Parse(field.text));
|
||
}
|
||
}
|
||
}
|
||
if (!isEnterValue)
|
||
{
|
||
//Debug.LogError($"没有键入有效参数!");
|
||
ShowWarming("没有键入有效参数!");
|
||
return;
|
||
}
|
||
//TODO: 显示不同的曲线信息
|
||
|
||
}
|
||
|
||
/// <summary>
|
||
/// 改造检查-空调
|
||
/// </summary>x
|
||
private void RepareCheck(int type)
|
||
{
|
||
switch (type)
|
||
{
|
||
case 0:
|
||
if (string.IsNullOrEmpty(repare_ac_name))
|
||
{
|
||
ShowWarming("请选择改造方案!");
|
||
return;
|
||
}
|
||
lineChart.RemoveData();
|
||
series = new List<Serie>();
|
||
series.Add(InitializeChart_Serie("能耗变化", "异常参数", 10, "改造前"));
|
||
series.Add(InitializeChart_Serie("能耗变化", "异常参数", 10, "改造后"));
|
||
EnergySavingChart(0);
|
||
EnergySavingChart(1);
|
||
break;
|
||
case 1:
|
||
if (string.IsNullOrEmpty(repare_pump_name))
|
||
{
|
||
ShowWarming("请选择改造方案!");
|
||
return;
|
||
}
|
||
series.Add(InitializeChart_Serie("能耗变化", "异常参数", 10, "改造前"));
|
||
series.Add(InitializeChart_Serie("能耗变化", "异常参数", 10, "改造后"));
|
||
EnergySavingChart(0);
|
||
EnergySavingChart(1);
|
||
break;
|
||
case 2:
|
||
if (string.IsNullOrEmpty(repare_acp_name))
|
||
{
|
||
ShowWarming("请选择改造方案!");
|
||
return;
|
||
}
|
||
series.Add(InitializeChart_Serie("能耗变化", "异常参数", 10, "改造前"));
|
||
series.Add(InitializeChart_Serie("能耗变化", "异常参数", 10, "改造后"));
|
||
EnergySavingChart(0);
|
||
EnergySavingChart(1);
|
||
break;
|
||
}
|
||
}
|
||
|
||
#region 图表
|
||
|
||
private Serie serie;
|
||
private LineChart lineChart;
|
||
private List<Serie> series = new List<Serie>();//存储多个series图表
|
||
|
||
/// <summary>
|
||
/// 折线设置
|
||
/// </summary>
|
||
private void InitializeChart(string title, string xAxisName, double yAxisMaxValue, string yAxisName)
|
||
{
|
||
|
||
lineChart.RemoveData();
|
||
|
||
lineChart.EnsureChartComponent<Title>().text = title;
|
||
|
||
// 设置X轴(时间轴)
|
||
var xAxis = lineChart.EnsureChartComponent<XAxis>();
|
||
xAxis.show = true;
|
||
xAxis.type = Axis.AxisType.Value;
|
||
xAxis.min = 0;
|
||
xAxis.axisName.name = xAxisName;
|
||
|
||
// 设置Y轴(温度轴)
|
||
var yAxis = lineChart.EnsureChartComponent<YAxis>();
|
||
yAxis.show = true;
|
||
yAxis.type = Axis.AxisType.Value;
|
||
yAxis.min = 0;
|
||
yAxis.max = yAxisMaxValue;
|
||
yAxis.axisName.name = yAxisName;
|
||
|
||
// 添加折线序列
|
||
serie = lineChart.AddSerie<Line>();
|
||
if (serie != null)
|
||
{
|
||
//serie.serieName = "温度变化";
|
||
serie.serieName = yAxisName;
|
||
serie.symbol.show = true;
|
||
serie.symbol.size = 5f;
|
||
serie.lineType = LineType.Normal;
|
||
serie.lineStyle.width = 3f;
|
||
serie.animation.enable = true;
|
||
|
||
// 设置颜色
|
||
serie.lineStyle.color = Color.red;
|
||
serie.symbol.color = Color.blue;
|
||
}
|
||
|
||
// 设置提示框
|
||
var tooltip = lineChart.GetChartComponent<Tooltip>();
|
||
if (tooltip == null) tooltip = lineChart.AddChartComponent<Tooltip>();
|
||
tooltip.show = true;
|
||
tooltip.type = Tooltip.Type.Line;
|
||
|
||
// 设置图例
|
||
var legend = lineChart.GetChartComponent<Legend>();
|
||
if (legend == null) legend = lineChart.AddChartComponent<Legend>();
|
||
legend.show = true;
|
||
//legend.data = new List<string> { "温度变化" };
|
||
legend.data = new List<string> { yAxisName };
|
||
}
|
||
|
||
/// <summary>
|
||
/// 多个折线设置,返回Serie
|
||
/// </summary>
|
||
private Serie InitializeChart_Serie(string title, string xAxisName, double yAxisMaxValue, string yAxisName)
|
||
{
|
||
// 标题
|
||
lineChart.EnsureChartComponent<Title>().text = title;
|
||
|
||
// X轴
|
||
var xAxis = lineChart.EnsureChartComponent<XAxis>();
|
||
xAxis.show = true;
|
||
xAxis.type = Axis.AxisType.Value;
|
||
xAxis.min = 0;
|
||
xAxis.axisName.name = xAxisName;
|
||
|
||
// Y轴
|
||
var yAxis = lineChart.EnsureChartComponent<YAxis>();
|
||
yAxis.show = true;
|
||
yAxis.type = Axis.AxisType.Value;
|
||
yAxis.min = 0;
|
||
yAxis.max = yAxisMaxValue;
|
||
yAxis.axisName.name = yAxisName;
|
||
|
||
// 折线系列
|
||
var serie = lineChart.AddSerie<Line>();
|
||
if (serie != null)
|
||
{
|
||
serie.serieName = yAxisName;
|
||
serie.symbol.show = true;
|
||
serie.symbol.size = 5f;
|
||
serie.lineType = LineType.Normal;
|
||
serie.lineStyle.width = 3f;
|
||
serie.animation.enable = true;
|
||
serie.lineStyle.color = Color.red;
|
||
serie.symbol.color = Color.blue;
|
||
}
|
||
|
||
// 提示框
|
||
var tooltip = lineChart.GetChartComponent<Tooltip>();
|
||
if (tooltip == null) tooltip = lineChart.AddChartComponent<Tooltip>();
|
||
tooltip.show = true;
|
||
tooltip.type = Tooltip.Type.Line;
|
||
|
||
// 图例
|
||
var legend = lineChart.GetChartComponent<Legend>();
|
||
if (legend == null) legend = lineChart.AddChartComponent<Legend>();
|
||
legend.show = true;
|
||
legend.data = new List<string> { yAxisName };
|
||
|
||
return serie;
|
||
}
|
||
|
||
// 生成图表主方法
|
||
private void GenerateTemperatureChart(float durationHours, float initialTemp)
|
||
{
|
||
// 生成温度数据
|
||
List<Vector2> temperatureData = GenerateTemperatureData(durationHours, initialTemp);
|
||
|
||
// 更新图表
|
||
UpdateChartWithData(temperatureData, 5);
|
||
}
|
||
|
||
// 生成温度数据
|
||
private List<Vector2> GenerateTemperatureData(float durationHours, float initialTemp)
|
||
{
|
||
List<Vector2> dataPoints = new List<Vector2>();
|
||
|
||
// 生成时间点(每小时一个点)
|
||
for (int hour = 0; hour <= durationHours; hour++)
|
||
{
|
||
// 可以根据需要调整时间间隔
|
||
float time = hour;
|
||
float temperature = CalculateTemperatureAtHour_(hour, initialTemp, durationHours);
|
||
dataPoints.Add(new Vector2(time, temperature));
|
||
}
|
||
|
||
return dataPoints;
|
||
}
|
||
// 生成高耗能场景图表
|
||
private void HighenErgyConsumptionChart(float parameter)
|
||
{
|
||
// 生成温度数据
|
||
List<Vector2> temperatureData = GetDynamicChartPoints(parameter);
|
||
|
||
// 更新图表
|
||
UpdateChartWithData(temperatureData, 5);
|
||
}
|
||
/// <summary>
|
||
/// 生成节能改造图表
|
||
/// </summary>
|
||
/// <param name="parameter"></param>
|
||
/// <param name="indext">数据表下标</param>
|
||
private void EnergySavingChart(int indext)
|
||
{
|
||
// 生成温度数据
|
||
List<Vector2> temperatureData = Energysavingdata(indext);
|
||
|
||
// 更新图表
|
||
UpdateEnergySavingChartWithData(temperatureData, 5, indext);
|
||
}
|
||
//------"改造前参数"
|
||
float beforeStartEnergy = 20f; // 起始能耗
|
||
float beforePeakEnergy = 50; // 峰值(平稳段的值)
|
||
[Range(0, 1)] public float beforePlateauStart = 0.7f; // 平稳开始点(0~1),默认70%处开始平稳
|
||
//------"改造前参数"
|
||
|
||
//------"改造后参数"
|
||
float afterStartEnergy = 15f; // 起始能耗(必须低于改造前起始,保证始终低于)
|
||
float afterPeakEnergy = 40; // 平稳段峰值(必须小于改造前峰值)
|
||
float afterPlateauStart = 0.5f; // 平稳开始点(0~1),默认50%处开始平稳
|
||
float afterFluctuation = 0.5f; // 改造后波动幅度(微小波动)
|
||
//------"改造后参数"
|
||
public List<Vector2> Energysavingdata(int indext)
|
||
{
|
||
RandomValue();
|
||
List<Vector2> data = new List<Vector2>();
|
||
if (indext == 0)
|
||
{
|
||
// 生成数据点
|
||
for (int i = 0; i <= 10; i++) // 包含端点,共 pointCount+1 个点
|
||
{
|
||
float t = (float)i / 10; // 归一化进度 [0,1]
|
||
float x = t * 24; // X坐标(时间)
|
||
|
||
// --- 改造前数据 ---
|
||
float beforeEnergy;
|
||
if (t <= beforePlateauStart)
|
||
{
|
||
// 上升阶段:线性插值
|
||
float progress = t / beforePlateauStart; // 0~1
|
||
beforeEnergy = Mathf.Lerp(beforeStartEnergy, beforePeakEnergy, progress);
|
||
}
|
||
else
|
||
{
|
||
// 平稳阶段:保持峰值
|
||
beforeEnergy = beforePeakEnergy;
|
||
}
|
||
|
||
// 添加数据点 (x, y)
|
||
data.Add(new Vector2(x, beforeEnergy));
|
||
}
|
||
|
||
return data;
|
||
}
|
||
else
|
||
{
|
||
for (int i = 0; i <= 10; i++) // 包含端点,共 pointCount+1 个点
|
||
{
|
||
float t = (float)i / 10; // 归一化进度 [0,1]
|
||
float x = t * 24; // X坐标(时间)
|
||
float afterEnergy;
|
||
if (t <= afterPlateauStart)
|
||
{
|
||
// 上升阶段:线性插值(更缓)
|
||
float progress = t / afterPlateauStart;
|
||
afterEnergy = Mathf.Lerp(afterStartEnergy, afterPeakEnergy, progress);
|
||
}
|
||
else
|
||
{
|
||
// 平稳阶段:保持峰值 + 微小正弦波动
|
||
afterEnergy = afterPeakEnergy + afterFluctuation * Mathf.Sin(x * 0.8f);
|
||
}
|
||
data.Add(new Vector2(x, afterEnergy));
|
||
}
|
||
return data;
|
||
}
|
||
|
||
}
|
||
/// <summary>
|
||
/// 随机生成改造前改造后数值
|
||
/// </summary>
|
||
private void RandomValue()
|
||
{
|
||
beforeStartEnergy = UnityEngine.Random.Range(20, 50);// 起始能耗
|
||
beforePeakEnergy = UnityEngine.Random.Range(50, 80);// 峰值(平稳段的值)
|
||
beforePlateauStart = UnityEngine.Random.Range(0.5f, 0.8f);// 平稳开始点(0~1),0.5为50%处开始平稳
|
||
|
||
afterStartEnergy = UnityEngine.Random.Range(10, 20); // 起始能耗(必须低于改造前起始,保证始终低于)
|
||
afterPeakEnergy = UnityEngine.Random.Range(40, 49); // 平稳段峰值(必须小于改造前峰值)
|
||
afterPlateauStart = UnityEngine.Random.Range(0.4f, 0.7f); // 平稳开始点(0~1),默认50%处开始平稳
|
||
afterFluctuation = UnityEngine.Random.Range(0.3f, 0.7f); // 改造后波动幅度(微小波动)
|
||
}
|
||
/// <summary>
|
||
/// 根据当前故障程度,动态生成 X 轴和 Y 轴坐标点
|
||
/// </summary>
|
||
/// <param name="currentFault">当前的故障百分比数字 (如:输入 10 代表 10%)</param>
|
||
/// <returns>返回 3 个动态坐标点</returns>
|
||
public List<Vector2> GetDynamicChartPoints(float currentFault)
|
||
{
|
||
List<Vector2> points = new List<Vector2>();
|
||
|
||
float starpower = UnityEngine.Random.Range(0, 100);
|
||
|
||
// 1. 起点:永远是 (0, 基础能耗)
|
||
points.Add(new Vector2(0f, starpower));
|
||
|
||
// 2. 中点:X 轴是当前故障的一半,Y 轴能耗也相应增加一半
|
||
float xMid = currentFault / 2f;
|
||
float yMid = starpower + (starpower * (xMid / starpower)); // 按比例增加能耗
|
||
points.Add(new Vector2(xMid, yMid));
|
||
|
||
// 3. 终点:X 轴达到当前故障值,Y 轴达到目标能耗
|
||
float xEnd = currentFault;
|
||
float yEnd = starpower + (starpower * (xEnd / starpower));
|
||
points.Add(new Vector2(xEnd, yEnd));
|
||
|
||
return points;
|
||
}
|
||
// 计算每小时温度 - 可自定义算法
|
||
private float CalculateTemperatureAtHour(int hour, float initialTemp, float totalDuration)
|
||
{
|
||
// 示例1: 指数升温然后稳定
|
||
float maxTemp = initialTemp + 30f;
|
||
float timeFactor = hour / totalDuration;
|
||
|
||
if (timeFactor < 0.7f)
|
||
{
|
||
// 前70%时间指数升温
|
||
return initialTemp + (maxTemp - initialTemp) * (1 - Mathf.Exp(-timeFactor * 3));
|
||
}
|
||
else
|
||
{
|
||
// 后30%时间保持稳定
|
||
return maxTemp;
|
||
}
|
||
}
|
||
/// <summary>
|
||
/// 平滑显示温度曲线,从0-initialTemp
|
||
/// </summary>
|
||
/// <param name="hour"></param>
|
||
/// <param name="initialTemp"></param>
|
||
/// <param name="totalDuration"></param>
|
||
/// <returns></returns>
|
||
private float CalculateTemperatureAtHour_(int hour, float initialTemp, float totalDuration)
|
||
{
|
||
// 固定从 0 度开始
|
||
float startTemp = UnityEngine.Random.Range(0, 25);
|
||
|
||
// 计算总体时间进度 (0.0 到 1.0)
|
||
float timeFactor = Mathf.Clamp01((float)hour / totalDuration);
|
||
|
||
float currentTemp;
|
||
|
||
if (timeFactor < 0.7f)
|
||
{
|
||
// 前 70% 时间:从 0 指数升温
|
||
// 为了让升温在 70% 的节点刚好平滑到达终点,我们将 0~0.7 的进度重新映射为 0~1
|
||
float normalizedTime = timeFactor / 0.7f;
|
||
|
||
// 使用指数公式:当 normalizedTime 接近 1 时,1 - Exp(-5) 非常接近 1 (约0.993)
|
||
// 这样温度就会从 0 平滑地上升到 initialTemp
|
||
currentTemp = startTemp + (initialTemp - startTemp) * (1 - Mathf.Exp(-5f * normalizedTime));
|
||
}
|
||
else
|
||
{
|
||
// 后 30% 时间:保持稳定在最高温
|
||
currentTemp = initialTemp;
|
||
}
|
||
|
||
// 最终安全限制:确保返回值被严格卡在 0 到 initialTemp 之间
|
||
return Mathf.Clamp(currentTemp, 0f, initialTemp);
|
||
}
|
||
// 更新图表数据
|
||
private void UpdateChartWithData(List<Vector2> dataPoints, float maxDuration)
|
||
{
|
||
if (serie == null) return;
|
||
|
||
// 清空序列数据
|
||
serie.ClearData();
|
||
|
||
// 添加新数据点
|
||
foreach (var point in dataPoints)
|
||
{
|
||
serie.AddXYData(point.x, point.y);
|
||
//serie.AddData(new List<float> { point.x, point.y }, dataPoints.IndexOf(point));
|
||
}
|
||
|
||
// 更新X轴范围
|
||
var xAxis = lineChart.GetChartComponent<XAxis>();
|
||
if (xAxis != null)
|
||
{
|
||
xAxis.max = maxDuration;
|
||
xAxis.splitNumber = Mathf.Max(1, Mathf.FloorToInt(maxDuration));
|
||
}
|
||
|
||
// 自动调整Y轴范围
|
||
var yAxis = lineChart.GetChartComponent<YAxis>();
|
||
if (yAxis != null)
|
||
{
|
||
// 找到最小最大值
|
||
float minTemp = float.MaxValue;
|
||
float maxTemp = float.MinValue;
|
||
|
||
foreach (var point in dataPoints)
|
||
{
|
||
if (point.y < minTemp) minTemp = point.y;
|
||
if (point.y > maxTemp) maxTemp = point.y;
|
||
}
|
||
|
||
// 设置Y轴范围,留出10%边距
|
||
float margin = (maxTemp - minTemp) * 0.1f;
|
||
yAxis.min = Mathf.Floor(minTemp - margin);
|
||
yAxis.max = Mathf.Ceil(maxTemp + margin);
|
||
}
|
||
|
||
// 重绘图表
|
||
lineChart.RefreshChart();
|
||
}
|
||
// 更新节能改造图表数据
|
||
private void UpdateEnergySavingChartWithData(List<Vector2> dataPoints, float maxDuration, int serieindex)
|
||
{
|
||
if (series[serieindex] == null) return;
|
||
|
||
// 清空序列数据
|
||
series[serieindex].ClearData();
|
||
|
||
// 添加新数据点
|
||
foreach (var point in dataPoints)
|
||
{
|
||
series[serieindex].AddXYData(point.x, point.y);
|
||
//serie.AddData(new List<float> { point.x, point.y }, dataPoints.IndexOf(point));
|
||
}
|
||
|
||
// 更新X轴范围
|
||
var xAxis = lineChart.GetChartComponent<XAxis>();
|
||
if (xAxis != null)
|
||
{
|
||
xAxis.max = maxDuration;
|
||
xAxis.splitNumber = Mathf.Max(1, Mathf.FloorToInt(maxDuration));
|
||
}
|
||
|
||
// 自动调整Y轴范围
|
||
var yAxis = lineChart.GetChartComponent<YAxis>();
|
||
if (yAxis != null)
|
||
{
|
||
// 找到最小最大值
|
||
float minTemp = float.MaxValue;
|
||
float maxTemp = float.MinValue;
|
||
|
||
foreach (var point in dataPoints)
|
||
{
|
||
if (point.y < minTemp) minTemp = point.y;
|
||
if (point.y > maxTemp) maxTemp = point.y;
|
||
}
|
||
|
||
// 设置Y轴范围,留出10%边距
|
||
float margin = (maxTemp - minTemp) * 0.1f;
|
||
yAxis.min = Mathf.Floor(minTemp - margin);
|
||
yAxis.max = Mathf.Ceil(maxTemp + margin);
|
||
}
|
||
|
||
// 重绘图表
|
||
lineChart.RefreshChart();
|
||
}
|
||
// 添加多种温度变化模式
|
||
public void SetTemperatureMode(int mode, float durationHours, float initialTemp)
|
||
{
|
||
//if (!float.TryParse(durationInput.text, out float durationHours) ||
|
||
// !float.TryParse(initialTempInput.text, out float initialTemp))
|
||
//{
|
||
// return;
|
||
//}
|
||
|
||
List<Vector2> dataPoints = new List<Vector2>();
|
||
|
||
for (int hour = 0; hour <= durationHours; hour++)
|
||
{
|
||
float temperature = 0f;
|
||
|
||
switch (mode)
|
||
{
|
||
case 0: // 线性升温
|
||
temperature = initialTemp + 2f * hour;
|
||
break;
|
||
|
||
case 1: // 指数升温
|
||
temperature = initialTemp + 20f * (1 - Mathf.Exp(-hour * 0.5f));
|
||
break;
|
||
|
||
case 2: // 正弦波动
|
||
temperature = initialTemp + 10f + 5f * Mathf.Sin(hour * Mathf.PI / durationHours);
|
||
break;
|
||
|
||
case 3: // 阶梯式上升
|
||
temperature = initialTemp + 5f * Mathf.Floor(hour / 2);
|
||
break;
|
||
}
|
||
|
||
dataPoints.Add(new Vector2(hour, temperature));
|
||
}
|
||
|
||
UpdateChartWithData(dataPoints, durationHours);
|
||
}
|
||
|
||
// 添加实时数据功能
|
||
public void StartRealTimeUpdate(float initialTemp)
|
||
{
|
||
//if (!float.TryParse(initialTempInput.text, out float initialTemp))
|
||
// return;
|
||
|
||
StartCoroutine(RealTimeTemperatureUpdate(initialTemp));
|
||
}
|
||
|
||
private System.Collections.IEnumerator RealTimeTemperatureUpdate(float initialTemp)
|
||
{
|
||
float elapsedTime = 0f;
|
||
List<Vector2> dataPoints = new List<Vector2>();
|
||
|
||
while (elapsedTime < 10f) // 模拟10秒实时数据
|
||
{
|
||
// 添加新数据点
|
||
float temperature = initialTemp + UnityEngine.Random.Range(-2f, 2f) + elapsedTime * 2f;
|
||
dataPoints.Add(new Vector2(elapsedTime, temperature));
|
||
|
||
// 更新图表
|
||
UpdateChartWithData(dataPoints, elapsedTime);
|
||
|
||
elapsedTime += 0.5f; // 每0.5秒更新一次
|
||
yield return new WaitForSeconds(0.5f);
|
||
}
|
||
}
|
||
|
||
// 清空图表
|
||
public void ClearChart()
|
||
{
|
||
if (serie != null)
|
||
{
|
||
serie.ClearData();
|
||
}
|
||
|
||
if (lineChart != null)
|
||
{
|
||
lineChart.RefreshChart();
|
||
}
|
||
}
|
||
|
||
#endregion
|
||
|
||
#region 警告提示
|
||
|
||
/// <summary>
|
||
/// 显示警告信息
|
||
/// </summary>
|
||
/// <param name="warmingText"></param>
|
||
private void ShowWarming(string warmingText)
|
||
{
|
||
if (string.IsNullOrEmpty(warmingText.Trim())) return;
|
||
if (!variables.Get<RectTransform>("警告").gameObject.activeSelf)
|
||
variables.Get<RectTransform>("警告").gameObject.Activate();
|
||
// 快速完成打字
|
||
if (typingCoroutine != null)
|
||
StopCoroutine(typingCoroutine);
|
||
//开启打字效果
|
||
typingCoroutine = StartCoroutine(TypeText(warmingText));
|
||
|
||
StartCoroutine(AutoHideWarming(3.5f));
|
||
}
|
||
|
||
/// <summary>
|
||
/// 打字效果协程,逐个字符显示文本。
|
||
/// </summary>
|
||
/// <param name="text"></param>
|
||
/// <returns></returns>
|
||
private IEnumerator TypeText(string text)
|
||
{
|
||
variables.Get<Text>("警告文本").text = "";
|
||
|
||
foreach (char letter in text.ToCharArray())
|
||
{
|
||
variables.Get<Text>("警告文本").text += letter;
|
||
yield return new WaitForSeconds(typingSpeed);
|
||
}
|
||
}
|
||
|
||
/// <summary>
|
||
/// 自动隐藏警告信息协程,延迟一段时间后关闭警告框。
|
||
/// </summary>
|
||
/// <param name="durationTime"></param>
|
||
/// <returns></returns>
|
||
private IEnumerator AutoHideWarming(float durationTime)
|
||
{
|
||
yield return new WaitForSeconds(durationTime);
|
||
variables.Get<Text>("警告文本").text = "";
|
||
variables.Get<RectTransform>("警告").gameObject.Deactivate();
|
||
}
|
||
|
||
#endregion
|
||
|
||
#region ButtonData
|
||
|
||
/// <summary>
|
||
/// 设置默认
|
||
/// </summary>
|
||
/// <param name="target"></param>
|
||
/// <param name="data"></param>
|
||
private void SetNormal(Button target, ButtonData data)
|
||
{
|
||
Image img = target.GetComponent<Image>();
|
||
if (img != null)
|
||
{
|
||
img.sprite = data.normalSprite;
|
||
}
|
||
}
|
||
|
||
/// <summary>
|
||
/// 设置高亮
|
||
/// </summary>
|
||
/// <param name="target"></param>
|
||
/// <param name="data"></param>
|
||
private void SetHightlight(Button target, ButtonData data)
|
||
{
|
||
Image img = target.GetComponent<Image>();
|
||
if (img != null)
|
||
{
|
||
img.sprite = data.selectedSprite;
|
||
}
|
||
}
|
||
|
||
#endregion
|
||
|
||
#region tsq
|
||
|
||
/// <summary>
|
||
/// 按钮点击事件初始化
|
||
/// </summary>
|
||
private void ToggleInit()
|
||
{
|
||
variables.Get<Toggle>("一楼Toggle").onValueChanged.AddListener(delegate
|
||
{
|
||
ChooseFloor(1);
|
||
});
|
||
variables.Get<Toggle>("二楼Toggle").onValueChanged.AddListener(delegate
|
||
{
|
||
ChooseFloor(2);
|
||
});
|
||
variables.Get<Toggle>("三楼Toggle").onValueChanged.AddListener(delegate
|
||
{
|
||
ChooseFloor(3);
|
||
});
|
||
}
|
||
|
||
/// <summary>
|
||
/// 空调楼层选择
|
||
/// </summary>
|
||
/// <param name="floor"></param>
|
||
public void ChooseFloor(int floor)
|
||
{
|
||
switch (floor)
|
||
{
|
||
case 1:
|
||
GameMangner_TSQ.instance.FirstPersonController[0].transform.SetLocalPositionAndRotation
|
||
(new Vector3(0.1f, 0.025f, 2.2f), Quaternion.Euler(0, 120, 0));
|
||
break;
|
||
case 2:
|
||
GameMangner_TSQ.instance.FirstPersonController[0].transform.SetLocalPositionAndRotation
|
||
(new Vector3(0.1f, 0.355f, 2.2f), Quaternion.Euler(0, 120, 0));
|
||
break;
|
||
case 3:
|
||
GameMangner_TSQ.instance.FirstPersonController[0].transform.SetLocalPositionAndRotation
|
||
(new Vector3(-0.74f, 1.171f, 0.517f), Quaternion.Euler(0, 280, 0));
|
||
break;
|
||
}
|
||
}
|
||
|
||
/// <summary>
|
||
/// 泵面板
|
||
/// </summary>
|
||
private void BengPanel()
|
||
{
|
||
if (UIView.Get<EquipmentSimulationView>().IsActiveSelf())
|
||
{
|
||
UIView.Get<EquipmentSimulationView>().variables.Get<Text>("泵机Text").text = "开启泵";
|
||
//UIView.Get<EquipmentSimulationView>().variables.Get<RectTransform>("参数面板-冷却塔风机1").Activate();
|
||
|
||
//UIView.Get<EquipmentSimulationView>().variables.Get<Button>("启动运行-冷却塔风机1").onClick.AddListener(() => { SetStep(true); });
|
||
//UIView.Get<EquipmentSimulationView>().variables.Get<Button>("停止运行-冷却塔风机1").onClick.AddListener(() => { SetStep(false); });
|
||
if (UIView.Get<EquipmentSimulationView>().Stepbools[7] == true)
|
||
{
|
||
|
||
UIView.Get<EquipmentSimulationView>().variables.Get<Button>("启动运行-泵").Deactivate();
|
||
UIView.Get<EquipmentSimulationView>().variables.Get<Button>("停止运行-泵").Activate();
|
||
}
|
||
else
|
||
{
|
||
UIView.Get<EquipmentSimulationView>().variables.Get<Text>("泵机Text").text = "开启泵";
|
||
UIView.Get<EquipmentSimulationView>().variables.Get<Button>("停止运行-泵").Deactivate();
|
||
UIView.Get<EquipmentSimulationView>().variables.Get<Button>("启动运行-泵").Activate();
|
||
}
|
||
|
||
}
|
||
//StartCoroutine(AutoHide(4,"参数面板-冷却塔风机1"));
|
||
}
|
||
|
||
/// <summary>
|
||
/// 风机面板
|
||
/// </summary>
|
||
private void FengJiPanel()
|
||
{
|
||
if (UIView.Get<EquipmentSimulationView>().IsActiveSelf())
|
||
{
|
||
UIView.Get<EquipmentSimulationView>().variables.Get<Text>("空压机主机Text").text = "开启空压机";
|
||
//UIView.Get<EquipmentSimulationView>().variables.Get<RectTransform>("参数面板-冷却塔风机1").Activate();
|
||
|
||
//UIView.Get<EquipmentSimulationView>().variables.Get<Button>("启动运行-冷却塔风机1").onClick.AddListener(() => { SetStep(true); });
|
||
//UIView.Get<EquipmentSimulationView>().variables.Get<Button>("停止运行-冷却塔风机1").onClick.AddListener(() => { SetStep(false); });
|
||
if (UIView.Get<EquipmentSimulationView>().Stepbools[8] == true)
|
||
{
|
||
UIView.Get<EquipmentSimulationView>().variables.Get<Button>("启动运行-空压机").Deactivate();
|
||
UIView.Get<EquipmentSimulationView>().variables.Get<Button>("停止运行-空压机").Activate();
|
||
}
|
||
else
|
||
{
|
||
UIView.Get<EquipmentSimulationView>().variables.Get<Button>("停止运行-空压机").Deactivate();
|
||
UIView.Get<EquipmentSimulationView>().variables.Get<Button>("启动运行-空压机").Activate();
|
||
}
|
||
|
||
}
|
||
//StartCoroutine(AutoHide(4,"参数面板-冷却塔风机1"));
|
||
}
|
||
|
||
/// <summary>
|
||
/// 设备运行
|
||
/// </summary>
|
||
private void SBStartOperation(string YXCGtext)
|
||
{
|
||
if (string.IsNullOrEmpty(YXCGtext.Trim())) return;
|
||
if (!variables.Get<RectTransform>("运行成功").gameObject.activeSelf)
|
||
variables.Get<RectTransform>("运行成功").gameObject.Activate();
|
||
// 快速完成打字
|
||
if (typingCoroutine != null)
|
||
StopCoroutine(typingCoroutine);
|
||
//开启打字效果
|
||
typingCoroutine = StartCoroutine(YXCGTypeText(YXCGtext));
|
||
|
||
StartCoroutine(YXCGAutoHide(3.5f));
|
||
}
|
||
|
||
/// <summary>
|
||
/// 自动隐藏运行成功信息协程,延迟一段时间后关闭框。
|
||
/// </summary>
|
||
/// <param name="durationTime"></param>
|
||
/// <returns></returns>
|
||
private IEnumerator YXCGAutoHide(float durationTime)
|
||
{
|
||
yield return new WaitForSeconds(durationTime);
|
||
variables.Get<Text>("运行成功文本").text = "";
|
||
variables.Get<RectTransform>("运行成功").gameObject.Deactivate();
|
||
}
|
||
/// <summary>
|
||
/// 运行成功打字效果协程,逐个字符显示文本。
|
||
/// </summary>
|
||
/// <param name="text"></param>
|
||
/// <returns></returns>
|
||
private IEnumerator YXCGTypeText(string text)
|
||
{
|
||
variables.Get<Text>("运行成功文本").text = "";
|
||
|
||
foreach (char letter in text.ToCharArray())
|
||
{
|
||
variables.Get<Text>("运行成功文本").text += letter;
|
||
yield return new WaitForSeconds(typingSpeed);
|
||
}
|
||
}
|
||
|
||
|
||
#endregion
|
||
} |