using System.Collections.Generic; using Unity.VisualScripting; using UnityEngine; using UnityEngine.UI; public class LineGroupManager : MonoBehaviour { public static LineGroupManager Instance; private void Awake() { Instance = this; } public GameObject panel_object; public Button cls_bt; /// /// 当前选中的线缆组名 /// [Header("当前选中线缆组")] public string selected_group_name; public string selected_group_ID; /// /// 新增线缆组弹窗 /// [Header("线缆组弹窗")] public GameObject add_group_pop; public GameObject edit_group_pop; [Header("新增线缆")] public Button add_cable_bt; [Header("线缆组新增")] public InputField line_group_name_inputfield; /// /// 新增按钮 /// public Button add_group; /// /// 保存新增线缆组 /// public Button add_line_group_button; /// /// 取消新增线缆组 /// public Button cancel_line_group_button; public Button add_line_group_cls_button; [Header("线缆组修改")] public InputField line_group_editName_inputfield; public Button editSave_group_button; public Button cancel_group_button; public Button edit_group_cls_button; /// /// 线缆组容器 /// [Header("容器")] public GameObject line_group_content; /// /// 线缆容器(右) /// public GameObject line_content_right; /// /// 所有线缆组脚本 /// public List child_line_group_items = new List(); private void Start() { cls_bt.onClick.AddListener(() => { panel_object.SetActive(false); }); add_cable_bt.onClick.AddListener(() => { RedactPort.Inst.mybody = new RedactPort.Body(); RedactPort.Inst.PortList1_game = null; RedactPort.Inst.PortList2_game = null; RedactPort.Inst.PortList1 = null; RedactPort.Inst.PortList2 = null; panel_object.SetActive(false); PatternChoose.Inst.dk_bj_page.SetActive(true); }); //线缆组新增 add_group.onClick.AddListener(() => { add_group_pop.SetActive(true); line_group_name_inputfield.text = string.Empty; }); add_line_group_button.onClick.AddListener(() => { if (!string.IsNullOrWhiteSpace(line_group_name_inputfield.text)) { //AddLineGroup(line_group_name_inputfield.text); LineQuery.Inst.StartCoroutine(LineQuery.Inst.SaveJsonCoroutine(line_group_name_inputfield.text, x => { add_group_pop.SetActive(false); if (x) { StartCoroutine(LineQuery.Inst.Succeed((z) => { if (z) { } else { SecondConfirmPanel.DeleteConform(null, "更新场景失败"); Debug.Log("接口获取数据失败(线缆组新增-初始化失败)"); } })); } })); } else { add_group_pop.SetActive(false); SecondConfirmPanel.DeleteConform((returnValue) => { add_group_pop.SetActive(true); }, "线缆组名不能为空"); } }); cancel_line_group_button.onClick.AddListener(() => { add_group_pop.SetActive(false); line_group_name_inputfield.text = string.Empty; }); add_line_group_cls_button.onClick.AddListener(() => { add_group_pop.SetActive(false); line_group_name_inputfield.text = string.Empty; }); //线缆组修改 editSave_group_button.onClick.AddListener(() => { if (string.IsNullOrWhiteSpace(line_group_editName_inputfield.text)) { edit_group_pop.SetActive(false); SecondConfirmPanel.DeleteConform((returnValue) => { edit_group_pop.SetActive(true); }, "线缆组名不能为空"); return; } //点击保存 LineQuery.Inst.editJsonCoroutine(selected_group_ID, line_group_editName_inputfield.text, (x, y) => { edit_group_pop.SetActive(false); if (x) { StartCoroutine(LineQuery.Inst.Succeed((z) => { if (z) { } else { SecondConfirmPanel.DeleteConform(null, "更新场景失败"); Debug.Log("接口获取数据失败(线缆组修改-初始化失败)"); } })); } else { string v = "修改线缆组失败"; if (y != null) v = y.message; SecondConfirmPanel.DeleteConform(null, v); } }); }); cancel_group_button.onClick.AddListener(() => { edit_group_pop.SetActive(false); line_group_editName_inputfield.text = string.Empty; }); edit_group_cls_button.onClick.AddListener(() => { edit_group_pop.SetActive(false); line_group_editName_inputfield.text = string.Empty; }); } /// /// 根据数据库生成线缆并添加至列表 /// public void addxianlan() { GameObject xianlan = PatternChoose.Inst.xianlan.gameObject; GameManager.Inst.FindPortPos(); for (int i = 0; i < child_line_group_items.Count; i++) { LineGroupItem lineGroupItem = child_line_group_items[i].GetComponent(); lineGroupItem.ClearChilds(); for (int j = 0; j < xianlan.transform.childCount; j++) { //if (xianlan.transform.GetChild(j).GetComponent().cableGroupName == child_line_group_items[i].info_text.text) if (xianlan.transform.GetChild(j).name == child_line_group_items[i].info_text.text) { //lineGroupItem.AddLineItem(xianlan.transform.GetChild(j).GetComponent().cableName); //foreach (var item in xianlan.transform.GetChild(j).GetComponentsInChildren(true)) foreach (var item in xianlan.transform.GetChild(j).GetComponentsInChildren(true)) { var lines = item.GetComponent().lines; if (lines[1]) { var p0 = lines[0].GetComponent(); var p1 = lines[1].GetComponent(); List strings; if (p0.portList.startFlag == 1) { strings = new List { item.port_A_cabinet+"$"+item.port_A_deviceName+"$#"+item.port_A, item.port_B_cabinet+"$"+item.port_B_deviceName+"$#"+item.port_B }; } else { strings = new List { item.port_B_cabinet+"$"+item.port_B_deviceName+"$#"+item.port_B, item.port_A_cabinet+"$"+item.port_A_deviceName+"$#"+item.port_A, }; } lineGroupItem.AddLineItem(item.name, lines, strings); } } } } } } public void AddLineGroupInit() { foreach (var item in LineQuery.Inst.keyValues) { if (!string.IsNullOrWhiteSpace(item.Key)) { AddLineGroup(item.Key, item.Value); } } } /// /// 显示面板 /// public void ShowPanel() { selected_group_name = string.Empty; selected_group_ID = string.Empty; PatternChoose.Inst.dk_bj_page.gameObject.SetActive(false); PatternChoose.Inst.dk_xz_page.gameObject.SetActive(false); StartCoroutine(LineQuery.Inst.getJsonCoroutine((u, z) => { if (u) { addxianlan(); panel_object.SetActive(true); GameManager.Inst.portCloseFlashing(); } })); //AddLineGroupInit(); } /// /// 隐藏面板 /// public void HidePanel() { selected_group_name = string.Empty; selected_group_ID = string.Empty; panel_object.SetActive(false); } /// /// 添加线缆组 /// /// public void AddLineGroup(string name, string id, bool success = true) { if (!success) { SecondConfirmPanel.DeleteConform(null, "操作失败"); return; } //判断是否有重复 if (child_line_group_items.Find(x => x.info_text.text == name)) { //SecondConfirmPanel.DeleteConform(null, "存在重复名称"); return; } //int? a = line_group_content.transform.childCount; var item = LineObjectPool.Instance.GetItemFromPool(); item.transform.SetParent(line_group_content.transform); child_line_group_items.Add(item); //传递数据 item.info_text.text = name; item.id = id; //处理完毕后清空输入框 line_group_name_inputfield.SetTextWithoutNotify(""); } /// /// 回收右侧对象(线缆) /// public void Empty_line_content_right() { var l = line_content_right.GetComponentsInChildren(true); for (int i = l.Length - 1; i >= 0; i--) { LineObjectPool.Instance.PushItemToPool(l[i]); } } /// /// 回收左侧对象(线缆组) /// public void Empty_line_content_left() { child_line_group_items.Clear(); var l = line_group_content.GetComponentsInChildren(true); for (int i = l.Length - 1; i >= 0; i--) { LineObjectPool.Instance.PushItemToPool(l[i]); } } }