using DG.Tweening; using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.UI; public class ToolFuncManager : MonoBehaviour { //在根节点下查找所有包含T组件的物体,InActice的也行 static public List FindChildrenWithComponent(Transform parentTF) where T : Component { List result = new List(); FindChildrenWithComponentRecursively(parentTF, result); return result; } static public T FindChildWithComponent(Transform parentTF) where T : Component { T result = parentTF.GetComponent(); if (result == null) { foreach (Transform childTF in parentTF) result = FindChildWithComponent(childTF); } return result; } static private void FindChildrenWithComponentRecursively(Transform parentTF, List result) where T : Component { for (int i = 0; i < parentTF.childCount; i++) { Transform childTF = parentTF.GetChild(i); GameObject childGO = childTF.gameObject; // 检查当前子物体是否包含目标组件 if (childGO.TryGetComponent(out T component)) { result.Add(childGO.GetComponent()); } // 递归查找子物体的子物体 FindChildrenWithComponentRecursively(childTF, result); } } //在根节点下查找名称为childName物体,InActice的也行 static public Transform GetChild(Transform parentTF, string childName) { //在子物体中查找 childName = childName.Trim(); Transform childTF = parentTF.Find(childName); if (childTF != null) return childTF; //将问题交给子物体 for (int i = 0; i < parentTF.childCount; i++) { childTF = GetChild(parentTF.GetChild(i), childName); if (childTF != null) return childTF; } return null; } /// /// 计算两个list的交集数量 /// /// /// /// public static int CountMatches(List L1, List L2) { int count = 0; foreach (string item in L2) { if (L1.Contains(item)) { count++; } } return count; } public static void ActiveEmbededTip(GameObject tip, Tween tween = null)//激活界面中已经嵌入的提示 { if (tween != null) tween.Kill(true); tip.gameObject.SetActive(true); Image image = tip.GetComponent(); image.enabled = true; tween = DOVirtual.Float(1, 0.3f, 0.5f, t => { Color finalColor = image.color; finalColor.a = t; image.color = finalColor; }).SetLoops(-1, LoopType.Yoyo);//HQB 原始数值:1,0. } }