167 lines
4.7 KiB
C#
167 lines
4.7 KiB
C#
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;
|
|
/// <summary>
|
|
/// 当前选中的线缆组名
|
|
/// </summary>
|
|
public string selected_group_name;
|
|
public InputField line_group_name_inputfield;
|
|
/// <summary>
|
|
/// 新增线缆组弹窗
|
|
/// </summary>
|
|
public GameObject add_group_pop;
|
|
/// <summary>
|
|
/// 新增按钮
|
|
/// </summary>
|
|
public Button add_group;
|
|
/// <summary>
|
|
/// 保存新增线缆组
|
|
/// </summary>
|
|
public Button add_line_group_button;
|
|
/// <summary>
|
|
/// 取消新增线缆组
|
|
/// </summary>
|
|
public Button cancel_line_group_button;
|
|
/// <summary>
|
|
/// 线缆组容器
|
|
/// </summary>
|
|
public GameObject line_group_content;
|
|
|
|
/// <summary>
|
|
/// 线缆容器(右)
|
|
/// </summary>
|
|
public GameObject line_content_right;
|
|
|
|
public List<LineGroupItem> child_line_group_items = new List<LineGroupItem>();
|
|
|
|
private void Start()
|
|
{
|
|
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));
|
|
}
|
|
});
|
|
cancel_line_group_button.onClick.AddListener(() =>
|
|
{
|
|
add_group_pop.SetActive(false);
|
|
line_group_name_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>();
|
|
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))
|
|
{
|
|
lineGroupItem.AddLineItem(item.name, item.lines);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
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;
|
|
panel_object.SetActive(true);
|
|
AddLineGroupInit();
|
|
}
|
|
|
|
/// <summary>
|
|
/// 隐藏面板
|
|
/// </summary>
|
|
public void HidePanel()
|
|
{
|
|
selected_group_name = 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;
|
|
}
|
|
|
|
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>();
|
|
for (int i = l.Length - 1; i >= 0; i--)
|
|
{
|
|
LineObjectPool.Instance.PushItemToPool<LineItem>(l[i]);
|
|
}
|
|
}
|
|
}
|