GQ_Communicate/GQ_TongXin/Assets/Scripts/SearchName.cs

360 lines
11 KiB
C#

using DG.Tweening;
using System;
using System.Collections.Generic;
using TMPro;
using UnityEngine;
using UnityEngine.UI;
/// <summary>
/// 搜索框
/// </summary>
public class SearchName : MonoBehaviour
{
public GameObject scrollView;
public Transform scrollViewContent;
public TMP_InputField inputField;
public GameObject prefabsText;
[Header("加入需要搜索的设备名称")]
public List<GameObject> objs = new List<GameObject>();
public List<string> objs_str = new List<string>();
//展示的名字
private List<string> SearchObjects = new List<string>();
public List<GameObject> button_objects = new List<GameObject>();
public SearchType searchType;
void Start()
{
//searchType = SearchType.None;
//scrollView.SetActive(false);
InputFieldEvent();
}
void InputFieldEvent()
{
inputField.onValueChanged.AddListener(a =>
{
if (searchType == SearchType.None)
return;
if (a != "")
{
Serach(a);
}
else
{
Serach(null);
}
});
}
public void Serach(string strName = null)
{
if (string.IsNullOrEmpty(strName))
{
for (int i = 0; i < scrollViewContent.childCount; i++)
{
scrollViewContent.GetChild(i).gameObject.SetActive(true);
}
return;
}
//SearchObjects.Clear();
for (int i = 0; i < scrollViewContent.childCount; i++)
{
//Destroy(scrollViewContent.GetChild(i).gameObject);
scrollViewContent.GetChild(i).gameObject.SetActive(false);
}
int index = 0;
foreach (var go in objs_str)
{
if (!string.IsNullOrEmpty(strName))
{
if (go.Contains(strName))
{
//SearchObjects.Add(go);
scrollViewContent.GetChild(index).gameObject.SetActive(true);
}
}
//else
//{
// SearchObjects.Add(go);
//}
index++;
}
//if (string.IsNullOrEmpty(strName))
//{
// for (int i = 0; i < scrollViewContent.childCount; i++)
// {
// //Destroy(scrollViewContent.GetChild(i).gameObject);
// scrollViewContent.GetChild(i).gameObject.SetActive(true);
// }
//}
for (int i = 0; i < SearchObjects.Count; i++)
{
//GameObject tmp = Instantiate(prefabsText, scrollViewContent, false);
//TextMeshProUGUI text = tmp.GetComponentInChildren<TextMeshProUGUI>();
TextMeshProUGUI text = scrollViewContent.GetChild(i).GetComponentInChildren<TextMeshProUGUI>();
text.text = SearchObjects[i];
}
addonClick();
}
/// <summary>
/// 机柜列表
/// </summary>
public void LoadCabinet(SearchType type)
{
searchType = type;
if (!gameObject.activeSelf)
gameObject.SetActive(true);
init();
for (int i = 0; i < GameManager.Inst.Cabinets_go.Count; i++)
{
objs.Add(GameManager.Inst.Cabinets_go[i]);
string s = GameManager.Inst.Cabinets_go[i].GetComponent<DeviceQuery>().deviceList.deviceName;
objs_str.Add(s);
SearchObjects.Add(s);
}
for (int i = 0; i < SearchObjects.Count; i++)
{
GameObject tmp = Instantiate(prefabsText, scrollViewContent, false);
TextMeshProUGUI text = tmp.GetComponentInChildren<TextMeshProUGUI>();
text.text = SearchObjects[i];
button_objects.Add(tmp);
}
addonClick();
}
/// <summary>
/// 添加列表点击方法
/// </summary>
public void addonClick()
{
int childCount = SearchObjects.Count;
for (int i = 0; i < childCount; i++)
{
int co = i;
int eventCount = scrollViewContent.GetChild(i).GetComponent<Button>().onClick.GetPersistentEventCount();
if (eventCount > 0)
scrollViewContent.GetChild(i).GetComponent<Button>().onClick.RemoveAllListeners();
//FindGo(objs, i, (go) =>
//{
//var jigui = GameManager.Inst.FindParent(scrollViewContent.GetChild(i).gameObject, GameManager.Inst.IsDesiredParent);
switch (searchType)
{
case SearchType.None:
break;
case SearchType.:
{
scrollViewContent.GetChild(co).GetComponent<Button>().onClick.AddListener(() =>
{
Debug.Log(co);
objs[co].GetComponent<ClickEvent>().Change_hide(objs[co],true,true);
//if (jigui)
//{
// jigui.GetComponent<ClickEvent>().Zoomin();
//}
});
}
break;
case SearchType.线_展示:
{
scrollViewContent.GetChild(co).GetComponent<Button>().onClick.AddListener(() =>
{
TransparentGlowManage.Inst.transparencyALL(GameObject.Find("机柜").GetComponentsInChildren<TransparentGlow>());
CreateLine createLine = PatternChoose.Inst.transform.Find("画线").GetComponent<CreateLine>();
//var lines = createLine.xianLan.Find(objs[i].GetComponent<PortQuery>().portList.remark).GetComponent<LineInfor>().lines;
//var A = GameManager.Inst.FindParent(objs[co].gameObject, GameManager.Inst.IsDesiredParent);
////var B = GameManager.Inst.FindParent(lines[1].gameObject, GameManager.Inst.IsDesiredParent);
//var B_ = Array.Find(GameManager.Inst.TmsPorts_go.ToArray(), (item) =>
// {
// try
// {
// return (item.GetComponent<PortQuery>().portList.conPort == objs[co].GetComponent<PortQuery>().portList.port &&
// item.GetComponent<PortQuery>().portList.remark == objs[co].GetComponent<PortQuery>().portList.remark);
// }
// catch
// {
// return false;
// }
// });
//var B = GameManager.Inst.FindParent(B_, GameManager.Inst.IsDesiredParent);
//List<TransparentGlow> transparentGlows = new List<TransparentGlow>();
//transparentGlows.Add(A.GetComponent<TransparentGlow>());
//transparentGlows.Add(B.GetComponent<TransparentGlow>());
List<TransparentGlow> transparentGlows = new List<TransparentGlow>();
Array.ForEach(GameObject.Find("线缆").GetComponentsInChildren<LineInfor>(), (item) =>
{
if (item.name != objs_str[co])
return;
GameObject go1= GameManager.Inst.FindParent(item.lines[0].gameObject, GameManager.Inst.IsDesiredParent);
GameObject go2 = GameManager.Inst.FindParent( item.lines[1].gameObject, GameManager.Inst.IsDesiredParent);
transparentGlows.Add(go1.GetComponent<TransparentGlow>());
transparentGlows.Add(go2.GetComponent<TransparentGlow>());
});
TransparentGlowManage.Inst.renewALL(transparentGlows.ToArray());
});
}
break;
default:
break;
}
//});
}
}
Predicate<Transform> findCabinet = (Transform go) =>
{
//端口-设备 go.parent
//端口-板卡-设备 go.parent.parent
var p = go.parent;
if (p.parent.parent.parent.parent.GetComponent<DeviceQuery>())
{
if (p.parent.parent.parent.parent.GetComponent<DeviceQuery>().deviceList.type == "1")
{
return true;
}
else if (p.parent.parent.parent.GetComponent<DeviceQuery>())
{
if (p.parent.parent.parent.GetComponent<DeviceQuery>().deviceList.type == "1")
{
return true;
}
}
}
else if (p.parent.parent.parent.GetComponent<DeviceQuery>())
{
if (p.parent.parent.parent.GetComponent<DeviceQuery>().deviceList.type == "1")
{
return true;
}
}
return false;
};
private bool Isitive(Transform obj)
{
throw new NotImplementedException();
}
// 寻找机柜
void FindGo(List<GameObject> objs, int index, Action<GameObject> callback)
{
GameObject go = null;
try
{
go = objs[index].transform.Find(objs[index].name).gameObject;
}
catch
{
go = objs[index];
}
callback?.Invoke(go);
}
public void LoadXianLan(SearchType type)
{
searchType = type;
if (!gameObject.activeSelf)
gameObject.SetActive(true);
init();
Dictionary<string, string> dic = new Dictionary<string, string>();
CreateLine createLine = PatternChoose.Inst.transform.Find("画线").GetComponent<CreateLine>();
for (int i = 0; i < createLine.list7.Count; i++)
{
if (i != 0 && i % 2 != 0)
{
objs.Add(createLine.list7[i].gameObject);
string s = createLine.list7[i].GetComponent<PortQuery>().portList.cableGroupName;
if (dic.ContainsKey(s))
continue;
dic.Add(s, "");
objs_str.Add(s);
SearchObjects.Add(s);
}
}
for (int i = 0; i < SearchObjects.Count; i++)
{
GameObject tmp = Instantiate(prefabsText, scrollViewContent, false);
TextMeshProUGUI text = tmp.GetComponentInChildren<TextMeshProUGUI>();
text.text = SearchObjects[i];
}
TransparentGlowManage.Inst.renewALL(GameObject.Find("机柜").GetComponentsInChildren<TransparentGlow>());
addonClick();
}
void init()
{
for (int i = 0; i < scrollViewContent.childCount; i++)
{
Destroy(scrollViewContent.GetChild(i).gameObject);
}
objs.Clear();
objs_str.Clear();
SearchObjects.Clear();
button_objects.Clear();
inputField.transform.Find("Text Area/Placeholder").GetComponent<TextMeshProUGUI>().text = "请输入要搜索的" + searchType.ToString().Split('_')[0];
scrollView.transform.Find("表头/Text (TMP)").GetComponent<TextMeshProUGUI>().text = searchType.ToString().Split('_')[0] + "名称";
}
private void Update()
{
}
/// <summary>
/// 搜索框类型
/// </summary>
public enum SearchType
{
None,
,
线_展示
}
}