TBodyHit.cs 15 KB

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