Framwork/Assets/Scripts/Base/MonoBehaviour/UIGameObjectBinding.cs

54 lines
1.0 KiB
C#

using System.Linq;
using Sirenix.OdinInspector;
using UnityEngine;
namespace HK
{
public class UIGameObjectBinding : GameObjectBinding
{
private string[] strs = new string[]
{
"img",
"tog",
"txt",
"btn",
"obj",
"sli",
"inp",
"dro",
};
#if UNITY_EDITOR
[Button("自动添加UI控件")]
void AutoAddUIGameObject()
{
FindChild(transform);
}
void FindChild(Transform self)
{
if (CheckName(self.name))
{
AddValue(self);
}
for (var i = 0; i < self.childCount; i++)
{
FindChild(self.GetChild(i));
}
}
bool CheckName(string str)
{
foreach (var se in strs)
{
if (str.Contains(se))
{
return true;
}
}
return false;
}
#endif
}
}