KupaCtrl.cs 8.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387
  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. for (int i = 0; i < this.m_morphId.Length; i++)
  10. {
  11. this.m_morphId[i] = -1;
  12. }
  13. if (this.m_morph.hash.ContainsKey("openkupa"))
  14. {
  15. this.m_morphId[0] = (int)this.m_morph.hash["openkupa"];
  16. }
  17. if (this.m_morph.hash.ContainsKey("openvagina"))
  18. {
  19. this.m_morphId[1] = (int)this.m_morph.hash["openvagina"];
  20. }
  21. if (this.m_morph.hash.ContainsKey("openanal"))
  22. {
  23. this.m_morphId[2] = (int)this.m_morph.hash["openanal"];
  24. }
  25. if (this.m_morph.hash.ContainsKey("chinkos"))
  26. {
  27. this.m_morphId[3] = (int)this.m_morph.hash["chinkos"];
  28. }
  29. Transform transform = CMT.SearchObjName(body0.m_trBones, "_IK_vagina", true);
  30. if (transform != null)
  31. {
  32. this.m_trans[0] = transform;
  33. }
  34. Transform transform2 = CMT.SearchObjName(body0.m_trBones, "_IK_vagina", true);
  35. if (transform2 != null)
  36. {
  37. this.m_trans[1] = transform2;
  38. }
  39. Transform transform3 = CMT.SearchObjName(body0.m_trBones, "_IK_anal", true);
  40. if (transform3 != null)
  41. {
  42. this.m_trans[2] = transform3;
  43. }
  44. }
  45. public void FinishAll()
  46. {
  47. for (int i = 0; i < this.m_taskList.Count; i++)
  48. {
  49. this.m_taskList[i].ForceFinish();
  50. }
  51. this.m_taskList.Clear();
  52. this.m_morph.FixBlendValues();
  53. }
  54. public void ResetAll()
  55. {
  56. for (int i = 0; i < this.m_morphId.Length; i++)
  57. {
  58. if (this.m_morphId[i] != -1)
  59. {
  60. this.m_morph.SetBlendValues(this.m_morphId[i], 0f);
  61. }
  62. }
  63. this.m_taskList.Clear();
  64. this.m_morph.FixBlendValues();
  65. }
  66. public void KupaStart(KupaCtrl.OPEN reg, float trans, float delay, float val, bool add = false)
  67. {
  68. if (!add)
  69. {
  70. this.Finish(reg);
  71. }
  72. if (this.m_morphId[(int)reg] != -1)
  73. {
  74. this.m_taskList.Add(new KupaCtrl.Task(this.m_morph, this.m_morphId[(int)reg], reg, trans, delay, val));
  75. }
  76. }
  77. public void AutoKupaStart(KupaCtrl.OPEN reg, Maid targetMan, float val, float speedIn, float sppedOut, float outVal)
  78. {
  79. this.m_taskList.RemoveAll((KupaCtrl.ATask i) => i.m_reg == reg);
  80. Transform trBones = targetMan.body0.m_trBones;
  81. NDebug.Assert(trBones != null, "男の体が未だロードされていません。");
  82. Transform transform = CMT.SearchObjName(trBones, "chinkoCenter", true);
  83. if (transform != null)
  84. {
  85. Transform[] array = new Transform[3];
  86. array[0] = transform.Find("chinko1");
  87. array[1] = array[0].Find("chinko2");
  88. array[2] = array[1].Find("chinko_nub");
  89. if (this.m_morphId[(int)reg] != -1)
  90. {
  91. 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));
  92. }
  93. }
  94. }
  95. public void Finish(KupaCtrl.OPEN reg)
  96. {
  97. for (int j = 0; j < this.m_taskList.Count; j++)
  98. {
  99. KupaCtrl.ATask atask = this.m_taskList[j];
  100. if (atask.m_reg == reg)
  101. {
  102. atask.ForceFinish();
  103. }
  104. }
  105. this.m_taskList.RemoveAll((KupaCtrl.ATask i) => i.m_reg == reg);
  106. }
  107. public void Reset(KupaCtrl.OPEN reg)
  108. {
  109. if (this.m_morphId[(int)reg] != -1)
  110. {
  111. this.m_morph.SetBlendValues(this.m_morphId[(int)reg], 0f);
  112. }
  113. this.m_taskList.RemoveAll((KupaCtrl.ATask i) => i.m_reg == reg);
  114. }
  115. public void SelfUpdate()
  116. {
  117. bool flag = false;
  118. for (int j = 0; j < this.m_taskList.Count; j++)
  119. {
  120. flag |= (this.m_taskList[j].IsVisible() && this.m_taskList[j].SelfUpdate());
  121. }
  122. if (flag)
  123. {
  124. this.m_morph.FixBlendValues();
  125. }
  126. this.m_taskList.RemoveAll((KupaCtrl.ATask i) => !i.IsVisible());
  127. }
  128. public TMorph m_morph;
  129. private int[] m_morphId = new int[4];
  130. private List<KupaCtrl.ATask> m_taskList = new List<KupaCtrl.ATask>();
  131. private Transform[] m_trans = new Transform[4];
  132. public enum OPEN
  133. {
  134. KUPA,
  135. VAGINA,
  136. ANAL,
  137. CHINKOS,
  138. MAX
  139. }
  140. private abstract class ATask
  141. {
  142. public ATask(TMorph morph, int id, KupaCtrl.OPEN reg)
  143. {
  144. this.m_morph = morph;
  145. this.m_id = id;
  146. this.m_reg = reg;
  147. }
  148. public virtual bool IsVisible()
  149. {
  150. return this.m_visible;
  151. }
  152. public abstract void ForceFinish();
  153. public virtual void ForceReset()
  154. {
  155. this.m_morph.SetBlendValues(this.m_id, 0f);
  156. this.m_visible = false;
  157. }
  158. public abstract bool SelfUpdate();
  159. protected TMorph m_morph;
  160. protected int m_id;
  161. public KupaCtrl.OPEN m_reg;
  162. protected bool m_visible;
  163. }
  164. private class Task : KupaCtrl.ATask
  165. {
  166. public Task(TMorph morph, int id, KupaCtrl.OPEN reg, float trans, float delay, float val) : base(morph, id, reg)
  167. {
  168. this.m_transTime = trans;
  169. this.m_delayTime = delay;
  170. this.m_distVal = Mathf.Clamp01(val);
  171. this.m_startTime = Time.realtimeSinceStartup;
  172. this.m_visible = true;
  173. this.m_start = false;
  174. if (trans <= 0f && delay <= 0f)
  175. {
  176. this.ForceFinish();
  177. return;
  178. }
  179. }
  180. public override void ForceFinish()
  181. {
  182. this.m_morph.SetBlendValues(this.m_id, this.m_distVal);
  183. this.m_visible = false;
  184. }
  185. public override bool SelfUpdate()
  186. {
  187. if (!this.m_visible)
  188. {
  189. return false;
  190. }
  191. float num = Time.realtimeSinceStartup - this.m_startTime;
  192. if (!this.m_start)
  193. {
  194. if (this.m_delayTime > num)
  195. {
  196. return false;
  197. }
  198. if (this.m_transTime <= 0f)
  199. {
  200. this.ForceFinish();
  201. return true;
  202. }
  203. this.m_start = true;
  204. this.m_startVal = this.m_morph.GetBlendValues(this.m_id);
  205. this.m_subVal = this.m_distVal - this.m_startVal;
  206. }
  207. float num2 = num - this.m_delayTime;
  208. float num3 = 1f;
  209. if (0f < this.m_transTime)
  210. {
  211. num3 = this.m_startVal + this.m_subVal * (num2 / this.m_transTime);
  212. }
  213. if (this.m_transTime <= num2 || this.m_distVal == num3)
  214. {
  215. num3 = this.m_distVal;
  216. this.m_visible = false;
  217. }
  218. float num4 = Mathf.Clamp01(num3);
  219. if (num4 != this.m_morph.GetBlendValues(this.m_id))
  220. {
  221. this.m_morph.SetBlendValues(this.m_id, num4);
  222. return true;
  223. }
  224. return false;
  225. }
  226. private float m_transTime;
  227. private float m_delayTime;
  228. private float m_distVal;
  229. private float m_startTime;
  230. private float m_startTime2;
  231. private float m_startVal;
  232. private float m_subVal;
  233. private bool m_start;
  234. }
  235. private class Target : KupaCtrl.ATask
  236. {
  237. public Target(TMorph morph, int id, KupaCtrl.OPEN reg, Transform src, Transform[] target, float val, float speedIn, float sppedOut, float outVal) : base(morph, id, reg)
  238. {
  239. this.m_src = src;
  240. this.m_target = target;
  241. this.m_distVal = val;
  242. this.m_sppedIn = speedIn;
  243. this.m_sppedNow = speedIn;
  244. this.m_sppedOut = sppedOut;
  245. this.m_outVal = outVal;
  246. this.m_visible = true;
  247. }
  248. public override void ForceFinish()
  249. {
  250. this.m_visible = false;
  251. }
  252. public override void ForceReset()
  253. {
  254. this.m_morph.SetBlendValues(this.m_id, 0f);
  255. this.m_visible = false;
  256. }
  257. public override bool SelfUpdate()
  258. {
  259. if (!this.m_visible)
  260. {
  261. return false;
  262. }
  263. Vector3 lhs = this.m_src.TransformVector(-Vector3.forward);
  264. float num = Vector3.Distance(this.m_src.position, this.m_target[this.m_target.Length - 1].position);
  265. float num2 = float.PositiveInfinity;
  266. int num3 = 0;
  267. Vector3 zero = Vector3.zero;
  268. float num4 = 0f;
  269. for (int i = 1; i < this.m_target.Length; i++)
  270. {
  271. Vector3 position = this.m_target[i - 1].position;
  272. Vector3 position2 = this.m_src.position;
  273. MathCM.Segment segment = new MathCM.Segment(position, this.m_target[i].position);
  274. Vector3 vector;
  275. float num6;
  276. float num5 = MathCM.calcPointSegmentDist(ref position2, ref segment, out vector, out num6);
  277. if (num5 < num2)
  278. {
  279. num2 = num5;
  280. num3 = i;
  281. num4 = num6;
  282. }
  283. }
  284. float num7 = this.m_outNowVal;
  285. if (num2 <= this.m_hitDistance)
  286. {
  287. num7 = this.m_distVal;
  288. if (0f < num4 && num4 < 1f)
  289. {
  290. this.m_outNowVal = this.m_outVal;
  291. }
  292. }
  293. else if (num2 <= this.m_apprDistance)
  294. {
  295. num7 = this.m_outNowVal + (this.m_distVal - this.m_outNowVal) * (1f - (num2 - this.m_hitDistance) / (this.m_apprDistance - this.m_hitDistance));
  296. Vector3 normalized = (this.m_target[num3 - 1].position - this.m_target[num3].position).normalized;
  297. float num8 = Vector3.Dot(lhs, normalized);
  298. if ((double)num8 <= 0.0)
  299. {
  300. num7 = 0f;
  301. }
  302. else if (num8 <= 0.7f)
  303. {
  304. num7 *= num8 / 0.7f;
  305. }
  306. }
  307. if (num7 - this.m_befRatio > 0f)
  308. {
  309. this.m_sppedNow = this.m_sppedIn;
  310. }
  311. else if (num7 - this.m_befRatio < 0f)
  312. {
  313. this.m_sppedNow = this.m_sppedOut;
  314. }
  315. this.m_nowRatio += (num7 - this.m_nowRatio) * (Time.deltaTime * this.m_sppedNow);
  316. this.m_befRatio = num7;
  317. float num9 = Mathf.Clamp01(this.m_nowRatio);
  318. if (num9 != this.m_morph.GetBlendValues(this.m_id))
  319. {
  320. this.m_morph.SetBlendValues(this.m_id, num9);
  321. return true;
  322. }
  323. return false;
  324. }
  325. public Transform m_src;
  326. public Transform[] m_target;
  327. private float m_distVal = 1f;
  328. private float m_outVal;
  329. private float m_apprDistance = 0.025f;
  330. private float m_hitDistance = 0.02f;
  331. private float m_sppedIn = 5f;
  332. private float m_sppedOut = 5f;
  333. private float m_sppedNow = 5f;
  334. private float m_outNowVal;
  335. private float m_nowRatio;
  336. private float m_befRatio;
  337. }
  338. }