using DG.Tweening;
using System;
using System.Collections.Generic;
using TMPro;
using UnityEngine;
using UnityEngine.EventSystems;
using UnityEngine.UI;
///
/// 搜索框
///
public class SearchName : MonoBehaviour
{
public GameObject scrollView;
public Transform scrollViewContent;
public TMP_InputField inputField;
public GameObject prefabsText;
///
/// 搜索按钮
///
public Button serarchBtn;
[Header("加入需要搜索的设备名称")]
public List objs = new List();
public List objs_str = new List();
//展示的名字
private List SearchObjects = new List();
public List button_objects = new List();
public SearchType searchType;
///
/// 线缆组中不包含线缆的线缆组名
///
public Dictionary dic_notContain = new Dictionary();
public float initialHeight;
public RectTransform rectTransform;
public GameObject biaoTou;
public Image bg;
private void Awake()
{
rectTransform = scrollView.GetComponent();
initialHeight = rectTransform.sizeDelta.y;
rectTransform.sizeDelta = new Vector2(rectTransform.sizeDelta.x, 0);
gameObject.SetActive(false);
biaoTou.SetActive(false);
}
void Start()
{
//searchType = SearchType.None;
//scrollView.SetActive(false);
InputFieldEvent();
OnClickSearchBtn();
}
private void OnClickSearchBtn()
{
serarchBtn.onClick.AddListener(() =>
{
show_menu();
});
}
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 text = scrollViewContent.GetChild(i).GetComponentInChildren();
text.text = SearchObjects[i];
}
addonClick();
}
///
/// 机柜列表
///
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().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();
text.text = SearchObjects[i];
button_objects.Add(tmp);
}
addonClick();
}
///
/// 添加列表点击方法
///
public void addonClick()
{
int childCount = SearchObjects.Count;
for (int i = 0; i < childCount; i++)
{
int co = i;
int eventCount = scrollViewContent.GetChild(i).GetComponent