GQ_Communicate/GQ_URP/GQ/Assets/Scripts/WJ/LineGroup/LineItem.cs

110 lines
3.7 KiB
C#

using UnityEngine;
using UnityEngine.UI;
public class LineItem : MonoBehaviour
{
public LineGroupItem lineGroupItem;
public string id;
public Text info_text;
public Text item_tittle_start_text;
public Text item_tittle_end_text;
public Button delete_button;
public Button set_button;
bool do_init = false;
public LineItem(string _id, Text _info_text, Button _delete_button, Button _set_button, bool isgo = false)
{
if (isgo)
{
id = _id;
info_text = _info_text;
delete_button = _delete_button;
set_button = _set_button;
}
}
private void OnEnable()
{
var g = GameManager.Inst.FindParent(gameObject, GameManager.Inst.IsFindLineGroupItem);
if (g != null && !lineGroupItem)
lineGroupItem = g.GetComponent<LineGroupItem>();
}
// Start is called before the first frame update
void Start()
{
if (!do_init)
Init();
}
public void Init()
{
do_init = true;
if (set_button)
set_button.onClick.AddListener(() =>
{
LineGroupManager.Instance.panel_object.SetActive(false);
Debug.Log("ÐÞ¸Ä");
//ÅÐ¶ÏÆðʼ¶Ë¿Ú
LocatingCable locatingCable = GetComponent<LocatingCable>();
PortQuery p = new PortQuery();
if (locatingCable.lines[0].GetComponent<PortQuery>().portList.startFlag == 1)
{
p = locatingCable.lines[0].GetComponent<PortQuery>();
GameManager.Inst.nowDevice = locatingCable.lines[0].gameObject;
RedactPort.Inst.PortList1_game = locatingCable.lines[0].gameObject;
RedactPort.Inst.PortList2 = locatingCable.lines[1].GetComponent<PortQuery>().portList;
}
else
{
p = locatingCable.lines[1].GetComponent<PortQuery>();
GameManager.Inst.nowDevice = locatingCable.lines[1].gameObject;
RedactPort.Inst.PortList1_game = locatingCable.lines[1].gameObject;
RedactPort.Inst.PortList2 = locatingCable.lines[0].GetComponent<PortQuery>().portList;
}
GameManager.Inst.nowDeviceID = p.portList.id;
RedactPort.Inst.PortList1 = p.portList;
RedactPort.Inst.OnToggleChanged(RedactPort.Inst.toggle);
RedactPort.Inst.AutoShowInfo(RedactPort.Inst.PortList1);
PatternChoose.Inst.dk_bj_page.SetActive(true);
});
delete_button.onClick.AddListener(() =>
{
//ɾ³ýÈ·ÈÏ
SecondConfirmPanel.DeleteConform((delete) =>
{
if (delete)
{
//LineGroupItem lineGroup = transform.parent.parent.GetComponent<LineGroupItem>();
//LineQuery.Inst.deleteCableName(lineGroupItem.info_text.text, info_text.text, (x) =>
LineQuery.Inst.deleteCableName(GetComponent<LocatingCable>(), (x) =>
{
if (!string.IsNullOrEmpty(x))
{
LineObjectPool.Instance.PushItemToPool(this);
}
else
{
Debug.Log("¶Ë¿ÚIDΪ¿Õ");
}
});
}
});
});
}
/// <summary>
/// Çå³ý×ÔÉíÐÅÏ¢ÒÔ¹©Ï´ÎʹÓÃ
/// </summary>
public void Clear()
{
id = string.Empty;
info_text.text = string.Empty;
lineGroupItem = null;
}
}