CMT.cs 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. using System;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. public class CMT
  5. {
  6. public static Transform SearchObjName(Transform t, string name, bool boSMPass = true)
  7. {
  8. string name2 = t.name;
  9. if (boSMPass && name2.Contains("_SM_"))
  10. {
  11. return null;
  12. }
  13. if (name == "_ROOT_")
  14. {
  15. return t;
  16. }
  17. if (name2 == name)
  18. {
  19. return t;
  20. }
  21. for (int i = 0; i < t.childCount; i++)
  22. {
  23. Transform child = t.GetChild(i);
  24. Transform transform = CMT.SearchObjName(child, name, boSMPass);
  25. if (transform != null)
  26. {
  27. return transform;
  28. }
  29. }
  30. return null;
  31. }
  32. public static void SearchAndAddObj(Transform t, Dictionary<string, Transform> dic)
  33. {
  34. string name = t.name;
  35. if (name.Contains("_SM_"))
  36. {
  37. return;
  38. }
  39. dic[name] = t;
  40. for (int i = 0; i < t.childCount; i++)
  41. {
  42. CMT.SearchAndAddObj(t.GetChild(i), dic);
  43. }
  44. }
  45. public static Transform SearchObjObj(Transform tParent, Transform tSearch)
  46. {
  47. if (tParent == tSearch)
  48. {
  49. return tSearch;
  50. }
  51. for (int i = 0; i < tParent.childCount; i++)
  52. {
  53. Transform child = tParent.GetChild(i);
  54. Transform transform = CMT.SearchObjObj(child, tSearch);
  55. if (transform != null)
  56. {
  57. return transform;
  58. }
  59. }
  60. return null;
  61. }
  62. public static void BindTrans(List<Transform> listPosRot, List<Transform> listScl, Dictionary<string, Transform> body1, Transform t)
  63. {
  64. Transform item;
  65. if (body1.TryGetValue(t.name, out item))
  66. {
  67. listPosRot.Add(t);
  68. listPosRot.Add(item);
  69. if (t.name == "Mune_L" || t.name == "Mune_R")
  70. {
  71. listScl.Add(t);
  72. listScl.Add(item);
  73. }
  74. }
  75. for (int i = 0; i < t.childCount; i++)
  76. {
  77. CMT.BindTrans(listPosRot, listScl, body1, t.GetChild(i));
  78. }
  79. }
  80. public static void TestTrans(Transform t)
  81. {
  82. t.localRotation = Quaternion.identity;
  83. for (int i = 0; i < t.childCount; i++)
  84. {
  85. CMT.TestTrans(t.GetChild(i));
  86. }
  87. }
  88. public static void SetActiveFlag(Transform t, bool bo)
  89. {
  90. for (int i = 0; i < t.childCount; i++)
  91. {
  92. Transform child = t.GetChild(i);
  93. CMT.SetActiveFlag(child, bo);
  94. child.gameObject.SetActive(bo);
  95. }
  96. t.gameObject.SetActive(bo);
  97. }
  98. public static Transform SearchObjNameContainsLower(Transform t, string name, bool bIgnoreCase = false)
  99. {
  100. string name2 = t.name;
  101. if ((!bIgnoreCase) ? name2.Contains(name) : name2.ToLower().Contains(name))
  102. {
  103. return t;
  104. }
  105. for (int i = 0; i < t.childCount; i++)
  106. {
  107. Transform child = t.GetChild(i);
  108. Transform transform = CMT.SearchObjNameContainsLower(child, name, bIgnoreCase);
  109. if (transform != null)
  110. {
  111. return transform;
  112. }
  113. }
  114. return null;
  115. }
  116. }