using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class LineGroupManager : MonoBehaviour
{
public static LineGroupManager Instance;
private void Awake()
{
Instance = this;
}
public GameObject panel_object;
public InputField line_group_name_inputfield;
public Button add_line_group_button;
///
/// 线缆组容器
///
public GameObject line_group_content;
public List child_line_group_items = new List();
private void Start()
{
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));
}
});
}
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))
{
lineGroupItem.AddLineItem(item.name);
}
}
}
}
}
public void AddLineGroupInit()
{
foreach (var item in LineQuery.Inst.keyValues)
{
if (!string.IsNullOrWhiteSpace(item.Key))
{
AddLineGroup(item.Key);
}
}
}
///
/// 显示面板
///
public void ShowPanel()
{
panel_object.SetActive(true);
AddLineGroupInit();
}
///
/// 隐藏面板
///
public void HidePanel()
{
panel_object.SetActive(false);
}
///
/// 添加线缆组
///
///
public void AddLineGroup(string name, 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;
}
var item = LineObjectPool.Instance.GetItemFromPool();
item.transform.SetParent(line_group_content.transform);
child_line_group_items.Add(item);
//传递数据
item.info_text.text = name;
//处理完毕后清空输入框
line_group_name_inputfield.SetTextWithoutNotify("");
}
}