unity模糊查询
unity 模糊查询
你好! 这是你第一次使用 Markdown编辑器 所展示的欢迎页。如果你想学习如何使用Markdown编辑器, 可以仔细阅读这篇文章,了解一下Markdown的基本语法知识。
上代码
using System
.Collections
;
using System
.Collections
.Generic
;
using UnityEngine
;
using UnityEngine
.EventSystems
;
using UnityEngine
.UI
;
public class ReadText : MonoBehaviour
{
private InputField queries
;
private List
<string> allStr
= new List<string>();
private List
<string> currentStr
= new List<string>();
private Transform OSTObj
;
public GameObject InstantObj
;
private GameObject dropDownBox
;
private void Start()
{
queries
= transform
.Find("QueriesText").GetComponent<InputField>();
queries
.onValueChanged
.AddListener(Changed
);
OSTObj
= transform
.Find("Scroll View/Viewport/Content");
dropDownBox
=transform
.Find("Scroll View").gameObject
;
if (dropDownBox
.activeInHierarchy
)
dropDownBox
.SetActive(false);
allStr
.Add("afsdjjf");
allStr
.Add("sdfsgd");
allStr
.Add("gfhjghj");
allStr
.Add("khjgftrdf");
allStr
.Add("45fgfdg");
allStr
.Add("41fgfdg");
allStr
.Add("iuouio");
allStr
.Add("8845rs");
allStr
.Add("544fd54fds");
}
public void Changed(string str
)
{
if (!dropDownBox
.activeInHierarchy
)
dropDownBox
.SetActive(true);
ResetStr();
for (int i
= 0; i
< allStr
.Count
; i
++)
{
if (allStr
[i
].Contains(str
))
currentStr
.Add(allStr
[i
]);
}
for (int a
= 0; a
< currentStr
.Count
; a
++)
{
GameObject games
= Instantiate(InstantObj
, Vector3
.zero
, Quaternion
.identity
);
games
.name
= currentStr
[a
];
games
.GetComponentInChildren<Text>().text
= currentStr
[a
];
games
.transform
.parent
= OSTObj
.transform
;
games
.GetComponent<Button>().onClick
.AddListener(Listenevents
);
}
}
public void ResetStr()
{
currentStr
.Clear();
if (OSTObj
.childCount
> 0)
{
for (int i
= 0; i
< OSTObj
.childCount
; i
++)
Destroy(OSTObj
.GetChild(i
).gameObject
);
}
}
public void Listenevents()
{
queries
.text
= EventSystem
.current
.currentSelectedGameObject
.transform
.name
;
if (dropDownBox
.activeInHierarchy
)
dropDownBox
.SetActive(false);
}
}
[Dome **模糊查询
**](https
://download
.csdn
.net
/download
/qq_19323929
/12573758)