ShoulderThighIKData.cs 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. using System;
  2. using RootMotion.FinalIK;
  3. using UnityEngine;
  4. [Serializable]
  5. public class ShoulderThighIKData : LimbIKData
  6. {
  7. public ShoulderThighIKData(IKEffector root_effector, FBIKChain chain, IKMappingLimb ik_mapping, FullBodyIKCtrl ik_ctrl, Transform tgt_bone) : base(ik_ctrl, chain, ik_mapping, tgt_bone, false)
  8. {
  9. this.Effector = root_effector;
  10. this.Effector.target = base.IKTarget;
  11. this.m_IsUpperBody = (this.TargetBone == this.MyIKCtrl.GetIKBone(FullBodyIKCtrl.IKBoneType.UpperArm_L) || this.TargetBone == this.MyIKCtrl.GetIKBone(FullBodyIKCtrl.IKBoneType.UpperArm_R));
  12. this.m_ForceIKEnable = true;
  13. }
  14. public ElbowKneeIKData ElbowKneeData
  15. {
  16. get
  17. {
  18. return this.m_ElbowKneeData;
  19. }
  20. }
  21. public HandFootIKData HandFootData
  22. {
  23. get
  24. {
  25. return this.m_HandFootData;
  26. }
  27. }
  28. protected override void SetTargetTransform(IKCtrlData.IKSettingData data, Vector3 pos, Quaternion rot)
  29. {
  30. base.SetTargetTransform(data, pos, rot);
  31. Transform iktarget = this.m_HandFootData.IKTarget;
  32. Transform iktarget2 = this.m_ElbowKneeData.IKTarget;
  33. Vector3 position = this.TargetBone.InverseTransformPoint(this.m_ElbowKneeData.TargetBone.position);
  34. Vector3 position2 = this.m_ElbowKneeData.TargetBone.InverseTransformPoint(this.m_HandFootData.TargetBone.position);
  35. if (!data.IsPointAttach)
  36. {
  37. if (!this.m_ElbowKneeData.GetIKSettingData(IKCtrlData.IKAttachType.Rotate).IsIKExec)
  38. {
  39. iktarget2.rotation = base.IKTarget.rotation * this.m_ElbowKneeData.TargetBone.localRotation;
  40. }
  41. if (!this.m_HandFootData.GetIKSettingData(IKCtrlData.IKAttachType.Rotate).IsIKExec)
  42. {
  43. iktarget.rotation = iktarget2.rotation * this.m_HandFootData.TargetBone.localRotation;
  44. }
  45. }
  46. if (!this.m_ElbowKneeData.GetIKSettingData(IKCtrlData.IKAttachType.NewPoint).IsIKExec)
  47. {
  48. iktarget2.position = base.IKTarget.TransformPoint(position);
  49. }
  50. if (!this.m_HandFootData.GetIKSettingData(IKCtrlData.IKAttachType.NewPoint).IsIKExec)
  51. {
  52. iktarget.position = iktarget2.TransformPoint(position2);
  53. }
  54. }
  55. public void SetChainData(HandFootIKData handfoot_data, ElbowKneeIKData elbowknee_data)
  56. {
  57. this.m_HandFootData = handfoot_data;
  58. this.m_ElbowKneeData = elbowknee_data;
  59. }
  60. protected override void OnPostSetPositionWeight(float val)
  61. {
  62. if (this.m_IsPullBody)
  63. {
  64. this.Effector.positionWeight = val;
  65. }
  66. }
  67. protected override void OnPostSetRotationWeight(float val)
  68. {
  69. if (this.m_IsPullBody)
  70. {
  71. this.Effector.rotationWeight = val;
  72. }
  73. }
  74. public override void Update()
  75. {
  76. if (!this.m_IsPullBody && base.RotateIK.IsIKExec)
  77. {
  78. this.TargetBone.rotation = Quaternion.Lerp(this.TargetBone.rotation, base.IKTarget.rotation, base.RotationWeight);
  79. }
  80. }
  81. public readonly IKEffector Effector;
  82. private ElbowKneeIKData m_ElbowKneeData;
  83. private HandFootIKData m_HandFootData;
  84. }