CMT.cs 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  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 SearchAndAddTrans(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.SearchAndAddTrans(t.GetChild(i), dic);
  43. }
  44. }
  45. public static void SearchAndAddObj(Transform t, Dictionary<string, Transform> dic)
  46. {
  47. string name = t.name;
  48. if (name.Contains("_SM_"))
  49. {
  50. return;
  51. }
  52. dic[name] = t;
  53. for (int i = 0; i < t.childCount; i++)
  54. {
  55. CMT.SearchAndAddObj(t.GetChild(i), dic);
  56. }
  57. }
  58. public static Transform SearchObjObj(Transform tParent, Transform tSearch)
  59. {
  60. if (tParent == tSearch)
  61. {
  62. return tSearch;
  63. }
  64. for (int i = 0; i < tParent.childCount; i++)
  65. {
  66. Transform child = tParent.GetChild(i);
  67. Transform transform = CMT.SearchObjObj(child, tSearch);
  68. if (transform != null)
  69. {
  70. return transform;
  71. }
  72. }
  73. return null;
  74. }
  75. public static void BindTrans(List<Transform> listPosRot, List<Transform> listScl, Dictionary<string, Transform> body1, Transform t, bool is_crc_body = false)
  76. {
  77. Transform item;
  78. if (body1.TryGetValue(t.name, out item))
  79. {
  80. listPosRot.Add(t);
  81. listPosRot.Add(item);
  82. if (t.name == "Mune_L" || t.name == "Mune_R")
  83. {
  84. listScl.Add(t);
  85. listScl.Add(item);
  86. }
  87. else if (is_crc_body && t.name.Contains("chinko"))
  88. {
  89. listScl.Add(t);
  90. listScl.Add(item);
  91. }
  92. }
  93. for (int i = 0; i < t.childCount; i++)
  94. {
  95. CMT.BindTrans(listPosRot, listScl, body1, t.GetChild(i), is_crc_body);
  96. }
  97. }
  98. public static void TestTrans(Transform t)
  99. {
  100. t.localRotation = Quaternion.identity;
  101. for (int i = 0; i < t.childCount; i++)
  102. {
  103. CMT.TestTrans(t.GetChild(i));
  104. }
  105. }
  106. public static void SetActiveFlag(Transform t, bool bo)
  107. {
  108. for (int i = 0; i < t.childCount; i++)
  109. {
  110. Transform child = t.GetChild(i);
  111. CMT.SetActiveFlag(child, bo);
  112. child.gameObject.SetActive(bo);
  113. }
  114. t.gameObject.SetActive(bo);
  115. }
  116. public static Transform SearchObjNameContainsLower(Transform t, string name, bool bIgnoreCase = false)
  117. {
  118. string name2 = t.name;
  119. if ((!bIgnoreCase) ? name2.Contains(name) : name2.ToLower().Contains(name))
  120. {
  121. return t;
  122. }
  123. for (int i = 0; i < t.childCount; i++)
  124. {
  125. Transform child = t.GetChild(i);
  126. Transform transform = CMT.SearchObjNameContainsLower(child, name, bIgnoreCase);
  127. if (transform != null)
  128. {
  129. return transform;
  130. }
  131. }
  132. return null;
  133. }
  134. }