KupaCtrl.cs 11 KB

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