BodyCtrlData.cs 3.4 KB

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