完善功能

This commit is contained in:
shenjianxing 2025-02-18 10:49:11 +08:00
parent fa26f6d6a3
commit 992c5f6735
2 changed files with 47 additions and 26 deletions

View File

@ -17,7 +17,7 @@ GameObject:
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 0
m_IsActive: 1
--- !u!224 &5541630126728550664
RectTransform:
m_ObjectHideFlags: 0

View File

@ -143,41 +143,62 @@ namespace QFramework.Example
// 清空SearchContent下的所有子物体
SearchContent.RemoveAllChildren();
// 遍历Content下的所有子物体
for (int i = 0; i < Content.childCount; i++)
{
Transform child = Content.GetChild(i);
string name = child.Find("ToggleContent/Label").GetComponent<TextMeshProUGUI>().text;
// 检查子物体的名字是否包含搜索字符串
if (name.Contains(str))
{
// 复制该子物体到SearchContent中
GameObject clone = GameObject.Instantiate(SearchItem.gameObject, SearchContent);
if (child.Find("SubContent").childCount > 0)
{
clone.transform.Find("Button/Label").GetComponent<TextMeshProUGUI>().text = "(组)" + name;
}
else
{
clone.transform.Find("Button/Label").GetComponent<TextMeshProUGUI>().text = name;
}
}
// 递归检查子物体的子物体
CheckChildren(child, str);
}
// 递归检查子物体的子物体
CheckChildren(Content, str);
}
// 递归检查子物体的子物体
private void CheckChildren(Transform parent, string str)
{
// 遍历当前父物体下的所有子物体
for (int i = 0; i < parent.childCount; i++)
{
Transform child = parent.GetChild(i);
if (child.name.Contains(str))
// 尝试查找 ToggleContent/Label 组件
Transform labelTransform = child.Find("ToggleContent/Label");
if (labelTransform != null)
{
GameObject clone = GameObject.Instantiate(child.gameObject, SearchContent);
TextMeshProUGUI textComponent = labelTransform.GetComponent<TextMeshProUGUI>();
if (textComponent != null)
{
string name = textComponent.text;
// 检查子物体的名字是否包含搜索字符串
if (name.Contains(str))
{
// 复制该子物体到 SearchContent 中
GameObject clone = GameObject.Instantiate(SearchItem.gameObject, SearchContent);
Transform subContent = child.Find("SubContent");
// 检查是否有子内容
if (subContent.childCount > 0)
{
Transform buttonLabel = clone.transform.Find("Button/Label");
if (buttonLabel != null)
{
TextMeshProUGUI buttonText = buttonLabel.GetComponent<TextMeshProUGUI>();
if (buttonText != null)
{
buttonText.text = "(组)" + name;
}
}
// 递归检查当前子物体的子物体
CheckChildren(subContent, str);
}
else
{
Transform buttonLabel = clone.transform.Find("Button/Label");
if (buttonLabel != null)
{
TextMeshProUGUI buttonText = buttonLabel.GetComponent<TextMeshProUGUI>();
if (buttonText != null)
{
buttonText.text = name;
}
}
}
}
}
}
CheckChildren(child, str);
}
}