BodyCtrlData.cs 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  1. using System;
  2. using UnityEngine;
  3. [Serializable]
  4. public class BodyCtrlData : IKCtrlData
  5. {
  6. public BodyCtrlData(FullBodyIKCtrl ik_ctrl) : base(ik_ctrl, ik_ctrl.GetIKBone(FullBodyIKCtrl.IKBoneType.Root), false, false)
  7. {
  8. this.PosBaseBone = this.TargetBone;
  9. this.m_ChainBones = new Transform[]
  10. {
  11. this.TargetBone
  12. };
  13. this.m_ForceIKEnable = false;
  14. }
  15. public bool IsDoSetCharaPos { get; private set; }
  16. public Vector3 OrijinMaidPos { get; private set; }
  17. public override void ApplyIKSetting()
  18. {
  19. this.OrijinMaidPos = this.MyIKCtrl.TgtChara.GetPos();
  20. this.m_PosOffset = Vector3.zero;
  21. base.ApplyIKSetting();
  22. }
  23. private bool CheckDoIK()
  24. {
  25. if (!base.IsIKExec)
  26. {
  27. return false;
  28. }
  29. if (this.HeightFit == BodyCtrlData.HeightFitType.None)
  30. {
  31. return true;
  32. }
  33. int num = this.MyIKCtrl.TgtChara.GetProp(MPN.sintyou).value + this.MyIKCtrl.TgtChara.GetProp(MPN.DouPer).value;
  34. Maid tgtChara = base.GetIKSettingData(IKCtrlData.IKAttachType.NewPoint).curTargetData.TgtChara;
  35. int num2 = tgtChara.GetProp(MPN.sintyou).value + tgtChara.GetProp(MPN.DouPer).value;
  36. if (this.HeightFit == BodyCtrlData.HeightFitType.Higher)
  37. {
  38. return num > num2;
  39. }
  40. return num < num2;
  41. }
  42. protected override void SetTargetTransform(IKCtrlData.IKSettingData data, Vector3 pos, Quaternion rot)
  43. {
  44. if (!data.IsPointAttach || !this.CheckDoIK())
  45. {
  46. return;
  47. }
  48. if (data.FirstFrame && !data.BlendNow)
  49. {
  50. this.m_FirstBonePos = this.PosBaseBone.position;
  51. }
  52. Vector3 b = (!data.BlendNow) ? this.m_FirstBonePos : this.PosBaseBone.position;
  53. pos = ((!data.BlendNow) ? this.m_FirstTgtPosRot.pos : pos);
  54. base.SetTargetTransform(data, pos, rot);
  55. Vector3 enable = this.m_OffsetEnable.GetEnable(base.IKTarget.position - b, false);
  56. if (data.BlendType == IKCtrlData.IKBlendType.IK_To_IK)
  57. {
  58. this.m_PosOffset = Vector3.Lerp(this.m_lastPosOffset, enable, data.BlendWeight);
  59. }
  60. else if (data.BlendType == IKCtrlData.IKBlendType.IK_To_Detach)
  61. {
  62. this.m_PosOffset = Vector3.Lerp(Vector3.zero, this.m_lastPosOffset, 1f - data.BlendWeight);
  63. }
  64. else
  65. {
  66. this.m_PosOffset = Vector3.Lerp(Vector3.zero, enable, data.BlendWeight);
  67. }
  68. base.PositionWeight = data.BlendWeight;
  69. }
  70. public override void Update()
  71. {
  72. if (!this.CheckDoIK())
  73. {
  74. return;
  75. }
  76. this.SetPosOffset(this.m_PosOffset);
  77. }
  78. public void SetPosOffset(Vector3 offset)
  79. {
  80. if (!base.IsIKExec)
  81. {
  82. base.PointIK.IsIKExec = true;
  83. base.PositionWeight = 1f;
  84. }
  85. this.IsDoSetCharaPos = true;
  86. Vector3 pos = this.MyIKCtrl.TgtChara.GetPos();
  87. this.MyIKCtrl.TgtChara.SetPos(pos + offset * base.PositionWeight);
  88. }
  89. public void CharaPosReset()
  90. {
  91. if (this.IsDoSetCharaPos)
  92. {
  93. this.MyIKCtrl.TgtChara.SetPos(this.OrijinMaidPos);
  94. }
  95. this.IsDoSetCharaPos = false;
  96. }
  97. public override void Detach(IKCtrlData.IKAttachType attachType)
  98. {
  99. this.m_lastPosOffset = this.m_PosOffset;
  100. base.Detach(attachType);
  101. base.BlendPosRot.Copy(this.PosBaseBone);
  102. this.HeightFit = BodyCtrlData.HeightFitType.None;
  103. }
  104. [SerializeField]
  105. private Vector3 m_PosOffset = Vector3.zero;
  106. private Vector3 m_FirstBonePos = Vector3.zero;
  107. private Vector3 m_lastPosOffset = Vector3.zero;
  108. public Transform PosBaseBone;
  109. public BodyCtrlData.HeightFitType HeightFit = BodyCtrlData.HeightFitType.None;
  110. public enum HeightFitType
  111. {
  112. Higher,
  113. Lower,
  114. None
  115. }
  116. }