using System; using System.Collections; using System.Collections.Generic; using System.Linq; using UnityEditor; using UnityEngine; using UnityEngine.UI; using static WebInteraction; public class UIToCabinet : MonoBehaviour { public List toggles = new List(); /// /// 机柜容量标识 /// public GameObject rongLaing; public GameObject xianlanpz; public GameObject mask_img; public Button enter_home; public Button back_home; public GameObject first_level_menu; public List second_level_menu; // Start is called before the first frame update void Start() { enter_home.onClick.AddListener(() => { mask_img.SetActive(false); first_level_menu.SetActive(true); }); toggles = GetComponentsInChildren(true).ToList(); back_home.onClick.AddListener(() => { if (mask_img.activeSelf) return; mask_img.SetActive(true); TransparentGlowManage.Inst.renewALL(); CabinetUIManager.ChangeMenu(Menu.None); first_level_menu.transform.Find("Toggle Group/Toggle_全景监控").GetComponent().isOn = true; for (int i = 0; i < GameManager.Inst.Cabinets_go.Count; i++) GameManager.Inst.Cabinets_go[i].transform.Find("高亮").gameObject.SetActive(false); for (int i = 0; i < second_level_menu.Count; i++) second_level_menu[i].SetActive(false); for (int i = 0; i < GameManager.Inst.pop_ups.Count; i++) GameManager.Inst.pop_ups[i].SetActive(false); first_level_menu.SetActive(false); }); for (int i = 0; i < toggles.Count; i++) { var index = i; toggles[i].onValueChanged.AddListener((ison) => { if (ison) { CreateLine createLine = PatternChoose.Inst.transform.Find("画线").GetComponent(); UI_init(); Debug.Log("第" + index); if (mask_img.activeSelf) return; switch (toggles[index].name) { case "Toggle_设备告警": { StartCoroutine(Loadinfo(Menu.M_全景监控_设备告警, (x) => { if (string.IsNullOrEmpty(x)) return; init(Menu.M_全景监控_设备告警); ExtendedFlycam.Inst.QuanJing(); PatternChoose.Inst.transform.Find("Panel搜索框").GetComponent().LoadCabinet(SearchName.SearchType.机柜); GameManager.Inst.search_box.SetActive(true); CabinetUIManager.ChangeMenu(Menu.M_全景监控_设备告警); })); } break; case "Toggle_全景监控": { StartCoroutine(Loadinfo(Menu.M_全景监控_设备告警, (x) => { if (string.IsNullOrEmpty(x)) return; init(Menu.M_全景监控_设备告警); ExtendedFlycam.Inst.QuanJing(); PatternChoose.Inst.transform.Find("Panel搜索框").GetComponent().LoadCabinet(SearchName.SearchType.机柜); GameManager.Inst.search_box.SetActive(true); CabinetUIManager.ChangeMenu(Menu.M_全景监控_设备告警); })); } break; case "Toggle_数字孪生": { rongLaing.SetActive(true); init(Menu.M_数字孪生_机柜容量); ExtendedFlycam.Inst.QuanJing(); GameManager.Inst.DisplayCapacity(ison); PatternChoose.Inst.transform.Find("Panel搜索框").GetComponent().LoadCabinet(SearchName.SearchType.机柜); CabinetUIManager.ChangeMenu(Menu.M_数字孪生_机柜容量); } break; case "Toggle_温湿度": { StartCoroutine(Loadinfo(Menu.M_全景监控_温度, (x) => { if (string.IsNullOrEmpty(x)) return; init(Menu.M_全景监控_温度); ExtendedFlycam.Inst.QuanJing(); PatternChoose.Inst.transform.Find("Panel搜索框").GetComponent().LoadCabinet(SearchName.SearchType.机柜); GameManager.Inst.search_box.SetActive(true); CabinetUIManager.ChangeMenu(Menu.M_全景监控_温度); })); } break; case "Toggle_柜门状态": { init(Menu.M_全景监控_柜门状态); ExtendedFlycam.Inst.QuanJing(); GameManager.Inst.DoorCondition(/*ison*/); PatternChoose.Inst.transform.Find("Panel搜索框").GetComponent().LoadCabinet(SearchName.SearchType.机柜); GameManager.Inst.search_box.SetActive(true); CabinetUIManager.ChangeMenu(Menu.M_全景监控_柜门状态); } break; case "Toggle_红外监测": { init(Menu.M_全景监控_红外监测); ExtendedFlycam.Inst.QuanJing(); GameManager.Inst.search_box.SetActive(false); CabinetUIManager.ChangeMenu(Menu.M_全景监控_红外监测); } break; case "Toggle_现场作业": { init(Menu.M_全景监控_现场作业); ExtendedFlycam.Inst.QuanJing(); if (BoolMonitor.Value) { WebInteraction.Inst.isWorkPlay = true; WebInteraction.Inst.OpenTicket(); } CabinetUIManager.ChangeMenu(Menu.M_全景监控_现场作业); } break; case "Toggle_摄像头": { init(Menu.M_全景监控_摄像头); ExtendedFlycam.Inst.QuanJing(); //if (BoolMonitor.Value) // WebInteraction.Inst.OpenVideo(); PatternChoose.Inst.transform.Find("Panel搜索框").GetComponent().LoadCabinet(SearchName.SearchType.机柜); CabinetUIManager.ChangeMenu(Menu.M_全景监控_摄像头); } break; case "Toggle_机柜容量": { rongLaing.SetActive(true); init(Menu.M_数字孪生_机柜容量); ExtendedFlycam.Inst.QuanJing(); PatternChoose.Inst.transform.Find("Panel搜索框").GetComponent().LoadCabinet(SearchName.SearchType.机柜); GameManager.Inst.DisplayCapacity(ison); CabinetUIManager.ChangeMenu(Menu.M_数字孪生_机柜容量); } break; case "Toggle_接地网": { FloorController.Inst.FloorTransparent(); init(Menu.M_数字孪生_接地网); ExtendedFlycam.Inst.QuanJing(); CabinetUIManager.ChangeMenu(Menu.M_数字孪生_接地网); } break; case "Toggle_线缆链接": { init(Menu.M_数字孪生_线缆连接_展示); ExtendedFlycam.Inst.QuanJing(); //CreateLine createLine = PatternChoose.Inst.transform.Find("画线").GetComponent(); createLine.OnMenuChanged(Menu.M_数字孪生_线缆连接_展示); CabinetUIManager.ChangeMenu(Menu.M_数字孪生_线缆连接_展示); } break; case "Toggle_场景管理": { init(Menu.M_数字孪生_场景管理); ExtendedFlycam.Inst.QuanJing(); GameManager.Inst.power_open(); //GameManager.Inst.objectToShow_add.SetActive(true); var SN1 = GameManager.Inst.objectToShow_add.GetComponent(); SN1.hide_menu(); CabinetUIManager.ChangeMenu(Menu.M_数字孪生_场景管理); } break; case "Toggle_智能巡检": { init(Menu.M_数字孪生_智能巡检); ExtendedFlycam.Inst.QuanJing(); GameManager.Inst.search_box.SetActive(false); CabinetUIManager.ChangeMenu(Menu.M_数字孪生_智能巡检); } break; case "Toggle_温度": { StartCoroutine(Loadinfo(Menu.M_全景监控_温度, (x) => { if (string.IsNullOrEmpty(x)) return; init(Menu.M_全景监控_温度); ExtendedFlycam.Inst.QuanJing(); PatternChoose.Inst.transform.Find("Panel搜索框").GetComponent().LoadCabinet(SearchName.SearchType.机柜); CabinetUIManager.ChangeMenu(Menu.M_全景监控_温度); })); } break; case "Toggle_湿度": { init(Menu.M_全景监控_湿度); ExtendedFlycam.Inst.QuanJing(); PatternChoose.Inst.transform.Find("Panel搜索框").GetComponent().LoadCabinet(SearchName.SearchType.机柜); CabinetUIManager.ChangeMenu(Menu.M_全景监控_湿度); } break; case "Toggle_烟感": { init(Menu.M_全景监控_烟感); ExtendedFlycam.Inst.QuanJing(); PatternChoose.Inst.transform.Find("Panel搜索框").GetComponent().LoadCabinet(SearchName.SearchType.机柜); CabinetUIManager.ChangeMenu(Menu.M_全景监控_烟感); } break; case "Toggle_水浸": { init(Menu.M_全景监控_水浸); ExtendedFlycam.Inst.QuanJing(); PatternChoose.Inst.transform.Find("Panel搜索框").GetComponent().LoadCabinet(SearchName.SearchType.机柜); CabinetUIManager.ChangeMenu(Menu.M_全景监控_水浸); } break; case "Toggle_线缆连接展示": { init(Menu.M_数字孪生_线缆连接_展示); ExtendedFlycam.Inst.QuanJing(); //PatternChoose.Inst.transform.Find("Panel搜索框").GetComponent().LoadCabinet(SearchName.SearchType.线缆_展示); createLine.OnMenuChanged(Menu.M_数字孪生_线缆连接_展示); CabinetUIManager.ChangeMenu(Menu.M_数字孪生_线缆连接_展示); } break; case "Toggle_线缆连接配置": { init(Menu.M_数字孪生_线缆连接_配置); ExtendedFlycam.Inst.QuanJing(); GameManager.Inst.power_open(); CabinetUIManager.ChangeMenu(Menu.M_数字孪生_线缆连接_配置); } break; case "Toggle_线缆组配置": { LineGroupManager.Instance.ShowPanel(); SecondConfirmPanel.Instance.panel_object.SetActive(false); init(Menu.M_数字孪生_线缆组配置); CabinetUIManager.ChangeMenu(Menu.M_数字孪生_线缆组配置); } break; default: break; } createLine.deletxianLan(CabinetUIManager.Instance.current_menu); if (toggles[index].name == "Toggle_线缆连接展示" || toggles[index].name == "Toggle_线缆连接配置" || toggles[index].name == "Toggle_线缆组配置" || toggles[index].name == "Toggle_线缆链接") { xianlanpz.SetActive(true); } else { xianlanpz.SetActive(false); } } }); } } /// /// 按键切换初始化 /// public void UI_init() { GameManager.Inst.power_close(); if (GameManager.Inst.objectToShow_add.activeSelf) { var SN1 = GameManager.Inst.objectToShow_add.GetComponent(); SN1.hide_menu(); GameManager.Inst.objectToShow_add.SetActive(false); } GameManager.Inst.stagingPanel.SetActive(false); GameManager.Inst.editorMenu.gameObject.SetActive(false); rongLaing.SetActive(false); FloorController.Inst.FloorNormal(); LineGroupManager.Instance.HidePanel(); for (int i = 0; i < GameManager.Inst.pop_ups.Count; i++) { GameManager.Inst.pop_ups[i].SetActive(false); } for (int i = 0; i < CabinetUIManager.Instance.cabinet_ui_base_list.Count; i++) { if (CabinetUIManager.Instance.cabinet_ui_base_list[i].gameObject.activeSelf && CabinetUIManager.Instance.cabinet_ui_base_list[i].gameObject.name != "智能巡检") { CabinetUIManager.Instance.cabinet_ui_base_list[i].gameObject.SetActive(false); } } } public IEnumerator Loadinfo(Menu menu, Action callback) { if (menu == Menu.M_全景监控_温度) { yield return StartCoroutine(GameManager.Inst.init_ENV((x) => { if (string.IsNullOrEmpty(x)) return; GameManager.Inst.Load_ENV(); callback?.Invoke("1"); })); } else if (menu == Menu.M_全景监控_设备告警) { yield return StartCoroutine(GameManager.Inst.init_TmsAlarm((x) => { if (string.IsNullOrEmpty(x)) return; GameManager.Inst.Load_TmsAlarm(); callback?.Invoke("1"); })); } } // Update is called once per frame void Update() { } public void init(Menu menu) { if (WebInteraction.Inst.isWorkPlay && menu != Menu.M_全景监控_现场作业) WebInteraction.Inst.CloseTicket(); CreateLine createLine = PatternChoose.Inst.transform.Find("画线").GetComponent(); if (!CheckAllChildrenActive(createLine.gameObject) && menu != Menu.M_数字孪生_线缆连接_展示) { for (int i = 0; i < createLine.transform.childCount; i++) { createLine.transform.GetChild(i).gameObject.SetActive(false); } } if (menu == Menu.M_数字孪生_线缆连接_配置 || menu == Menu.M_数字孪生_场景管理 || menu == Menu.M_数字孪生_线缆组配置) { for (int i = 0; i < CabinetUIManager.Instance.door_list.Count; i++) { CabinetUIManager.Instance.door_list[i].gameObject.SetActive(false); } } else { for (int i = 0; i < CabinetUIManager.Instance.door_list.Count; i++) { CabinetUIManager.Instance.door_list[i].gameObject.SetActive(true); } } } /// /// 判断父物体下子物体是否都为隐藏 /// /// /// bool CheckAllChildrenActive(GameObject parent) { int childCount = parent.transform.childCount; for (int i = 0; i < childCount; i++) { GameObject child = parent.transform.GetChild(i).gameObject; if (child.activeSelf) { return false; } } return true; } }