TBoneHair_.cs 9.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410
  1. using System;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. public class TBoneHair_
  5. {
  6. public TBoneHair_(TBodySkin bs)
  7. {
  8. this.bodyskin = bs;
  9. if (bs != null)
  10. {
  11. this.body = bs.body;
  12. }
  13. }
  14. public void SearchGameObj(GameObject obj, bool bNoSkirt = false)
  15. {
  16. if (this.bodyhit == null)
  17. {
  18. return;
  19. }
  20. this.hair1list = new List<THair1>();
  21. this.SkirtList = new THair1[24];
  22. this.SkirtListDBL = new THair1[48];
  23. this.boSkirt = false;
  24. this.m_listBoneScaleDef.Clear();
  25. Transform transform = obj.transform;
  26. for (int i = 0; i < transform.childCount; i++)
  27. {
  28. this.SearchHair(transform.GetChild(i).transform, transform, bNoSkirt);
  29. }
  30. int num = 0;
  31. int num2 = 0;
  32. for (int j = 0; j < 24; j++)
  33. {
  34. if (this.SkirtList[j] != null)
  35. {
  36. if (num2 == 0)
  37. {
  38. num2 = this.SkirtList[j].hplist.Count;
  39. }
  40. else if (num2 != this.SkirtList[j].hplist.Count)
  41. {
  42. Debug.LogError("Skirt Bone Count ERROR!!");
  43. break;
  44. }
  45. num++;
  46. }
  47. }
  48. if (1 <= num && num < 12)
  49. {
  50. Debug.LogError("error. skirt 12 > " + num);
  51. }
  52. if (12 <= num)
  53. {
  54. this.m_nSkirtCountW = num;
  55. this.m_nSkirtCountH = this.m_nSkirtCountW * 2;
  56. this.boSkirt = true;
  57. for (int k = 0; k < this.m_nSkirtCountW; k++)
  58. {
  59. this.SkirtList[k].SetPair(this.SkirtList[(k + this.m_nSkirtCountW - 1) % this.m_nSkirtCountW], this.SkirtList[(k + 1) % this.m_nSkirtCountW]);
  60. }
  61. for (int l = 0; l < this.m_nSkirtCountW; l++)
  62. {
  63. this.SkirtListDBL[l * 2] = this.SkirtList[l];
  64. }
  65. for (int m = 0; m < this.m_nSkirtCountW; m++)
  66. {
  67. this.SkirtListDBL[m * 2 + 1] = new THair1(this, this.SkirtList[m].root, this.SkirtList[m].root_oya, this.bodyhit, this.SkirtList[m], this.SkirtList[(m + 1) % this.m_nSkirtCountW]);
  68. }
  69. for (int n = 0; n < this.m_nSkirtCountH; n++)
  70. {
  71. this.SkirtListDBL[n].SetPair(this.SkirtListDBL[(n + this.m_nSkirtCountH - 1) % this.m_nSkirtCountH], this.SkirtListDBL[(n + 1) % this.m_nSkirtCountH]);
  72. }
  73. for (int num3 = 0; num3 < this.m_nSkirtCountH; num3++)
  74. {
  75. this.SkirtListDBL[num3].CheckPair(num3);
  76. }
  77. }
  78. this.m_bEnable = true;
  79. }
  80. private void SearchHair(Transform t, Transform t_oya, bool bNoSkirt = false)
  81. {
  82. bool flag = false;
  83. if (t.transform.childCount == 0)
  84. {
  85. return;
  86. }
  87. HairMode hairMode = HairMode.non;
  88. Vector3 softG = new Vector3(0f, -0.003f, 0f);
  89. float num = 0.05f;
  90. float p = 0.5f;
  91. int num2 = -1;
  92. if (t.name.Contains("_yure_"))
  93. {
  94. if (t.name.Contains("_skirt_") && !bNoSkirt)
  95. {
  96. for (int i = 1; i <= 24; i++)
  97. {
  98. if (t.name.Contains(i.ToString("D2")))
  99. {
  100. num2 = i - 1;
  101. break;
  102. }
  103. }
  104. if (num2 >= 0)
  105. {
  106. hairMode = HairMode.skrt;
  107. }
  108. }
  109. else if (t.name.Contains("_yure_hair_"))
  110. {
  111. hairMode = HairMode.hair;
  112. }
  113. else if (t.name.Contains("_yure_soft_"))
  114. {
  115. hairMode = HairMode.ribbon;
  116. }
  117. else if (t.name.Contains("_yure_hard_"))
  118. {
  119. hairMode = HairMode.ribbon;
  120. }
  121. }
  122. if (hairMode != HairMode.non)
  123. {
  124. if (this.JumpChkT == null)
  125. {
  126. this.JumpChkT = t;
  127. }
  128. if (hairMode == HairMode.skrt && (t.localScale.x < 0.999f || 1.001f < t.localScale.x || t.localScale.y < 0.999f || 1.001f < t.localScale.y || t.localScale.z < 0.999f || 1.001f < t.localScale.z))
  129. {
  130. this.m_listBoneScaleDef.Add(new BoneScaleDef(t, t.localPosition, t.localRotation, t.localScale));
  131. t.localScale = Vector3.one;
  132. Transform transform = t;
  133. while (transform.childCount != 0)
  134. {
  135. transform = transform.GetChild(0);
  136. this.m_listBoneScaleDef.Add(new BoneScaleDef(transform, transform.localPosition, transform.localRotation, transform.localScale));
  137. transform.localScale = Vector3.one;
  138. }
  139. }
  140. THair1 thair = new THair1(this, t, t_oya, this.bodyhit, null, null);
  141. if (thair.hplist.Count <= 2)
  142. {
  143. Debug.LogError(t.name + " " + thair.hplist.Count);
  144. }
  145. thair.Mode = hairMode;
  146. if (hairMode != HairMode.hair)
  147. {
  148. if (hairMode == HairMode.ribbon)
  149. {
  150. if (t.name.Contains("_yure_hard_"))
  151. {
  152. thair.boHard = true;
  153. }
  154. if (thair.pointCount == 1)
  155. {
  156. p = 10f;
  157. if (thair.boHard)
  158. {
  159. num *= 2f;
  160. }
  161. }
  162. }
  163. else if (hairMode == HairMode.skrt)
  164. {
  165. num = 0.05f;
  166. p = 0.3f;
  167. softG = new Vector3(0f, -0.01f, 0f);
  168. }
  169. }
  170. thair.SoftG = softG;
  171. if (hairMode == HairMode.skrt)
  172. {
  173. this.SkirtList[num2] = thair;
  174. }
  175. else
  176. {
  177. thair.KusariIDX = this.hair1list.Count;
  178. this.hair1list.Add(thair);
  179. }
  180. int num3 = 0;
  181. foreach (THp thp in thair.hplist)
  182. {
  183. Transform t2 = thp.t;
  184. if (t2.name.Contains("_yure_"))
  185. {
  186. if (t2.name.Contains("_skirt_"))
  187. {
  188. num = 0.5f;
  189. p = 0.9f;
  190. if (t2.name.Contains("_h_"))
  191. {
  192. num = 0.95f;
  193. p = 99999f;
  194. }
  195. }
  196. else if (t2.name.Contains("_yure_hair_"))
  197. {
  198. num = 0.05f;
  199. p = 0.3f;
  200. if (t2.name.Contains("_h_"))
  201. {
  202. num = 0.5f;
  203. p = 3f;
  204. }
  205. if (t2.name.Contains("_h50_"))
  206. {
  207. num = 0.1f;
  208. p = 1f;
  209. }
  210. }
  211. else if (t2.name.Contains("_yure_soft_"))
  212. {
  213. num = 0.05f;
  214. p = 0.5f;
  215. }
  216. else if (t2.name.Contains("_yure_hard_"))
  217. {
  218. num = 0.1f;
  219. p = 1f;
  220. }
  221. }
  222. float softPer = Mathf.Pow((float)num3 / (float)thair.hplist.Count, p);
  223. thp.SoftPer = softPer;
  224. thp.SoftTgtG = num;
  225. num3++;
  226. }
  227. flag = true;
  228. }
  229. if (!flag)
  230. {
  231. for (int j = 0; j < t.childCount; j++)
  232. {
  233. this.SearchHair(t.GetChild(j), t, bNoSkirt);
  234. }
  235. }
  236. }
  237. public void Init()
  238. {
  239. this.m_bEnable = false;
  240. this.hair1list = new List<THair1>();
  241. }
  242. public void LoadHitCheck(Transform root, string fn, int rot, string tag)
  243. {
  244. this.bodyhit = new TBodyHit();
  245. this.bodyhit.LoadSphereFromFile(root, fn, tag);
  246. this.bodyhit.RotOffset = (float)rot;
  247. }
  248. public void SaveData(Transform rootBody, string SaveName)
  249. {
  250. this.bodyhit = new TBodyHit();
  251. this.bodyhit.SetSphere(rootBody, SaveName);
  252. this.hair1list = new List<THair1>();
  253. }
  254. public void Update()
  255. {
  256. if (!this.m_bEnable || this.bodyhit == null)
  257. {
  258. return;
  259. }
  260. bool upDefTgt = false;
  261. if (this.JumpChkT != null)
  262. {
  263. upDefTgt = ((this.JumpChkPos - this.JumpChkT.position).magnitude > 0.1f);
  264. this.JumpChkPos = this.JumpChkT.position;
  265. }
  266. if (this.m_listBoneScaleDef.Count != 0)
  267. {
  268. for (int i = 0; i < this.m_listBoneScaleDef.Count; i++)
  269. {
  270. BoneScaleDef boneScaleDef = this.m_listBoneScaleDef[i];
  271. boneScaleDef.trTarget.localPosition = boneScaleDef.vBackPos;
  272. boneScaleDef.trTarget.localRotation = boneScaleDef.qBackRot;
  273. boneScaleDef.trTarget.localScale = boneScaleDef.vBackScale;
  274. }
  275. }
  276. this.bodyhit.PreUpdate();
  277. this.boneAxis = this.boneAxis0;
  278. for (int j = 0; j < this.hair1list.Count; j++)
  279. {
  280. this.hair1list[(j + 4) % this.hair1list.Count].SetUpDefTgt(upDefTgt);
  281. }
  282. for (int k = 0; k < this.hair1list.Count; k++)
  283. {
  284. this.hair1list[(k + 4) % this.hair1list.Count].Calc(this.bodyhit);
  285. }
  286. for (int l = 0; l < this.hair1list.Count; l++)
  287. {
  288. this.hair1list[(l + 4) % this.hair1list.Count].Proc(this.bodyhit);
  289. }
  290. if (this.boSkirt)
  291. {
  292. this.bodyhit.SkirtFT = 1f + this.body.JumpDis * 0.5f;
  293. for (int m = 0; m < 2; m++)
  294. {
  295. for (int n = 0; n < this.m_nSkirtCountW; n++)
  296. {
  297. this.SkirtListDBL[n * 2].SetUpDefTgt(upDefTgt);
  298. }
  299. for (int num = 0; num < this.m_nSkirtCountW; num++)
  300. {
  301. this.SkirtListDBL[num * 2 + 1].SetUpDefTgt(upDefTgt);
  302. }
  303. for (int num2 = 1; num2 < this.SkirtListDBL[0].hplist.Count; num2++)
  304. {
  305. for (int num3 = 0; num3 < this.m_nSkirtCountH; num3++)
  306. {
  307. this.SkirtListDBL[num3].Calc_skirt2(num2);
  308. }
  309. }
  310. for (int num4 = 1; num4 < this.SkirtListDBL[0].hplist.Count; num4++)
  311. {
  312. for (int num5 = 0; num5 < this.m_nSkirtCountH; num5++)
  313. {
  314. this.SkirtListDBL[num5].Calc_skirt_up(num4);
  315. }
  316. }
  317. for (int num6 = 1; num6 < this.SkirtListDBL[0].hplist.Count; num6++)
  318. {
  319. for (int num7 = 0; num7 < this.m_nSkirtCountH; num7++)
  320. {
  321. int num8 = (num7 + this.m_nSkirtCountW) % this.m_nSkirtCountH;
  322. this.SkirtListDBL[num8].Calc_skirt_pair(num6);
  323. }
  324. }
  325. for (int num9 = 0; num9 < this.m_nSkirtCountH; num9++)
  326. {
  327. this.SkirtListDBL[num9].Proc(this.bodyhit);
  328. }
  329. }
  330. }
  331. if (this.m_listBoneScaleDef.Count != 0)
  332. {
  333. for (int num10 = 0; num10 < this.m_listBoneScaleDef.Count; num10++)
  334. {
  335. BoneScaleDef boneScaleDef2 = this.m_listBoneScaleDef[num10];
  336. boneScaleDef2.vBackPos = boneScaleDef2.trTarget.localPosition;
  337. boneScaleDef2.qBackRot = boneScaleDef2.trTarget.localRotation;
  338. boneScaleDef2.vBackScale = boneScaleDef2.trTarget.localScale;
  339. }
  340. }
  341. if (this.m_listBoneScaleDef.Count != 0)
  342. {
  343. for (int num11 = 0; num11 < this.m_listBoneScaleDef.Count; num11++)
  344. {
  345. BoneScaleDef boneScaleDef3 = this.m_listBoneScaleDef[num11];
  346. boneScaleDef3.trTarget.localPosition = boneScaleDef3.vDefPos;
  347. boneScaleDef3.trTarget.localRotation = boneScaleDef3.qDefRot;
  348. boneScaleDef3.trTarget.localScale = boneScaleDef3.vDefScale;
  349. }
  350. }
  351. }
  352. public void DrawGizmos()
  353. {
  354. if (this.bodyhit == null)
  355. {
  356. return;
  357. }
  358. foreach (THitSphere thitSphere in this.bodyhit.spherelist)
  359. {
  360. if (thitSphere.t != null)
  361. {
  362. Gizmos.DrawWireSphere(thitSphere.t.TransformPoint(thitSphere.vs), thitSphere.len);
  363. }
  364. }
  365. }
  366. private Transform JumpChkT;
  367. private Vector3 JumpChkPos = new Vector3(0f, 0f, 0f);
  368. public Transform[] trsKusari = new Transform[24];
  369. public TBody body;
  370. public TBodySkin bodyskin;
  371. public bool boSkirt;
  372. private List<THair1> hair1list;
  373. public const int SKIRT_W_MAX = 24;
  374. public const int SKIRT_H_MAX = 48;
  375. private int m_nSkirtCountW;
  376. private int m_nSkirtCountH;
  377. private THair1[] SkirtList;
  378. private THair1[] SkirtListDBL = new THair1[24];
  379. public TBodyHit bodyhit;
  380. public Vector3 boneAxis0 = new Vector3(-90f, 0f, 0f);
  381. public Vector3 boneAxis = new Vector3(-90f, 0f, 0f);
  382. private bool m_bEnable;
  383. private List<BoneScaleDef> m_listBoneScaleDef = new List<BoneScaleDef>();
  384. }