34 lines
865 B
C#
34 lines
865 B
C#
using UnityEngine;
|
|
|
|
namespace Game
|
|
{
|
|
public static class CommonHelper
|
|
{
|
|
public static T FindChildDeep<T>(this Transform self, string name) where T : Object
|
|
{
|
|
Transform findDeep = null;
|
|
FindDeep(self, name, ref findDeep);
|
|
if (findDeep == null)
|
|
{
|
|
Debug.LogError("未找到此组件");
|
|
}
|
|
|
|
var component = findDeep.GetComponent<T>();
|
|
return component;
|
|
}
|
|
|
|
static void FindDeep(Transform tran, string name, ref Transform transform)
|
|
{
|
|
if (tran.name == name)
|
|
{
|
|
transform = tran;
|
|
return;
|
|
}
|
|
|
|
for (var i = 0; i < tran.childCount; i++)
|
|
{
|
|
FindDeep(tran.GetChild(i), name, ref transform);
|
|
}
|
|
}
|
|
}
|
|
} |