96 lines
2.8 KiB
C#
96 lines
2.8 KiB
C#
using DG.Tweening;
|
||
using System.Collections;
|
||
using System.Collections.Generic;
|
||
using UnityEngine;
|
||
using UnityEngine.UI;
|
||
|
||
public class ToolFuncManager : MonoBehaviour
|
||
{
|
||
//在根节点下查找所有包含T组件的物体,InActice的也行
|
||
static public List<T> FindChildrenWithComponent<T>(Transform parentTF) where T : Component
|
||
{
|
||
List<T> result = new List<T>();
|
||
FindChildrenWithComponentRecursively<T>(parentTF, result);
|
||
return result;
|
||
}
|
||
|
||
static public T FindChildWithComponent<T>(Transform parentTF) where T : Component
|
||
{
|
||
T result = parentTF.GetComponent<T>();
|
||
if (result == null)
|
||
{
|
||
foreach (Transform childTF in parentTF)
|
||
result = FindChildWithComponent<T>(childTF);
|
||
}
|
||
return result;
|
||
}
|
||
|
||
static private void FindChildrenWithComponentRecursively<T>(Transform parentTF, List<T> result) where T : Component
|
||
{
|
||
for (int i = 0; i < parentTF.childCount; i++)
|
||
{
|
||
Transform childTF = parentTF.GetChild(i);
|
||
GameObject childGO = childTF.gameObject;
|
||
|
||
// 检查当前子物体是否包含目标组件
|
||
if (childGO.TryGetComponent<T>(out T component))
|
||
{
|
||
result.Add(childGO.GetComponent<T>());
|
||
}
|
||
|
||
// 递归查找子物体的子物体
|
||
FindChildrenWithComponentRecursively<T>(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;
|
||
}
|
||
|
||
/// <summary>
|
||
/// 计算两个list的交集数量
|
||
/// </summary>
|
||
/// <param name="L1"></param>
|
||
/// <param name="L2"></param>
|
||
/// <returns></returns>
|
||
public static int CountMatches(List<string> L1, List<string> 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>();
|
||
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.
|
||
}
|
||
}
|