using System;
using UnityEngine;
namespace LastZero.Utility
{
public static class SearchController {
/// <summary>
/// 搜索
/// </summary>
/// <param name="parent">父物体</param>
/// <param name="key">关键字</param>
public static void Search(Transform parent, string key)
{
for (int i = 0; i < parent.childCount; i++)
{
if (parent.GetChild(i).name.Contains(key,StringComparison.OrdinalIgnoreCase))
{
parent.GetChild(i).gameObject.SetActive(true);
}
else
{
parent.GetChild(i).gameObject.SetActive(false);
}
}
}
/// <summary>
/// 还原
/// </summary>
/// <param name="parent">父物体</param>
public static void Reset(Transform parent)
{
for (int i = 0; i < parent.childCount; i++)
{
parent.GetChild(i).gameObject.SetActive(true);
}
}
/// <summary>
/// 判断是否包含某字符串(不区分大小写)
/// </summary>
/// <param name="input">被查找字符串</param>
/// <param name="strChecked">检查是否含有的字符串</param>
/// <returns>bool</returns>
public static bool Contains(this string input, string strChecked, StringComparison stringComparison)
{
return input.IndexOf(strChecked, stringComparison) >= 0;//StringComparison枚举定义一些规则,OrdinalIgnoreCase为忽略大小写
}
}
}
StringComparison枚举,详见下面链接