123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123 |
- using System;
- using System.Collections.Generic;
- using UnityEngine;
- public class CMT
- {
- public static Transform SearchObjName(Transform t, string name, bool boSMPass = true)
- {
- string name2 = t.name;
- if (boSMPass && name2.Contains("_SM_"))
- {
- return null;
- }
- if (name == "_ROOT_")
- {
- return t;
- }
- if (name2 == name)
- {
- return t;
- }
- for (int i = 0; i < t.childCount; i++)
- {
- Transform child = t.GetChild(i);
- Transform transform = CMT.SearchObjName(child, name, boSMPass);
- if (transform != null)
- {
- return transform;
- }
- }
- return null;
- }
- public static void SearchAndAddObj(Transform t, Dictionary<string, Transform> dic)
- {
- string name = t.name;
- if (name.Contains("_SM_"))
- {
- return;
- }
- dic[name] = t;
- for (int i = 0; i < t.childCount; i++)
- {
- CMT.SearchAndAddObj(t.GetChild(i), dic);
- }
- }
- public static Transform SearchObjObj(Transform tParent, Transform tSearch)
- {
- if (tParent == tSearch)
- {
- return tSearch;
- }
- for (int i = 0; i < tParent.childCount; i++)
- {
- Transform child = tParent.GetChild(i);
- Transform transform = CMT.SearchObjObj(child, tSearch);
- if (transform != null)
- {
- return transform;
- }
- }
- return null;
- }
- public static void BindTrans(List<Transform> listPosRot, List<Transform> listScl, Dictionary<string, Transform> body1, Transform t)
- {
- Transform item;
- if (body1.TryGetValue(t.name, out item))
- {
- listPosRot.Add(t);
- listPosRot.Add(item);
- if (t.name == "Mune_L" || t.name == "Mune_R")
- {
- listScl.Add(t);
- listScl.Add(item);
- }
- }
- for (int i = 0; i < t.childCount; i++)
- {
- CMT.BindTrans(listPosRot, listScl, body1, t.GetChild(i));
- }
- }
- public static void TestTrans(Transform t)
- {
- t.localRotation = Quaternion.identity;
- for (int i = 0; i < t.childCount; i++)
- {
- CMT.TestTrans(t.GetChild(i));
- }
- }
- public static void SetActiveFlag(Transform t, bool bo)
- {
- for (int i = 0; i < t.childCount; i++)
- {
- Transform child = t.GetChild(i);
- CMT.SetActiveFlag(child, bo);
- child.gameObject.SetActive(bo);
- }
- t.gameObject.SetActive(bo);
- }
- public static Transform SearchObjNameContainsLower(Transform t, string name, bool bIgnoreCase = false)
- {
- string name2 = t.name;
- if ((!bIgnoreCase) ? name2.Contains(name) : name2.ToLower().Contains(name))
- {
- return t;
- }
- for (int i = 0; i < t.childCount; i++)
- {
- Transform child = t.GetChild(i);
- Transform transform = CMT.SearchObjNameContainsLower(child, name, bIgnoreCase);
- if (transform != null)
- {
- return transform;
- }
- }
- return null;
- }
- }
|