BoneHair2.cs 4.1 KB

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