KupaCtrl.cs 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542
  1. using System;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. public class KupaCtrl
  5. {
  6. public KupaCtrl(TBody body0, TMorph morph)
  7. {
  8. this.m_morph = morph;
  9. this.m_body0 = body0;
  10. for (int i = 0; i < this.m_morphId.Length; i++)
  11. {
  12. this.m_morphMozaId[i] = (this.m_morphId[i] = -1);
  13. }
  14. if (this.m_morph.hash.ContainsKey("openkupa"))
  15. {
  16. this.m_morphId[0] = (int)this.m_morph.hash["openkupa"];
  17. }
  18. if (this.m_morph.hash.ContainsKey("openvagina"))
  19. {
  20. this.m_morphId[1] = (int)this.m_morph.hash["openvagina"];
  21. }
  22. if (this.m_morph.hash.ContainsKey("openanal"))
  23. {
  24. this.m_morphId[2] = (int)this.m_morph.hash["openanal"];
  25. }
  26. if (this.m_morph.hash.ContainsKey("chinkos"))
  27. {
  28. this.m_morphId[3] = (int)this.m_morph.hash["chinkos"];
  29. }
  30. if (this.m_morph.hash.ContainsKey("chinkof"))
  31. {
  32. this.m_morphId[4] = (int)this.m_morph.hash["chinkof"];
  33. }
  34. Transform transform = CMT.SearchObjName(body0.m_trBones, "_IK_vagina", true);
  35. if (transform != null)
  36. {
  37. this.m_trans[0] = transform;
  38. }
  39. Transform transform2 = CMT.SearchObjName(body0.m_trBones, "_IK_vagina", true);
  40. if (transform2 != null)
  41. {
  42. this.m_trans[1] = transform2;
  43. }
  44. Transform transform3 = CMT.SearchObjName(body0.m_trBones, "_IK_anal", true);
  45. if (transform3 != null)
  46. {
  47. this.m_trans[2] = transform3;
  48. }
  49. }
  50. public void AddMozaMorph(TMorph morphMoza)
  51. {
  52. this.m_morphMoza = morphMoza;
  53. if (this.m_morphMoza.hash.ContainsKey("openkupa"))
  54. {
  55. this.m_morphMozaId[0] = (int)this.m_morphMoza.hash["openkupa"];
  56. }
  57. if (this.m_morphMoza.hash.ContainsKey("openvagina"))
  58. {
  59. this.m_morphMozaId[1] = (int)this.m_morphMoza.hash["openvagina"];
  60. }
  61. if (this.m_morphMoza.hash.ContainsKey("openanal"))
  62. {
  63. this.m_morphMozaId[2] = (int)this.m_morphMoza.hash["openanal"];
  64. }
  65. if (this.m_morphMoza.hash.ContainsKey("chinkos"))
  66. {
  67. this.m_morphMozaId[3] = (int)this.m_morphMoza.hash["chinkos"];
  68. }
  69. if (this.m_morphMoza.hash.ContainsKey("chinkof"))
  70. {
  71. this.m_morphMozaId[4] = (int)this.m_morphMoza.hash["chinkof"];
  72. }
  73. }
  74. public void FinishAll()
  75. {
  76. for (int i = 0; i < this.m_taskList.Count; i++)
  77. {
  78. this.m_taskList[i].ForceFinish();
  79. }
  80. this.m_taskList.Clear();
  81. this.m_morph.FixBlendValues();
  82. if (this.m_morphMoza != null)
  83. {
  84. this.m_morphMoza.FixBlendValues();
  85. }
  86. }
  87. public void ResetAll()
  88. {
  89. for (int i = 0; i < this.m_morphId.Length; i++)
  90. {
  91. if (this.m_morphId[i] != -1)
  92. {
  93. this.m_morph.SetBlendValues(this.m_morphId[i], 0f);
  94. if (this.m_morphMoza != null && this.m_morphMozaId[i] != -1)
  95. {
  96. this.m_morphMoza.SetBlendValues(this.m_morphMozaId[i], 0f);
  97. }
  98. }
  99. }
  100. this.m_taskList.Clear();
  101. this.m_morph.FixBlendValues();
  102. if (this.m_morphMoza != null)
  103. {
  104. this.m_morphMoza.FixBlendValues();
  105. }
  106. }
  107. public void KupaStart(KupaCtrl.OPEN reg, float trans, float delay, float val, bool add = false)
  108. {
  109. if (!add)
  110. {
  111. this.Finish(reg);
  112. }
  113. if (this.m_morphId[(int)reg] != -1)
  114. {
  115. this.m_taskList.Add(new KupaCtrl.Task(this.m_morph, this.m_morphMoza, this.m_morphId[(int)reg], this.m_morphMozaId[(int)reg], reg, trans, delay, val));
  116. }
  117. }
  118. public void AutoKupaStart(KupaCtrl.OPEN reg, Maid targetMan, float val, float speedIn, float sppedOut, float outVal, float lengthRatio)
  119. {
  120. if (this.m_body0.boMAN)
  121. {
  122. Debug.LogError("AutoKupaStartはMaid専用。");
  123. return;
  124. }
  125. this.m_taskList.RemoveAll((KupaCtrl.ATask i) => i.m_reg == reg);
  126. Transform trBones = targetMan.body0.m_trBones;
  127. NDebug.Assert(trBones != null, "男の体が未だロードされていません。");
  128. Transform transform = CMT.SearchObjName(trBones, "chinkoCenter", true);
  129. if (transform != null)
  130. {
  131. Transform[] array = new Transform[3];
  132. array[0] = transform.Find("chinko1");
  133. array[1] = array[0].Find("chinko2");
  134. array[2] = array[1].Find("chinko_nub");
  135. if (this.m_morphId[(int)reg] != -1)
  136. {
  137. this.m_taskList.Add(new KupaCtrl.Target(this.m_morph, this.m_morphMoza, this.m_morphId[(int)reg], this.m_morphMozaId[(int)reg], reg, this.m_trans[(int)reg], array, val, speedIn, sppedOut, outVal, lengthRatio));
  138. }
  139. }
  140. }
  141. public void AutoKariStart(KupaCtrl.OPEN reg, KupaCtrl.TARGET target, Maid targetMaid, float destVal, float speedIn, float sppedOut, float outVal, float lengthRatio)
  142. {
  143. if (!this.m_body0.boMAN)
  144. {
  145. Debug.LogError("AutoKariStartはMan専用。");
  146. return;
  147. }
  148. this.m_taskList.RemoveAll((KupaCtrl.ATask i) => i.m_reg == reg);
  149. Transform trBones = this.m_body0.m_trBones;
  150. NDebug.Assert(trBones != null, "男の体が未だロードされていません。");
  151. Transform transform = CMT.SearchObjName(trBones, "chinkoCenter", true);
  152. if (transform != null)
  153. {
  154. Transform[] array = new Transform[3];
  155. array[0] = transform.Find("chinko1");
  156. array[1] = array[0].Find("chinko2");
  157. array[2] = array[1].Find("chinko_nub");
  158. Transform src = CMT.SearchObjName(targetMaid.body0.m_trBones, this.m_targetBoneName[(int)target], true);
  159. if (this.m_morphId[(int)reg] != -1)
  160. {
  161. this.m_taskList.Add(new KupaCtrl.Target(this.m_morph, this.m_morphMoza, this.m_morphId[(int)reg], this.m_morphMozaId[(int)reg], reg, src, array, destVal, speedIn, sppedOut, outVal, lengthRatio));
  162. }
  163. }
  164. }
  165. public void Finish(KupaCtrl.OPEN reg)
  166. {
  167. for (int j = 0; j < this.m_taskList.Count; j++)
  168. {
  169. KupaCtrl.ATask atask = this.m_taskList[j];
  170. if (atask.m_reg == reg)
  171. {
  172. atask.ForceFinish();
  173. }
  174. }
  175. this.m_taskList.RemoveAll((KupaCtrl.ATask i) => i.m_reg == reg);
  176. }
  177. public void Reset(KupaCtrl.OPEN reg)
  178. {
  179. if (this.m_morphId[(int)reg] != -1)
  180. {
  181. this.m_morph.SetBlendValues(this.m_morphId[(int)reg], 0f);
  182. if (this.m_morphMoza != null && this.m_morphMozaId[(int)reg] != -1)
  183. {
  184. this.m_morphMoza.SetBlendValues(this.m_morphMozaId[(int)reg], 0f);
  185. }
  186. }
  187. this.m_taskList.RemoveAll((KupaCtrl.ATask i) => i.m_reg == reg);
  188. }
  189. public void SelfUpdate()
  190. {
  191. bool flag = false;
  192. for (int j = 0; j < this.m_taskList.Count; j++)
  193. {
  194. flag |= (this.m_taskList[j].IsVisible() && this.m_taskList[j].SelfUpdate());
  195. }
  196. if (flag)
  197. {
  198. this.m_morph.FixBlendValues();
  199. if (this.m_morphMoza != null)
  200. {
  201. this.m_morphMoza.FixBlendValues();
  202. }
  203. }
  204. this.m_taskList.RemoveAll((KupaCtrl.ATask i) => !i.IsVisible());
  205. }
  206. public TMorph m_morph;
  207. public TMorph m_morphMoza;
  208. public TBody m_body0;
  209. private int[] m_morphId = new int[5];
  210. private int[] m_morphMozaId = new int[5];
  211. private string[] m_targetBoneName = new string[]
  212. {
  213. "Mouth",
  214. "_IK_vagina",
  215. "_IK_anal"
  216. };
  217. private List<KupaCtrl.ATask> m_taskList = new List<KupaCtrl.ATask>();
  218. private Transform[] m_trans = new Transform[5];
  219. public enum OPEN
  220. {
  221. KUPA,
  222. VAGINA,
  223. ANAL,
  224. CHINKOS,
  225. CHINKOF,
  226. MAX
  227. }
  228. public enum TARGET
  229. {
  230. MOUTH,
  231. VAGINA,
  232. ANAL,
  233. MAX
  234. }
  235. private abstract class ATask
  236. {
  237. public ATask(TMorph morph, TMorph morphMoza, int id, int mozaId, KupaCtrl.OPEN reg)
  238. {
  239. this.m_morph = morph;
  240. this.m_morphMoza = morphMoza;
  241. this.m_id = id;
  242. this.m_mozaId = mozaId;
  243. this.m_reg = reg;
  244. }
  245. public virtual bool IsVisible()
  246. {
  247. return this.m_visible;
  248. }
  249. public abstract void ForceFinish();
  250. public virtual void ForceReset()
  251. {
  252. this.m_morph.SetBlendValues(this.m_id, 0f);
  253. if (this.m_morphMoza != null && this.m_mozaId != -1)
  254. {
  255. this.m_morphMoza.SetBlendValues(this.m_mozaId, 0f);
  256. }
  257. this.m_visible = false;
  258. }
  259. public abstract bool SelfUpdate();
  260. protected TMorph m_morph;
  261. protected TMorph m_morphMoza;
  262. protected int m_id;
  263. protected int m_mozaId;
  264. public KupaCtrl.OPEN m_reg;
  265. protected bool m_visible;
  266. }
  267. private class Task : KupaCtrl.ATask
  268. {
  269. public Task(TMorph morph, TMorph morphMoza, int id, int mozaId, KupaCtrl.OPEN reg, float trans, float delay, float val) : base(morph, morphMoza, id, mozaId, reg)
  270. {
  271. this.m_transTime = trans;
  272. this.m_delayTime = delay;
  273. this.m_distVal = Mathf.Clamp01(val);
  274. this.m_startTime = Time.realtimeSinceStartup;
  275. this.m_visible = true;
  276. this.m_start = false;
  277. if (trans <= 0f && delay <= 0f)
  278. {
  279. this.ForceFinish();
  280. return;
  281. }
  282. }
  283. public override void ForceFinish()
  284. {
  285. this.m_morph.SetBlendValues(this.m_id, this.m_distVal);
  286. if (this.m_morphMoza != null && this.m_mozaId != -1)
  287. {
  288. this.m_morphMoza.SetBlendValues(this.m_mozaId, this.m_distVal);
  289. }
  290. this.m_visible = false;
  291. }
  292. public override bool SelfUpdate()
  293. {
  294. if (!this.m_visible)
  295. {
  296. return false;
  297. }
  298. float num = Time.realtimeSinceStartup - this.m_startTime;
  299. if (!this.m_start)
  300. {
  301. if (this.m_delayTime > num)
  302. {
  303. return false;
  304. }
  305. if (this.m_transTime <= 0f)
  306. {
  307. this.ForceFinish();
  308. return true;
  309. }
  310. this.m_start = true;
  311. this.m_startVal = this.m_morph.GetBlendValues(this.m_id);
  312. this.m_subVal = this.m_distVal - this.m_startVal;
  313. }
  314. float num2 = num - this.m_delayTime;
  315. float num3 = 1f;
  316. if (0f < this.m_transTime)
  317. {
  318. num3 = this.m_startVal + this.m_subVal * (num2 / this.m_transTime);
  319. }
  320. if (this.m_transTime <= num2 || this.m_distVal == num3)
  321. {
  322. num3 = this.m_distVal;
  323. this.m_visible = false;
  324. }
  325. float num4 = Mathf.Clamp01(num3);
  326. if (num4 != this.m_morph.GetBlendValues(this.m_id))
  327. {
  328. this.m_morph.SetBlendValues(this.m_id, num4);
  329. if (this.m_morphMoza != null && this.m_mozaId != -1)
  330. {
  331. this.m_morphMoza.SetBlendValues(this.m_mozaId, num4);
  332. }
  333. return true;
  334. }
  335. return false;
  336. }
  337. private float m_transTime;
  338. private float m_delayTime;
  339. private float m_distVal;
  340. private float m_startTime;
  341. private float m_startTime2;
  342. private float m_startVal;
  343. private float m_subVal;
  344. private bool m_start;
  345. }
  346. private class Target : KupaCtrl.ATask
  347. {
  348. public Target(TMorph morph, TMorph morphMoza, int id, int mozaId, KupaCtrl.OPEN reg, Transform src, Transform[] target, float val = 1f, float speedIn = 5f, float sppedOut = 5f, float outVal = 0f, float lengthRatio = 1f) : base(morph, morphMoza, id, mozaId, reg)
  349. {
  350. this.m_src = src;
  351. this.m_target = target;
  352. this.m_distVal = val;
  353. this.m_sppedIn = speedIn;
  354. this.m_sppedNow = speedIn;
  355. this.m_sppedOut = sppedOut;
  356. this.m_outVal = outVal;
  357. this.m_lengthRatio = lengthRatio;
  358. this.m_nowRatio = this.m_morph.GetBlendValues(this.m_id);
  359. this.m_visible = true;
  360. }
  361. public override void ForceFinish()
  362. {
  363. this.m_visible = false;
  364. }
  365. public override void ForceReset()
  366. {
  367. this.m_morph.SetBlendValues(this.m_id, 0f);
  368. if (this.m_morphMoza != null && this.m_mozaId != -1)
  369. {
  370. this.m_morphMoza.SetBlendValues(this.m_mozaId, 0f);
  371. }
  372. this.m_visible = false;
  373. }
  374. public override bool SelfUpdate()
  375. {
  376. if (!this.m_visible)
  377. {
  378. return false;
  379. }
  380. Vector3 lhs = this.m_src.TransformVector(-Vector3.forward);
  381. float num = Vector3.Distance(this.m_src.position, this.m_target[this.m_target.Length - 1].position);
  382. float num2 = float.PositiveInfinity;
  383. int num3 = 0;
  384. Vector3 zero = Vector3.zero;
  385. float num4 = 0f;
  386. float num5 = 0f;
  387. for (int i = 1; i < this.m_target.Length; i++)
  388. {
  389. num5 += Vector3.Distance(this.m_target[i - 1].position, this.m_target[i].position);
  390. }
  391. float num6 = num5 * this.m_lengthRatio;
  392. float num7 = 0f;
  393. for (int j = 1; j < this.m_target.Length; j++)
  394. {
  395. Vector3 position = this.m_target[j - 1].position;
  396. Vector3 position2 = this.m_src.position;
  397. this.m_segTemp.s = position;
  398. this.m_segTemp.e = this.m_target[j].position;
  399. this.m_segTemp.v = this.m_segTemp.e - this.m_segTemp.s;
  400. bool flag = false;
  401. float num8;
  402. num7 += (num8 = Vector3.Distance(this.m_segTemp.s, this.m_segTemp.e));
  403. if (num6 < num7)
  404. {
  405. this.m_segTemp.e = this.m_segTemp.s + this.m_segTemp.v.normalized * (num8 - (num7 - num6));
  406. flag = true;
  407. }
  408. Vector3 vector;
  409. float num10;
  410. float num9 = MathCM.calcPointSegmentDist(ref position2, ref this.m_segTemp, out vector, out num10);
  411. if (num9 < num2)
  412. {
  413. num2 = num9;
  414. num3 = j;
  415. num4 = num10;
  416. }
  417. if (flag)
  418. {
  419. break;
  420. }
  421. }
  422. float num11 = this.m_outNowVal;
  423. if (num2 <= this.m_hitDistance)
  424. {
  425. num11 = this.m_distVal;
  426. if (0f < num4 && num4 < 1f)
  427. {
  428. this.m_outNowVal = this.m_outVal;
  429. }
  430. }
  431. else if (num2 <= this.m_apprDistance)
  432. {
  433. num11 = this.m_outNowVal + (this.m_distVal - this.m_outNowVal) * (1f - (num2 - this.m_hitDistance) / (this.m_apprDistance - this.m_hitDistance));
  434. Vector3 normalized = (this.m_target[num3 - 1].position - this.m_target[num3].position).normalized;
  435. float num12 = Vector3.Dot(lhs, normalized);
  436. if ((double)num12 <= 0.0)
  437. {
  438. num11 = 0f;
  439. }
  440. else if (num12 <= 0.7f)
  441. {
  442. num11 *= num12 / 0.7f;
  443. }
  444. }
  445. if (num11 - this.m_befRatio > 0f)
  446. {
  447. this.m_sppedNow = this.m_sppedIn;
  448. }
  449. else if (num11 - this.m_befRatio < 0f)
  450. {
  451. this.m_sppedNow = this.m_sppedOut;
  452. }
  453. this.m_nowRatio += (num11 - this.m_nowRatio) * (Time.deltaTime * this.m_sppedNow);
  454. this.m_befRatio = num11;
  455. float num13 = Mathf.Clamp01(this.m_nowRatio);
  456. if (num13 != this.m_morph.GetBlendValues(this.m_id))
  457. {
  458. this.m_morph.SetBlendValues(this.m_id, num13);
  459. if (this.m_morphMoza != null && this.m_mozaId != -1)
  460. {
  461. this.m_morphMoza.SetBlendValues(this.m_mozaId, num13);
  462. }
  463. return true;
  464. }
  465. return false;
  466. }
  467. public Transform m_src;
  468. public Transform[] m_target;
  469. private float m_distVal = 1f;
  470. private float m_outVal;
  471. private float m_apprDistance = 0.025f;
  472. private float m_hitDistance = 0.02f;
  473. private float m_sppedIn = 5f;
  474. private float m_sppedOut = 5f;
  475. private float m_sppedNow = 5f;
  476. private float m_outNowVal;
  477. private float m_nowRatio;
  478. private float m_befRatio;
  479. private float m_lengthRatio = 1f;
  480. private MathCM.Segment m_segTemp = default(MathCM.Segment);
  481. }
  482. }