204 lines
6.6 KiB
C#
204 lines
6.6 KiB
C#
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using Unity.VisualScripting;
|
|
//using UnityEditor.Experimental.GraphView;
|
|
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 edit_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;
|
|
|
|
public Sprite normalSprite; // 按钮的默认状态
|
|
public Sprite selectedSprite; // 按钮被按下时的状态
|
|
|
|
/// <summary>
|
|
/// 所有的展开按钮
|
|
/// </summary>
|
|
[SerializeField] List<Button> buttons = new List<Button>();
|
|
|
|
private void Awake()
|
|
{
|
|
normalSprite = expand_button.image.sprite;
|
|
SpriteState spriteState = expand_button.spriteState;
|
|
selectedSprite = spriteState.selectedSprite;
|
|
}
|
|
|
|
private void OnEnable()
|
|
{
|
|
if (buttons.Count != 0)
|
|
{
|
|
for (int i = 0; i < buttons.Count; i++)
|
|
buttons[i].image.sprite = normalSprite;
|
|
}
|
|
}
|
|
|
|
// Start is called before the first frame update
|
|
void Start()
|
|
{
|
|
if (!do_init)
|
|
Init();
|
|
}
|
|
|
|
public void Init()
|
|
{
|
|
do_init = true;
|
|
expand_button.onClick.AddListener(() =>
|
|
{
|
|
//按钮变色
|
|
var groupItems = LineGroupManager.Instance.line_group_content.GetComponentsInChildren<LineGroupItem>().ToList();
|
|
buttons = groupItems.Select(item => item.expand_button).ToList();
|
|
for (int i = 0; i < buttons.Count; i++)
|
|
buttons[i].image.sprite = normalSprite;
|
|
expand_button.image.sprite = selectedSprite;
|
|
|
|
showRightPop();
|
|
//return;
|
|
//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;
|
|
// }
|
|
//}
|
|
id = this.id;
|
|
if (!string.IsNullOrEmpty(id))
|
|
{
|
|
LineQuery.Inst.StartCoroutine(LineQuery.Inst.deleteJsonCoroutine(id, (x) =>
|
|
{
|
|
if (!string.IsNullOrEmpty(x))
|
|
{
|
|
for (int i = 0; i < PatternChoose.Inst.xianlan.transform.childCount; i++)
|
|
{
|
|
if (PatternChoose.Inst.xianlan.transform.GetChild(i).name == info_text.text)
|
|
{
|
|
DestroyImmediate(PatternChoose.Inst.xianlan.transform.GetChild(i).gameObject);
|
|
break;
|
|
}
|
|
}
|
|
LineObjectPool.Instance.PushItemToPool(this);
|
|
}
|
|
else
|
|
{
|
|
Debug.LogError("删除线缆组失败:" + x);
|
|
}
|
|
}));
|
|
}
|
|
else
|
|
{
|
|
LineObjectPool.Instance.PushItemToPool(this);
|
|
}
|
|
}
|
|
});
|
|
});
|
|
edit_button.onClick.AddListener(() =>
|
|
{
|
|
LineGroupManager.Instance.line_group_editName_inputfield.text = info_text.text;
|
|
showRightPop();
|
|
LineGroupManager.Instance.edit_group_pop.SetActive(true);
|
|
});
|
|
|
|
}
|
|
|
|
/// <summary>
|
|
/// 添加线缆
|
|
/// </summary>
|
|
[ContextMenu("添加")]
|
|
public void AddLineItem(string info, List<Transform> lines, List<string> strings)
|
|
{
|
|
var item = LineObjectPool.Instance.GetItemFromPool<LineItem>();
|
|
item.transform.SetParent(line_item_content.transform);
|
|
child_line_items.Add(item);
|
|
//传递数据
|
|
item.info_text.text = info;
|
|
item.item_tittle_start_text.text = strings[0].Replace("$", " ");
|
|
item.item_tittle_end_text.text = strings[1].Replace("$", " ");
|
|
item.gameObject.GetComponent<LocatingCable>().lines = lines;
|
|
}
|
|
|
|
/// <summary>
|
|
/// 回收至对象池
|
|
/// </summary>
|
|
public void Clear()
|
|
{
|
|
if (normalSprite != null)
|
|
expand_button.image.sprite = normalSprite;
|
|
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]);
|
|
}
|
|
child_line_items.Clear();
|
|
}
|
|
|
|
public void ClearChilds()
|
|
{
|
|
for (int i = 0; i < child_line_items.Count; i++)
|
|
{
|
|
LineObjectPool.Instance.PushItemToPool<LineItem>(child_line_items[i]);
|
|
}
|
|
child_line_items.Clear();
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
/// 显示右侧(线缆目录)
|
|
/// </summary>
|
|
public void showRightPop()
|
|
{
|
|
LineGroupManager.Instance.selected_group_name = info_text.text;
|
|
LineGroupManager.Instance.selected_group_ID = this.id;
|
|
LineGroupManager.Instance.Empty_line_content_right();
|
|
for (int i = 0; i < child_line_items.Count; i++)
|
|
{
|
|
LineItem item = LineObjectPool.Instance.GetItemFromPool<LineItem>();
|
|
item.transform.SetParent(LineGroupManager.Instance.line_content_right.transform);
|
|
item.info_text.text = child_line_items[i].info_text.text;
|
|
item.item_tittle_start_text.text = child_line_items[i].item_tittle_start_text.text;
|
|
item.item_tittle_end_text.text = child_line_items[i].item_tittle_end_text.text;
|
|
item.lineGroupItem = child_line_items[i].transform.parent.parent.GetComponent<LineGroupItem>();
|
|
item.gameObject.GetComponent<LocatingCable>().lines = child_line_items[i].GetComponent<LocatingCable>().lines;
|
|
}
|
|
}
|
|
}
|