99 lines
2.5 KiB
C#
99 lines
2.5 KiB
C#
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
using UnityEngine.UI;
|
|
|
|
public class LineGroupItem : MonoBehaviour
|
|
{
|
|
public string id;
|
|
/// <summary>
|
|
/// 标题
|
|
/// </summary>
|
|
public Text info_text;
|
|
/// <summary>
|
|
/// 删除
|
|
/// </summary>
|
|
public Button delete_button;
|
|
/// <summary>
|
|
/// 展开
|
|
/// </summary>
|
|
public Button expand_button;
|
|
/// <summary>
|
|
/// 线缆容器
|
|
/// </summary>
|
|
public GameObject line_item_content;
|
|
/// <summary>
|
|
/// 线缆组中的线
|
|
/// </summary>
|
|
public List<LineItem> child_line_items = new List<LineItem>();
|
|
|
|
bool do_init = false;
|
|
|
|
// Start is called before the first frame update
|
|
void Start()
|
|
{
|
|
if (!do_init)
|
|
Init();
|
|
}
|
|
|
|
public void Init()
|
|
{
|
|
do_init = true;
|
|
expand_button.onClick.AddListener(() =>
|
|
{
|
|
line_item_content.SetActive(!line_item_content.activeSelf);
|
|
});
|
|
delete_button.onClick.AddListener(() =>
|
|
{
|
|
//删除确认
|
|
SecondConfirmPanel.DeleteConform((delete) =>
|
|
{
|
|
if (delete)
|
|
{
|
|
var id = "";
|
|
foreach (var item in LineQuery.Inst.keyValues)
|
|
{
|
|
if (item.Key== info_text.text)
|
|
{
|
|
id = item.Value;
|
|
break;
|
|
}
|
|
}
|
|
if (string.IsNullOrEmpty(id)) return;
|
|
LineQuery.Inst.StartCoroutine(LineQuery.Inst.deleteJsonCoroutine(id,(x)=>
|
|
{
|
|
LineObjectPool.Instance.PushItemToPool(this);
|
|
}));
|
|
}
|
|
});
|
|
});
|
|
}
|
|
|
|
/// <summary>
|
|
/// 添加线缆
|
|
/// </summary>
|
|
[ContextMenu("添加")]
|
|
public void AddLineItem(string info)
|
|
{
|
|
var item = LineObjectPool.Instance.GetItemFromPool<LineItem>();
|
|
item.transform.SetParent(line_item_content.transform);
|
|
child_line_items.Add(item);
|
|
//传递数据
|
|
item.info_text.text = info;
|
|
}
|
|
|
|
/// <summary>
|
|
/// 回收至对象池
|
|
/// </summary>
|
|
public void Clear()
|
|
{
|
|
id = string.Empty;
|
|
info_text.text = string.Empty;
|
|
|
|
for (int i = 0; i < child_line_items.Count; i++)
|
|
{
|
|
LineObjectPool.Instance.PushItemToPool<LineItem>(child_line_items[i]);
|
|
}
|
|
}
|
|
}
|