TBodyHit.cs 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645
  1. using System;
  2. using System.Collections.Generic;
  3. using System.IO;
  4. using UnityEngine;
  5. public class TBodyHit
  6. {
  7. public TBodyHit()
  8. {
  9. this.spherelist = new List<THitSphere>();
  10. }
  11. public void SetSphere(Transform t, string SaveName)
  12. {
  13. this.tRoot = t;
  14. this.MakeList(t, "ROOT", t);
  15. Debug.Log("BodyHit=" + this.spherelist.Count);
  16. string text = "G_Assets/_DAT/hitcheck";
  17. if (!Directory.Exists(text))
  18. {
  19. Directory.CreateDirectory(text);
  20. }
  21. BinaryWriter binaryWriter = new BinaryWriter(File.Create(text + "/" + SaveName + ".hitcheck"));
  22. int count = this.spherelist.Count;
  23. binaryWriter.Write("HitCheck");
  24. binaryWriter.Write(count);
  25. for (int i = 0; i < count; i++)
  26. {
  27. binaryWriter.Write(this.spherelist[i].type);
  28. binaryWriter.Write(this.spherelist[i].len);
  29. this.spherelist[i].len_ = this.spherelist[i].len;
  30. binaryWriter.Write(this.spherelist[i].lenxlen);
  31. this.spherelist[i].lenxlen_ = this.spherelist[i].lenxlen;
  32. binaryWriter.Write(this.spherelist[i].t.name);
  33. binaryWriter.Write(this.spherelist[i].t.parent.name);
  34. binaryWriter.Write(this.spherelist[i].t.localPosition.x);
  35. binaryWriter.Write(this.spherelist[i].t.localPosition.y);
  36. binaryWriter.Write(this.spherelist[i].t.localPosition.z);
  37. binaryWriter.Write(this.spherelist[i].SKRT);
  38. binaryWriter.Write(this.spherelist[i].RL);
  39. }
  40. binaryWriter.Close();
  41. }
  42. public void ScaleMune(string t, float fac)
  43. {
  44. if (t == "HARA")
  45. {
  46. this.HARA_FUTO = fac;
  47. }
  48. if (t == "MOMO")
  49. {
  50. this.MOMO_FUTO = fac;
  51. }
  52. if (t == "KOSHI_SCL")
  53. {
  54. this.KOSHI_SCL = fac;
  55. }
  56. if (t == "KOSHI_SVAL")
  57. {
  58. this.KOSHI_SVAL = fac;
  59. }
  60. if (t == "MUNE")
  61. {
  62. for (int i = 0; i < this.spherelist.Count; i++)
  63. {
  64. if (this.spherelist[i].SKRT == 99)
  65. {
  66. this.spherelist[i].len = this.spherelist[i].len_ * fac;
  67. this.spherelist[i].lenxlen = this.spherelist[i].len * this.spherelist[i].len;
  68. }
  69. }
  70. }
  71. }
  72. public void LoadSphereFromFile(Transform t, string FileName, string tag)
  73. {
  74. this.tRoot = t;
  75. this.BodySkinTAG = tag;
  76. MemoryStream input = null;
  77. using (AFileBase afileBase = GameUty.FileOpen(FileName, null))
  78. {
  79. if (afileBase == null || !afileBase.IsValid())
  80. {
  81. return;
  82. }
  83. input = new MemoryStream(afileBase.ReadAll());
  84. }
  85. BinaryReader binaryReader = new BinaryReader(input);
  86. if (binaryReader.ReadString() != "HitCheck")
  87. {
  88. binaryReader.Close();
  89. Debug.LogError("HitCheck header error!");
  90. return;
  91. }
  92. int num = binaryReader.ReadInt32();
  93. for (int i = 0; i < num; i++)
  94. {
  95. THitSphere thitSphere = new THitSphere();
  96. thitSphere.type = binaryReader.ReadInt32();
  97. thitSphere.len = binaryReader.ReadSingle();
  98. thitSphere.lenxlen = binaryReader.ReadSingle();
  99. thitSphere.lenxlen = thitSphere.len * thitSphere.len;
  100. thitSphere.lenxlen_ = thitSphere.lenxlen;
  101. thitSphere.len_ = thitSphere.len;
  102. thitSphere.name = binaryReader.ReadString();
  103. thitSphere.pname = binaryReader.ReadString();
  104. thitSphere.vs.x = binaryReader.ReadSingle();
  105. thitSphere.vs.y = binaryReader.ReadSingle();
  106. thitSphere.vs.z = binaryReader.ReadSingle();
  107. thitSphere.SKRT = binaryReader.ReadInt32();
  108. thitSphere.RL = binaryReader.ReadInt32();
  109. if (thitSphere.RL != -1 && thitSphere.SKRT == 1)
  110. {
  111. this.skrt_L1 = i;
  112. }
  113. if (thitSphere.RL != -1 && thitSphere.SKRT == 2)
  114. {
  115. this.skrt_L2 = i;
  116. }
  117. if (thitSphere.RL != -1 && thitSphere.SKRT == 3)
  118. {
  119. this.skrt_L3 = i;
  120. }
  121. if (thitSphere.RL == -1 && thitSphere.SKRT == 1)
  122. {
  123. this.skrt_R1 = i;
  124. }
  125. if (thitSphere.RL == -1 && thitSphere.SKRT == 2)
  126. {
  127. this.skrt_R2 = i;
  128. }
  129. if (thitSphere.RL == -1 && thitSphere.SKRT == 3)
  130. {
  131. this.skrt_R3 = i;
  132. }
  133. if (tag == THp.check_BONE)
  134. {
  135. Debug.LogWarning(string.Concat(new string[]
  136. {
  137. thitSphere.pname,
  138. ":",
  139. thitSphere.name,
  140. " : cnt=",
  141. this.SearchCountObj(thitSphere.pname, this.tRoot, 0).ToString()
  142. }));
  143. }
  144. thitSphere.t = this.SearchObj(thitSphere.pname, this.tRoot);
  145. if (thitSphere.t == null)
  146. {
  147. Debug.LogError("Hit sphere t=null " + thitSphere.pname);
  148. }
  149. this.spherelist.Add(thitSphere);
  150. if (tag == THp.check_BONE)
  151. {
  152. GameObject gameObject = UnityEngine.Object.Instantiate<GameObject>(GameObject.Find("SphereHIT"), Vector3.one * 0.3f, Quaternion.identity);
  153. float num2 = 1f;
  154. gameObject.transform.localScale = new Vector3(thitSphere.len / num2, thitSphere.len / num2, thitSphere.len / num2);
  155. gameObject.transform.localPosition = thitSphere.vs;
  156. gameObject.transform.parent = thitSphere.t;
  157. gameObject.transform.localPosition = thitSphere.vs;
  158. if (thitSphere.pname == "Mune_L")
  159. {
  160. }
  161. if (thitSphere.RL != 0)
  162. {
  163. gameObject.name = "SphereHIT_L";
  164. }
  165. else
  166. {
  167. gameObject.name = "SphereHIT_R";
  168. }
  169. thitSphere.tPtr = gameObject.transform;
  170. }
  171. }
  172. if (GameMain.Instance.VRMode && Application.isPlaying && FileName.ToLower() != "ik.hitcheck")
  173. {
  174. this.OvrAddHitSphere();
  175. }
  176. }
  177. private void OvrAddHitSphere()
  178. {
  179. string[] array = new string[]
  180. {
  181. "Sphere_HandHitL_",
  182. "Sphere_HandHitR_"
  183. };
  184. for (int i = 0; i < array.Length; i++)
  185. {
  186. THitSphere thitSphere = new THitSphere();
  187. thitSphere.type = 0;
  188. thitSphere.len = 0.1f;
  189. thitSphere.lenxlen = 0.01f;
  190. thitSphere.lenxlen = thitSphere.len * thitSphere.len;
  191. thitSphere.lenxlen_ = thitSphere.lenxlen;
  192. thitSphere.len_ = thitSphere.len;
  193. thitSphere.name = array[i];
  194. thitSphere.pname = "Bip01";
  195. thitSphere.vs.x = 0f;
  196. thitSphere.vs.y = -10000f;
  197. thitSphere.vs.z = 0f;
  198. thitSphere.SKRT = 0;
  199. thitSphere.RL = 1;
  200. thitSphere.t = this.SearchObj(thitSphere.pname, this.tRoot);
  201. if (thitSphere.t == null)
  202. {
  203. Debug.LogError("Hit sphere t=null " + thitSphere.pname);
  204. }
  205. this.spherelist.Add(thitSphere);
  206. if (i == 0)
  207. {
  208. this.m_listHandHitL.Add(thitSphere);
  209. }
  210. else
  211. {
  212. this.m_listHandHitR.Add(thitSphere);
  213. }
  214. }
  215. array = new string[]
  216. {
  217. "Sphere_HandHitLeapL_",
  218. "Sphere_HandHitLeapR_"
  219. };
  220. for (int j = 0; j < array.Length; j++)
  221. {
  222. THitSphere thitSphere2 = new THitSphere();
  223. thitSphere2.type = 0;
  224. thitSphere2.len = 0.1f;
  225. thitSphere2.lenxlen = 0.01f;
  226. thitSphere2.lenxlen = thitSphere2.len * thitSphere2.len;
  227. thitSphere2.lenxlen_ = thitSphere2.lenxlen;
  228. thitSphere2.len_ = thitSphere2.len;
  229. thitSphere2.name = array[j];
  230. thitSphere2.pname = "Bip01";
  231. thitSphere2.vs.x = 0f;
  232. thitSphere2.vs.y = -10000f;
  233. thitSphere2.vs.z = 0f;
  234. thitSphere2.SKRT = 0;
  235. thitSphere2.RL = 1;
  236. thitSphere2.t = this.SearchObj(thitSphere2.pname, this.tRoot);
  237. if (thitSphere2.t == null)
  238. {
  239. Debug.LogError("Hit sphere t=null " + thitSphere2.pname);
  240. }
  241. this.spherelist.Add(thitSphere2);
  242. if (j == 0)
  243. {
  244. this.m_HandHitLeapL = thitSphere2;
  245. }
  246. else
  247. {
  248. this.m_HandHitLeapR = thitSphere2;
  249. }
  250. }
  251. }
  252. private Transform SearchObj(string name, Transform t)
  253. {
  254. string name2 = t.name;
  255. if (name2.Contains("_IA_"))
  256. {
  257. return null;
  258. }
  259. if (name2 == name)
  260. {
  261. return t;
  262. }
  263. for (int i = 0; i < t.childCount; i++)
  264. {
  265. Transform transform = this.SearchObj(name, t.GetChild(i));
  266. if (transform != null)
  267. {
  268. return transform;
  269. }
  270. }
  271. return null;
  272. }
  273. private int SearchCountObj(string name, Transform t, int cnt = 0)
  274. {
  275. string name2 = t.name;
  276. if (name2.Contains("_IA_"))
  277. {
  278. return 0;
  279. }
  280. if (name2 == name)
  281. {
  282. cnt++;
  283. }
  284. for (int i = 0; i < t.childCount; i++)
  285. {
  286. cnt += this.SearchCountObj(name, t.GetChild(i), cnt);
  287. }
  288. return cnt;
  289. }
  290. private void MakeList(Transform t, string oyax, Transform root)
  291. {
  292. if (t.name.Contains("Sphere") || t.name.Contains("_SKRT_"))
  293. {
  294. string name = t.parent.name;
  295. THitSphere thitSphere = new THitSphere();
  296. thitSphere.t = t;
  297. thitSphere.len = t.localScale.x * 0.5f;
  298. thitSphere.lenxlen = thitSphere.len * thitSphere.len;
  299. thitSphere.SKRT = 0;
  300. if (t.name.Contains("_1_"))
  301. {
  302. thitSphere.SKRT = 1;
  303. }
  304. if (t.name.Contains("_2_"))
  305. {
  306. thitSphere.SKRT = 2;
  307. }
  308. if (t.name.Contains("_3_"))
  309. {
  310. thitSphere.SKRT = 3;
  311. }
  312. if (t.name.Contains("_MUNE_"))
  313. {
  314. thitSphere.SKRT = 99;
  315. }
  316. if (t.name.Contains("_UDE_"))
  317. {
  318. thitSphere.SKRT = 98;
  319. }
  320. if (t.name.Contains("_HARA_"))
  321. {
  322. thitSphere.SKRT = 97;
  323. }
  324. if (t.name.Contains("_MOMO_"))
  325. {
  326. thitSphere.SKRT = 96;
  327. }
  328. thitSphere.RL = 1;
  329. thitSphere.type = 0;
  330. if (t.parent.name == "Bip01 Head")
  331. {
  332. thitSphere.type = 1;
  333. }
  334. this.spherelist.Add(thitSphere);
  335. if (name.Contains("R") || t.name.Contains("_R_"))
  336. {
  337. Transform transform;
  338. if (t.name.Contains("_R_"))
  339. {
  340. transform = t.parent;
  341. }
  342. else
  343. {
  344. string text = string.Empty;
  345. int length = name.Length;
  346. for (int i = 0; i < length; i++)
  347. {
  348. char c = name[i];
  349. if (c == 'R')
  350. {
  351. c = 'L';
  352. }
  353. text += c.ToString();
  354. }
  355. transform = this.SearchObj(text, this.tRoot);
  356. }
  357. if (transform != null)
  358. {
  359. Transform transform2 = UnityEngine.Object.Instantiate<Transform>(t);
  360. if (transform2.name.Contains("_R_"))
  361. {
  362. transform2.name = "hit_copy";
  363. }
  364. THitSphere thitSphere2 = new THitSphere();
  365. thitSphere2.t = transform2;
  366. thitSphere2.SKRT = thitSphere.SKRT;
  367. thitSphere.RL = -1;
  368. transform2.position = new Vector3(root.position.x * 2f - t.position.x, t.position.y, t.position.z);
  369. transform2.parent = transform;
  370. thitSphere2.len = transform2.localScale.x * 0.5f;
  371. thitSphere2.lenxlen = thitSphere.len * thitSphere.len;
  372. thitSphere2.type = 0;
  373. this.spherelist.Add(thitSphere2);
  374. }
  375. }
  376. }
  377. List<Transform> list = new List<Transform>();
  378. for (int j = 0; j < t.childCount; j++)
  379. {
  380. list.Add(t.GetChild(j));
  381. }
  382. for (int k = 0; k < list.Count; k++)
  383. {
  384. this.MakeList(list[k], t.name, root);
  385. }
  386. }
  387. public void PreUpdate()
  388. {
  389. for (int i = 0; i < this.spherelist.Count; i++)
  390. {
  391. this.spherelist[i].wv_old = this.spherelist[i].wv;
  392. Vector3 wv = this.spherelist[i].t.TransformPoint(this.spherelist[i].vs);
  393. this.spherelist[i].wv = wv;
  394. if (this.spherelist[i].tPtr != null)
  395. {
  396. this.spherelist[i].len = this.spherelist[i].tPtr.localScale.x;
  397. this.spherelist[i].lenxlen = this.spherelist[i].len * this.spherelist[i].len;
  398. this.spherelist[i].tPtr.rotation = Quaternion.identity;
  399. this.spherelist[i].wv = this.spherelist[i].tPtr.position;
  400. }
  401. }
  402. }
  403. public bool SphereCheck(Vector3 v)
  404. {
  405. for (int i = 0; i < this.spherelist.Count; i++)
  406. {
  407. Vector3 wv = this.spherelist[i].wv;
  408. if ((v - wv).sqrMagnitude < this.spherelist[i].lenxlen)
  409. {
  410. return true;
  411. }
  412. }
  413. return false;
  414. }
  415. public bool SphereMove(ref Vector3 v, ref Vector3 g, Vector3 v_old)
  416. {
  417. bool result = false;
  418. for (int i = 0; i < this.spherelist.Count; i++)
  419. {
  420. Vector3 wv = this.spherelist[i].wv;
  421. if ((v - wv).sqrMagnitude < this.spherelist[i].lenxlen)
  422. {
  423. Vector3 normalized = (v_old - this.spherelist[i].wv_old).normalized;
  424. Vector3 a = wv + normalized * this.spherelist[i].len;
  425. v = a * 0.5f + v * 0.5f;
  426. if (this.spherelist[i].type == 0)
  427. {
  428. g *= 1f - Mathf.Abs(Vector3.Dot(normalized, g.normalized));
  429. g.y = 0f;
  430. }
  431. else
  432. {
  433. g.x *= 0.1f;
  434. g.y *= 0.95f;
  435. g.z *= 0.1f;
  436. }
  437. result = true;
  438. }
  439. }
  440. return result;
  441. }
  442. public bool SphereMove_skrt(ref Vector3 v, ref Vector3 g)
  443. {
  444. bool result = false;
  445. Vector3 a = Vector3.zero;
  446. float num = 0f;
  447. float num2 = 0f;
  448. for (int i = 0; i < this.spherelist.Count; i++)
  449. {
  450. Vector3 wv = this.spherelist[i].wv;
  451. Vector3 a2 = v - wv;
  452. float num3 = this.spherelist[i].len * (1f + _TS.TestVal3 * 2f);
  453. if (this.spherelist[i].SKRT == 96)
  454. {
  455. num3 *= this.SkirtFT;
  456. }
  457. if (a2.sqrMagnitude < num3 * num3)
  458. {
  459. float magnitude = a2.magnitude;
  460. a2 /= magnitude;
  461. float num4 = 1f - magnitude / num3;
  462. num2 += num4;
  463. num += num4;
  464. a += a2 * this.spherelist[i].len * num4;
  465. result = true;
  466. }
  467. }
  468. this.MST = num;
  469. if (num2 > 0.8f)
  470. {
  471. num2 = 0.8f;
  472. }
  473. g *= 1f - num2;
  474. if (num > 0.5f)
  475. {
  476. num -= 0.5f;
  477. this.MST_v = a * num;
  478. v += this.MST_v;
  479. }
  480. else
  481. {
  482. this.MST_v = Vector3.zero;
  483. }
  484. return result;
  485. }
  486. public bool SphereMove_skrtVSHOT(ref Vector3 v, ref Vector3 g, Vector3 vshot)
  487. {
  488. bool result = false;
  489. Vector3 a = Vector3.zero;
  490. float num = 0f;
  491. float num2 = 0f;
  492. for (int i = 0; i < this.spherelist.Count; i++)
  493. {
  494. Vector3 wv = this.spherelist[i].wv;
  495. Vector3 vector = v - wv;
  496. float num3 = this.spherelist[i].len * (1f + _TS.TestVal3 * 2f);
  497. if (vector.sqrMagnitude < num3 * num3)
  498. {
  499. float magnitude = vector.magnitude;
  500. float num4 = 1f - magnitude / num3;
  501. num2 += num4;
  502. num += num4;
  503. a += vshot * this.spherelist[i].len * num4;
  504. result = true;
  505. }
  506. }
  507. if (num2 > 0.8f)
  508. {
  509. num2 = 0.8f;
  510. }
  511. g *= 1f - num2;
  512. if (num > 0.5f)
  513. {
  514. num -= 0.5f;
  515. v += a * num;
  516. }
  517. return result;
  518. }
  519. public bool SphereMove_hair(ref Vector3 v, ref Vector3 g, Vector3 v2)
  520. {
  521. bool result = false;
  522. Vector3 a = Vector3.zero;
  523. float num = 0f;
  524. float num2 = 0f;
  525. for (int i = 0; i < this.spherelist.Count; i++)
  526. {
  527. Vector3 wv = this.spherelist[i].wv;
  528. Vector3 vector = v - wv;
  529. if (vector.sqrMagnitude < this.spherelist[i].lenxlen)
  530. {
  531. float magnitude = vector.magnitude;
  532. vector /= magnitude;
  533. float num3 = 1f - magnitude / this.spherelist[i].len;
  534. num3 *= num3;
  535. num2 += num3;
  536. a += vector;
  537. num += num3 * this.spherelist[i].len;
  538. result = true;
  539. }
  540. }
  541. if (num2 > 0.8f)
  542. {
  543. num2 = 0.8f;
  544. }
  545. g *= 1f - num2;
  546. a.Normalize();
  547. v += a * num;
  548. return result;
  549. }
  550. public bool SphereMove_hair2(ref Vector3 v, ref Vector3 g, Vector3 v_old)
  551. {
  552. bool result = false;
  553. Vector3 a = Vector3.zero;
  554. Vector3 a2 = Vector3.zero;
  555. float num = 0f;
  556. float num2 = 0f;
  557. for (int i = 0; i < this.spherelist.Count; i++)
  558. {
  559. Vector3 wv = this.spherelist[i].wv;
  560. Vector3 a3 = v - wv;
  561. float num3 = this.spherelist[i].len * (1f + _TS.TestVal2 * 2f);
  562. if (a3.sqrMagnitude < num3 * num3)
  563. {
  564. float magnitude = a3.magnitude;
  565. a3 /= magnitude;
  566. float num4 = 1f - magnitude / num3;
  567. num2 += num4;
  568. num += num4;
  569. a += a3 * this.spherelist[i].len * num4;
  570. Vector3 a4 = this.spherelist[i].wv - this.spherelist[i].wv_old;
  571. a2 += a4 * num4;
  572. result = true;
  573. }
  574. }
  575. num2 *= _TS.TestVal;
  576. if (num2 > 0.8f)
  577. {
  578. num2 = 0.8f;
  579. }
  580. g *= 1f - num2;
  581. if (num > 0.5f)
  582. {
  583. num -= 0.5f;
  584. v += a * num;
  585. }
  586. return result;
  587. }
  588. public float RotOffset;
  589. public List<THitSphere> spherelist;
  590. public Transform tRoot;
  591. public int skrt_R1;
  592. public int skrt_R2;
  593. public int skrt_R3;
  594. public int skrt_L1;
  595. public int skrt_L2;
  596. public int skrt_L3;
  597. public float MOMO_FUTO = 1f;
  598. public float HARA_FUTO;
  599. public float KOSHI_SCL = 1f;
  600. public float KOSHI_SVAL = 0.5f;
  601. public string BodySkinTAG;
  602. public List<THitSphere> m_listHandHitL = new List<THitSphere>();
  603. public List<THitSphere> m_listHandHitR = new List<THitSphere>();
  604. public THitSphere m_HandHitLeapL;
  605. public THitSphere m_HandHitLeapR;
  606. public float SkirtFT = 1f;
  607. public float MST;
  608. public Vector3 MST_v;
  609. }