using System; using System.Collections.Generic; using UnityEngine; using Object = UnityEngine.Object; namespace Game { public static class CommonHelper { public static T FindChildDeep(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(); 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 FindChildDeeps(this Transform self) where T : Object { List list = new List(); FindDeeps(self, ref list); if (list.Count <= 0) { Debug.LogError("未找到此组件"); } return list; } static void FindDeeps(Transform tran, ref List list) { var component = tran.GetComponent(); 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(UIType.GlobalLogOnlyAppUI); ui.AddLog(message); } public static void OpenAndSetTips(string content, Action sure = null, string btnSure = "确定", string btnClose = "关闭") { var ui = Game.uiManager.ShowUI(UIType.GlobalTipsUI); var globalTipsUI = ui as GlobalTipsUI; globalTipsUI.SetContent(content, btnSure, sure, btnClose); } } }