340 lines
11 KiB
C#
340 lines
11 KiB
C#
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;
|
|
|
|
|
|
/// <summary>
|
|
/// 当前选中的线缆组名
|
|
/// </summary>
|
|
[Header("当前选中线缆组")]
|
|
public string selected_group_name;
|
|
public string selected_group_ID;
|
|
|
|
|
|
/// <summary>
|
|
/// 新增线缆组弹窗
|
|
/// </summary>
|
|
[Header("线缆组弹窗")] public GameObject add_group_pop;
|
|
public GameObject edit_group_pop;
|
|
|
|
[Header("新增线缆")] public Button add_cable_bt;
|
|
|
|
[Header("线缆组新增")]
|
|
public InputField line_group_name_inputfield;
|
|
/// <summary>
|
|
/// 新增按钮
|
|
/// </summary>
|
|
public Button add_group;
|
|
/// <summary>
|
|
/// 保存新增线缆组
|
|
/// </summary>
|
|
public Button add_line_group_button;
|
|
/// <summary>
|
|
/// 取消新增线缆组
|
|
/// </summary>
|
|
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;
|
|
|
|
/// <summary>
|
|
/// 线缆组容器
|
|
/// </summary>
|
|
[Header("容器")] public GameObject line_group_content;
|
|
|
|
/// <summary>
|
|
/// 线缆容器(右)
|
|
/// </summary>
|
|
public GameObject line_content_right;
|
|
/// <summary>
|
|
/// 所有线缆组脚本
|
|
/// </summary>
|
|
public List<LineGroupItem> child_line_group_items = new List<LineGroupItem>();
|
|
|
|
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;
|
|
});
|
|
}
|
|
|
|
/// <summary>
|
|
/// 根据数据库生成线缆并添加至列表
|
|
/// </summary>
|
|
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>();
|
|
lineGroupItem.ClearChilds();
|
|
for (int j = 0; j < xianlan.transform.childCount; j++)
|
|
{
|
|
//if (xianlan.transform.GetChild(j).GetComponent<LineInfor>().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<LineInfor>().cableName);
|
|
//foreach (var item in xianlan.transform.GetChild(j).GetComponentsInChildren<LineInfor>(true))
|
|
foreach (var item in xianlan.transform.GetChild(j).GetComponentsInChildren<LineRendererInteraction>(true))
|
|
{
|
|
var lines = item.GetComponent<LineInfor>().lines;
|
|
if (lines[1])
|
|
{
|
|
var p0 = lines[0].GetComponent<PortQuery>();
|
|
var p1 = lines[1].GetComponent<PortQuery>();
|
|
List<string> strings;
|
|
if (p0.portList.startFlag == 1)
|
|
{
|
|
strings = new List<string>
|
|
{
|
|
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<string>
|
|
{
|
|
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);
|
|
}
|
|
}
|
|
|
|
}
|
|
|
|
/// <summary>
|
|
/// 显示面板
|
|
/// </summary>
|
|
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();
|
|
}
|
|
|
|
/// <summary>
|
|
/// 隐藏面板
|
|
/// </summary>
|
|
public void HidePanel()
|
|
{
|
|
selected_group_name = string.Empty;
|
|
selected_group_ID = string.Empty;
|
|
panel_object.SetActive(false);
|
|
}
|
|
|
|
/// <summary>
|
|
/// 添加线缆组
|
|
/// </summary>
|
|
/// <param name="name"></param>
|
|
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<LineGroupItem>();
|
|
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("");
|
|
}
|
|
|
|
/// <summary>
|
|
/// 回收右侧对象(线缆)
|
|
/// </summary>
|
|
public void Empty_line_content_right()
|
|
{
|
|
var l = line_content_right.GetComponentsInChildren<LineItem>(true);
|
|
for (int i = l.Length - 1; i >= 0; i--)
|
|
{
|
|
LineObjectPool.Instance.PushItemToPool<LineItem>(l[i]);
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// 回收左侧对象(线缆组)
|
|
/// </summary>
|
|
public void Empty_line_content_left()
|
|
{
|
|
child_line_group_items.Clear();
|
|
var l = line_group_content.GetComponentsInChildren<LineGroupItem>(true);
|
|
for (int i = l.Length - 1; i >= 0; i--)
|
|
{
|
|
LineObjectPool.Instance.PushItemToPool<LineGroupItem>(l[i]);
|
|
}
|
|
}
|
|
}
|