BoneHair2.cs 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190
  1. using System;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. public class BoneHair2
  5. {
  6. public BoneHair2(TBodySkin bodyskin)
  7. {
  8. this.m_BodySkin = bodyskin;
  9. }
  10. public void Init()
  11. {
  12. }
  13. public void Uninit()
  14. {
  15. if (this.m_listCollders != null)
  16. {
  17. for (int i = 0; i < this.m_listCollders.Count; i++)
  18. {
  19. if (this.m_listCollders[i] != null)
  20. {
  21. UnityEngine.Object.DestroyImmediate(this.m_listCollders[i].gameObject);
  22. }
  23. }
  24. this.m_listCollders.Clear();
  25. }
  26. }
  27. public bool InitGameObject(GameObject f_goRoot, MPN f_mpn)
  28. {
  29. BoneHair2.YureType yureType = BoneHair2.YureType.Non;
  30. Transform transform = this.SearchYureBone(f_goRoot.transform, out yureType);
  31. if (transform == null || yureType == BoneHair2.YureType.Non || yureType == BoneHair2.YureType.Skirt)
  32. {
  33. return false;
  34. }
  35. Transform parent = transform.parent;
  36. if (parent == null)
  37. {
  38. NDebug.Assert(transform.name + " の親が不正です。", false);
  39. }
  40. if (yureType == BoneHair2.YureType.Hair && parent.name.ToLower().IndexOf("hair") != 0)
  41. {
  42. NDebug.Assert("髪ボーン" + transform.name + " の親が不正です。", false);
  43. }
  44. string text = f_goRoot.name.Replace("_SM_", string.Empty);
  45. float[] f_aryDefStiffness = null;
  46. if (f_mpn == MPN.hairf)
  47. {
  48. f_aryDefStiffness = new float[]
  49. {
  50. 0.95f,
  51. 0.9f,
  52. 0.7f
  53. };
  54. }
  55. DynamicBone dynamicBone = ImportCM.TryLoadDynamicBone(f_goRoot, parent, text, this.m_BodySkin.body, f_aryDefStiffness);
  56. if (dynamicBone == null)
  57. {
  58. string f_strFileName = string.Empty;
  59. if (yureType == BoneHair2.YureType.Hair)
  60. {
  61. f_strFileName = "default_hair";
  62. if (f_mpn == MPN.hairf)
  63. {
  64. if (GameUty.IsExistFile("default_hairf.phy", null))
  65. {
  66. f_strFileName = "default_hairf";
  67. }
  68. }
  69. else if (f_mpn == MPN.hairr)
  70. {
  71. if (GameUty.IsExistFile("default_hairr.phy", null))
  72. {
  73. f_strFileName = "default_hairr";
  74. }
  75. }
  76. else if (f_mpn == MPN.hairs)
  77. {
  78. if (GameUty.IsExistFile("default_hairs.phy", null))
  79. {
  80. f_strFileName = "default_hairs";
  81. }
  82. }
  83. else if (f_mpn == MPN.hairt && GameUty.IsExistFile("default_hairt.phy", null))
  84. {
  85. f_strFileName = "default_hairt";
  86. }
  87. }
  88. else if (yureType == BoneHair2.YureType.Yure)
  89. {
  90. if (f_mpn != MPN.hairaho)
  91. {
  92. return false;
  93. }
  94. f_strFileName = "default_haira";
  95. }
  96. else if (yureType == BoneHair2.YureType.Skirt)
  97. {
  98. f_strFileName = "default_yure";
  99. }
  100. dynamicBone = ImportCM.TryLoadDynamicBone(f_goRoot, parent, f_strFileName, this.m_BodySkin.body, f_aryDefStiffness);
  101. if (dynamicBone == null)
  102. {
  103. return false;
  104. }
  105. }
  106. if (!string.IsNullOrEmpty(dynamicBone.m_ColliderFileName))
  107. {
  108. ImportCM.LoadDynamicCollilder(dynamicBone, dynamicBone.m_ColliderFileName, this.m_BodySkin.body.m_trBones, this.m_BodySkin.body.maid);
  109. }
  110. else if (GameUty.IsExistFile(text + ".col", null))
  111. {
  112. ImportCM.LoadDynamicCollilder(dynamicBone, text, this.m_BodySkin.body.m_trBones, this.m_BodySkin.body.maid);
  113. }
  114. else
  115. {
  116. string text2 = string.Empty;
  117. if (f_mpn == MPN.hairf)
  118. {
  119. text2 = "default_hairf";
  120. }
  121. else if (f_mpn == MPN.hairr)
  122. {
  123. text2 = "default_hairr";
  124. }
  125. else if (f_mpn == MPN.hairt)
  126. {
  127. text2 = "default_hairt";
  128. }
  129. else if (f_mpn == MPN.hairs)
  130. {
  131. text2 = "default_hairs";
  132. }
  133. else if (f_mpn == MPN.hairaho)
  134. {
  135. text2 = "default_haira";
  136. }
  137. if (!string.IsNullOrEmpty(text2))
  138. {
  139. ImportCM.LoadDynamicCollilder(dynamicBone, text2, this.m_BodySkin.body.m_trBones, this.m_BodySkin.body.maid);
  140. }
  141. }
  142. this.m_listCollders = dynamicBone.m_Colliders;
  143. return true;
  144. }
  145. private Transform SearchYureBone(Transform f_goParent, out BoneHair2.YureType f_eYureType)
  146. {
  147. if (f_goParent.name.Contains("_yure_hair_"))
  148. {
  149. f_eYureType = BoneHair2.YureType.Hair;
  150. return f_goParent;
  151. }
  152. if (f_goParent.name.Contains("_yure_skirt_"))
  153. {
  154. f_eYureType = BoneHair2.YureType.Skirt;
  155. return f_goParent;
  156. }
  157. if (f_goParent.name.Contains("_yure_"))
  158. {
  159. f_eYureType = BoneHair2.YureType.Yure;
  160. return f_goParent;
  161. }
  162. for (int i = 0; i < f_goParent.childCount; i++)
  163. {
  164. Transform transform = this.SearchYureBone(f_goParent.GetChild(i), out f_eYureType);
  165. if (transform != null)
  166. {
  167. return transform;
  168. }
  169. }
  170. f_eYureType = BoneHair2.YureType.Non;
  171. return null;
  172. }
  173. private TBodySkin m_BodySkin;
  174. private List<DynamicBoneColliderBase> m_listCollders;
  175. private enum YureType
  176. {
  177. Non,
  178. Hair,
  179. Skirt,
  180. Yure
  181. }
  182. }