KupaCtrl.cs 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504
  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. }
  94. }
  95. this.m_taskList.Clear();
  96. this.m_morph.FixBlendValues();
  97. if (this.m_morphMoza != null)
  98. {
  99. this.m_morphMoza.FixBlendValues();
  100. }
  101. }
  102. public void KupaStart(KupaCtrl.OPEN reg, float trans, float delay, float val, bool add = false)
  103. {
  104. if (!add)
  105. {
  106. this.Finish(reg);
  107. }
  108. if (this.m_morphId[(int)reg] != -1)
  109. {
  110. 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));
  111. }
  112. }
  113. public void AutoKupaStart(KupaCtrl.OPEN reg, Maid targetMan, float val, float speedIn, float sppedOut, float outVal, float lengthRatio)
  114. {
  115. if (this.m_body0.boMAN)
  116. {
  117. Debug.LogError("AutoKupaStartはMaid専用。");
  118. return;
  119. }
  120. this.m_taskList.RemoveAll((KupaCtrl.ATask i) => i.m_reg == reg);
  121. Transform trBones = targetMan.body0.m_trBones;
  122. NDebug.Assert(trBones != null, "男の体が未だロードされていません。");
  123. Transform transform = CMT.SearchObjName(trBones, "chinkoCenter", true);
  124. if (transform != null)
  125. {
  126. Transform[] array = new Transform[3];
  127. array[0] = transform.Find("chinko1");
  128. array[1] = array[0].Find("chinko2");
  129. array[2] = array[1].Find("chinko_nub");
  130. if (this.m_morphId[(int)reg] != -1)
  131. {
  132. 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));
  133. }
  134. }
  135. }
  136. public void AutoKariStart(KupaCtrl.OPEN reg, KupaCtrl.TARGET target, Maid targetMaid, float destVal, float speedIn, float sppedOut, float outVal, float lengthRatio)
  137. {
  138. if (!this.m_body0.boMAN)
  139. {
  140. Debug.LogError("AutoKariStartはMan専用。");
  141. return;
  142. }
  143. this.m_taskList.RemoveAll((KupaCtrl.ATask i) => i.m_reg == reg);
  144. Transform trBones = this.m_body0.m_trBones;
  145. NDebug.Assert(trBones != null, "男の体が未だロードされていません。");
  146. Transform transform = CMT.SearchObjName(trBones, "chinkoCenter", true);
  147. if (transform != null)
  148. {
  149. Transform[] array = new Transform[3];
  150. array[0] = transform.Find("chinko1");
  151. array[1] = array[0].Find("chinko2");
  152. array[2] = array[1].Find("chinko_nub");
  153. Transform src = CMT.SearchObjName(targetMaid.body0.m_trBones, this.m_targetBoneName[(int)target], true);
  154. if (this.m_morphId[(int)reg] != -1)
  155. {
  156. 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));
  157. }
  158. }
  159. }
  160. public void Finish(KupaCtrl.OPEN reg)
  161. {
  162. for (int j = 0; j < this.m_taskList.Count; j++)
  163. {
  164. KupaCtrl.ATask atask = this.m_taskList[j];
  165. if (atask.m_reg == reg)
  166. {
  167. atask.ForceFinish();
  168. }
  169. }
  170. this.m_taskList.RemoveAll((KupaCtrl.ATask i) => i.m_reg == reg);
  171. }
  172. public void Reset(KupaCtrl.OPEN reg)
  173. {
  174. if (this.m_morphId[(int)reg] != -1)
  175. {
  176. }
  177. this.m_taskList.RemoveAll((KupaCtrl.ATask i) => i.m_reg == reg);
  178. }
  179. public void SelfUpdate()
  180. {
  181. bool flag = false;
  182. for (int j = 0; j < this.m_taskList.Count; j++)
  183. {
  184. flag |= (this.m_taskList[j].IsVisible() && this.m_taskList[j].SelfUpdate());
  185. }
  186. if (flag)
  187. {
  188. this.m_morph.FixBlendValues();
  189. if (this.m_morphMoza != null)
  190. {
  191. this.m_morphMoza.FixBlendValues();
  192. }
  193. }
  194. this.m_taskList.RemoveAll((KupaCtrl.ATask i) => !i.IsVisible());
  195. }
  196. public TMorph m_morph;
  197. public TMorph m_morphMoza;
  198. public TBody m_body0;
  199. private int[] m_morphId = new int[5];
  200. private int[] m_morphMozaId = new int[5];
  201. private string[] m_targetBoneName = new string[]
  202. {
  203. "Mouth",
  204. "_IK_vagina",
  205. "_IK_anal"
  206. };
  207. private List<KupaCtrl.ATask> m_taskList = new List<KupaCtrl.ATask>();
  208. private Transform[] m_trans = new Transform[5];
  209. public enum OPEN
  210. {
  211. KUPA,
  212. VAGINA,
  213. ANAL,
  214. CHINKOS,
  215. CHINKOF,
  216. MAX
  217. }
  218. public enum TARGET
  219. {
  220. MOUTH,
  221. VAGINA,
  222. ANAL,
  223. MAX
  224. }
  225. private abstract class ATask
  226. {
  227. public ATask(TMorph morph, TMorph morphMoza, int id, int mozaId, KupaCtrl.OPEN reg)
  228. {
  229. this.m_morph = morph;
  230. this.m_morphMoza = morphMoza;
  231. this.m_id = id;
  232. this.m_mozaId = mozaId;
  233. this.m_reg = reg;
  234. }
  235. public virtual bool IsVisible()
  236. {
  237. return this.m_visible;
  238. }
  239. public abstract void ForceFinish();
  240. public virtual void ForceReset()
  241. {
  242. this.m_morph.SetBlendValues(this.m_id, 0f);
  243. if (this.m_morphMoza != null && this.m_mozaId != -1)
  244. {
  245. this.m_morphMoza.SetBlendValues(this.m_mozaId, 0f);
  246. }
  247. this.m_visible = false;
  248. }
  249. public abstract bool SelfUpdate();
  250. protected TMorph m_morph;
  251. protected TMorph m_morphMoza;
  252. protected int m_id;
  253. protected int m_mozaId;
  254. public KupaCtrl.OPEN m_reg;
  255. protected bool m_visible;
  256. }
  257. private class Task : KupaCtrl.ATask
  258. {
  259. 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)
  260. {
  261. this.m_transTime = trans;
  262. this.m_delayTime = delay;
  263. this.m_distVal = Mathf.Clamp01(val);
  264. this.m_startTime = Time.realtimeSinceStartup;
  265. this.m_visible = true;
  266. this.m_start = false;
  267. if (trans <= 0f && delay <= 0f)
  268. {
  269. this.ForceFinish();
  270. return;
  271. }
  272. }
  273. public override void ForceFinish()
  274. {
  275. this.m_visible = false;
  276. }
  277. public override bool SelfUpdate()
  278. {
  279. if (!this.m_visible)
  280. {
  281. return false;
  282. }
  283. float num = Time.realtimeSinceStartup - this.m_startTime;
  284. if (!this.m_start)
  285. {
  286. if (this.m_delayTime > num)
  287. {
  288. return false;
  289. }
  290. if (this.m_transTime <= 0f)
  291. {
  292. this.ForceFinish();
  293. return true;
  294. }
  295. this.m_start = true;
  296. this.m_startVal = this.m_morph.GetBlendValues(this.m_id);
  297. this.m_subVal = this.m_distVal - this.m_startVal;
  298. }
  299. float num2 = num - this.m_delayTime;
  300. float num3 = 1f;
  301. if (0f < this.m_transTime)
  302. {
  303. num3 = this.m_startVal + this.m_subVal * (num2 / this.m_transTime);
  304. }
  305. if (this.m_transTime <= num2 || this.m_distVal == num3)
  306. {
  307. num3 = this.m_distVal;
  308. this.m_visible = false;
  309. }
  310. float num4 = Mathf.Clamp01(num3);
  311. return num4 != this.m_morph.GetBlendValues(this.m_id);
  312. }
  313. private float m_transTime;
  314. private float m_delayTime;
  315. private float m_distVal;
  316. private float m_startTime;
  317. private float m_startTime2;
  318. private float m_startVal;
  319. private float m_subVal;
  320. private bool m_start;
  321. }
  322. private class Target : KupaCtrl.ATask
  323. {
  324. 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)
  325. {
  326. this.m_src = src;
  327. this.m_target = target;
  328. this.m_distVal = val;
  329. this.m_sppedIn = speedIn;
  330. this.m_sppedNow = speedIn;
  331. this.m_sppedOut = sppedOut;
  332. this.m_outVal = outVal;
  333. this.m_lengthRatio = lengthRatio;
  334. this.m_nowRatio = this.m_morph.GetBlendValues(this.m_id);
  335. this.m_visible = true;
  336. }
  337. public override void ForceFinish()
  338. {
  339. this.m_visible = false;
  340. }
  341. public override void ForceReset()
  342. {
  343. this.m_visible = false;
  344. }
  345. public override bool SelfUpdate()
  346. {
  347. if (!this.m_visible)
  348. {
  349. return false;
  350. }
  351. Vector3 lhs = this.m_src.TransformVector(-Vector3.forward);
  352. float num = Vector3.Distance(this.m_src.position, this.m_target[this.m_target.Length - 1].position);
  353. float num2 = float.PositiveInfinity;
  354. int num3 = 0;
  355. Vector3 zero = Vector3.zero;
  356. float num4 = 0f;
  357. float num5 = 0f;
  358. for (int i = 1; i < this.m_target.Length; i++)
  359. {
  360. num5 += Vector3.Distance(this.m_target[i - 1].position, this.m_target[i].position);
  361. }
  362. float num6 = num5 * this.m_lengthRatio;
  363. float num7 = 0f;
  364. for (int j = 1; j < this.m_target.Length; j++)
  365. {
  366. Vector3 position = this.m_target[j - 1].position;
  367. Vector3 position2 = this.m_src.position;
  368. this.m_segTemp.s = position;
  369. this.m_segTemp.e = this.m_target[j].position;
  370. this.m_segTemp.v = this.m_segTemp.e - this.m_segTemp.s;
  371. bool flag = false;
  372. float num8;
  373. num7 += (num8 = Vector3.Distance(this.m_segTemp.s, this.m_segTemp.e));
  374. if (num6 < num7)
  375. {
  376. this.m_segTemp.e = this.m_segTemp.s + this.m_segTemp.v.normalized * (num8 - (num7 - num6));
  377. flag = true;
  378. }
  379. Vector3 vector;
  380. float num10;
  381. float num9 = MathCM.calcPointSegmentDist(ref position2, ref this.m_segTemp, out vector, out num10);
  382. if (num9 < num2)
  383. {
  384. num2 = num9;
  385. num3 = j;
  386. num4 = num10;
  387. }
  388. if (flag)
  389. {
  390. break;
  391. }
  392. }
  393. float num11 = this.m_outNowVal;
  394. if (num2 <= this.m_hitDistance)
  395. {
  396. num11 = this.m_distVal;
  397. if (0f < num4 && num4 < 1f)
  398. {
  399. this.m_outNowVal = this.m_outVal;
  400. }
  401. }
  402. else if (num2 <= this.m_apprDistance)
  403. {
  404. num11 = this.m_outNowVal + (this.m_distVal - this.m_outNowVal) * (1f - (num2 - this.m_hitDistance) / (this.m_apprDistance - this.m_hitDistance));
  405. Vector3 normalized = (this.m_target[num3 - 1].position - this.m_target[num3].position).normalized;
  406. float num12 = Vector3.Dot(lhs, normalized);
  407. if ((double)num12 <= 0.0)
  408. {
  409. num11 = 0f;
  410. }
  411. else if (num12 <= 0.7f)
  412. {
  413. num11 *= num12 / 0.7f;
  414. }
  415. }
  416. if (num11 - this.m_befRatio > 0f)
  417. {
  418. this.m_sppedNow = this.m_sppedIn;
  419. }
  420. else if (num11 - this.m_befRatio < 0f)
  421. {
  422. this.m_sppedNow = this.m_sppedOut;
  423. }
  424. this.m_nowRatio += (num11 - this.m_nowRatio) * (Time.deltaTime * this.m_sppedNow);
  425. this.m_befRatio = num11;
  426. float num13 = Mathf.Clamp01(this.m_nowRatio);
  427. return num13 != this.m_morph.GetBlendValues(this.m_id);
  428. }
  429. public Transform m_src;
  430. public Transform[] m_target;
  431. private float m_distVal = 1f;
  432. private float m_outVal;
  433. private float m_apprDistance = 0.025f;
  434. private float m_hitDistance = 0.02f;
  435. private float m_sppedIn = 5f;
  436. private float m_sppedOut = 5f;
  437. private float m_sppedNow = 5f;
  438. private float m_outNowVal;
  439. private float m_nowRatio;
  440. private float m_befRatio;
  441. private float m_lengthRatio = 1f;
  442. private MathCM.Segment m_segTemp = default(MathCM.Segment);
  443. }
  444. }