ChinkoCtrl.cs 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. using System;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. public class ChinkoCtrl
  5. {
  6. public ChinkoCtrl(Transform chinkoCenterTrs)
  7. {
  8. List<Transform> list = this.worldPointList;
  9. this.m_chinkoCenterTrs = chinkoCenterTrs;
  10. list.Add(chinkoCenterTrs);
  11. this.worldPointList.Add(chinkoCenterTrs.Find("chinko1"));
  12. this.worldPointList.Add(this.worldPointList[this.worldPointList.Count - 1].Find("chinko2"));
  13. this.worldPointList.Add(this.worldPointList[this.worldPointList.Count - 1].Find("chinko_nub"));
  14. }
  15. public void StartChinkoSlide(Maid targetMaid, ChinkoCtrl.TARGET targetId, Vector3 offset, float apprDist = 0.05f)
  16. {
  17. this.m_targetMaidReg = CMT.SearchObjName(targetMaid.body0.m_Bones.transform, this.m_targetBoneName[(int)targetId], true);
  18. this.m_offset = offset;
  19. this.m_apprDistance = apprDist;
  20. }
  21. public void StopChinkoSlide()
  22. {
  23. this.m_targetMaidReg = null;
  24. }
  25. public void SelfUpdate()
  26. {
  27. if (this.m_targetMaidReg == null)
  28. {
  29. return;
  30. }
  31. Plane plane = new Plane(-this.m_targetMaidReg.forward, this.m_targetMaidReg.position);
  32. Plane plane2 = new Plane(-this.m_chinkoCenterTrs.right, this.m_chinkoCenterTrs.position);
  33. if (plane2.GetSide(this.m_targetMaidReg.position))
  34. {
  35. bool flag = false;
  36. for (int i = 1; i < this.worldPointList.Count; i++)
  37. {
  38. Vector3 vector;
  39. if (MathCM.PlaneSegmentIntersect(plane, this.worldPointList[i - 1].position, this.worldPointList[i].position, out vector))
  40. {
  41. Debug.DrawLine(vector, this.m_chinkoCenterTrs.position, Color.magenta);
  42. Vector3 b = this.m_targetMaidReg.position + this.m_offset - vector;
  43. this.m_chinkoCenterTrs.position = this.m_chinkoCenterTrs.position + b;
  44. flag = true;
  45. break;
  46. }
  47. }
  48. if (!flag)
  49. {
  50. Vector3 position = this.worldPointList[this.worldPointList.Count - 2].position;
  51. Vector3 position2 = this.worldPointList[this.worldPointList.Count - 1].position;
  52. float num = 0f;
  53. Vector3 normalized = (position2 - position).normalized;
  54. if (plane.Raycast(new Ray(position, normalized), out num))
  55. {
  56. float num2 = num - Vector3.Distance(position, position2);
  57. float d = 1f - Mathf.Clamp01(num2 / this.m_apprDistance);
  58. Vector3 vector = position + normalized * num;
  59. Vector3 a = this.m_targetMaidReg.position + this.m_offset - vector;
  60. this.m_chinkoCenterTrs.position = this.m_chinkoCenterTrs.position + a * d;
  61. }
  62. }
  63. }
  64. }
  65. private string[] m_targetBoneName = new string[]
  66. {
  67. "Mouth",
  68. "_IK_vagina",
  69. "_IK_anal"
  70. };
  71. private List<Transform> worldPointList = new List<Transform>();
  72. private Transform m_chinkoCenterTrs;
  73. private Transform m_targetMaidReg;
  74. private Vector3 m_offset = Vector3.zero;
  75. private float m_apprDistance = 0.05f;
  76. public enum TARGET
  77. {
  78. MOUTH,
  79. VAGINA,
  80. ANAL,
  81. MAX
  82. }
  83. }