using System.Collections; using System.Collections.Generic; using UnityEngine; using TMPro; using UnityEngine.UI; using System; using DG.Tweening; using Unity.VisualScripting; public class SearchName : MonoBehaviour { public GameObject scrollView; public Transform scrollViewContent; public TMP_InputField inputField; public GameObject prefabsText; [Header("加入需要搜索的设备名称")] public List objs = new List(); public List objs_str = new List(); //展示的名字 private List SearchObjects = new List(); void Start() { //scrollView.SetActive(false); InputFieldEvent(); } void InputFieldEvent() { inputField.onValueChanged.AddListener(a => { if (a != "") { scrollView.SetActive(true); Serach(a); } else { scrollView.SetActive(true); Serach(); } }); } public void Serach(string strName = null) { 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(); text.text = SearchObjects[i]; } addonClick(); } /// /// 机柜列表 /// public void LoadCabinet() { if (!gameObject.activeSelf) gameObject.SetActive(true); else return; for (int i = 0; i < scrollViewContent.childCount; i++) { Destroy(scrollViewContent.GetChild(i).gameObject); } objs.Clear(); objs_str.Clear(); SearchObjects.Clear(); for (int i = 0; i < GameManager.Inst.Cabinets_go.Count; i++) { objs.Add(GameManager.Inst.Cabinets_go[i]); objs_str.Add(GameManager.Inst.Cabinets_go[i].GetComponent().deviceList.deviceCode); SearchObjects.Add(GameManager.Inst.Cabinets_go[i].GetComponent().deviceList.deviceCode); } for (int i = 0; i < SearchObjects.Count; i++) { GameObject tmp = Instantiate(prefabsText, scrollViewContent, false); TextMeshProUGUI text = tmp.GetComponentInChildren(); text.text = SearchObjects[i]; } addonClick(); } public void addonClick() { int childCount = SearchObjects.Count; for (int i = 0; i < childCount; i++) { GameObject go; try { go = objs[i].transform.Find(objs[i].name).gameObject; } catch (Exception) { go = objs[i]; } scrollViewContent.GetChild(i).GetComponent