65 lines
1.7 KiB
C#
65 lines
1.7 KiB
C#
using System.Collections.Generic;
|
|
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);
|
|
}
|
|
}
|
|
|
|
public static List<T> FindChildDeeps<T>(this Transform self) where T : Object
|
|
{
|
|
List<T> list = new List<T>();
|
|
FindDeeps(self, ref list);
|
|
if (list.Count <= 0)
|
|
{
|
|
Debug.LogError("未找到此组件");
|
|
}
|
|
|
|
return list;
|
|
}
|
|
|
|
static void FindDeeps<T>(Transform tran, ref List<T> list)
|
|
{
|
|
var component = tran.GetComponent<T>();
|
|
if (component != null)
|
|
list.Add(component);
|
|
|
|
for (var i = 0; i < tran.childCount; i++)
|
|
{
|
|
FindDeeps(tran.GetChild(i), ref list);
|
|
}
|
|
}
|
|
|
|
public static void AddAppLog(string message)
|
|
{
|
|
var ui = Game.uiManager.GetUI<GlobalLogOnlyAppUI>(UIType.GlobalLogOnlyAppUI);
|
|
ui.AddLog(message);
|
|
}
|
|
}
|
|
} |