ElbowKneeIKData.cs 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. using System;
  2. using RootMotion.FinalIK;
  3. using UnityEngine;
  4. [Serializable]
  5. public class ElbowKneeIKData : LimbIKData
  6. {
  7. public ElbowKneeIKData(FBIKChain chain, FullBodyIKCtrl ik_ctrl, Transform tgt_bone) : base(ik_ctrl, chain, tgt_bone, false)
  8. {
  9. this.Chain.bendConstraint.bendGoal = base.IKTarget;
  10. this.PositionWeight = 0f;
  11. this.m_ForceIKEnable = true;
  12. }
  13. public override float PositionWeight
  14. {
  15. get
  16. {
  17. return this.Chain.bendConstraint.weight;
  18. }
  19. set
  20. {
  21. this.Chain.bendConstraint.weight = value;
  22. }
  23. }
  24. public override float RotationWeight { get; set; }
  25. public ShoulderThighIKData ShoulderThighData
  26. {
  27. get
  28. {
  29. return this.m_ShoulderThighData;
  30. }
  31. }
  32. public HandFootIKData HandFootData
  33. {
  34. get
  35. {
  36. return this.m_HandFootData;
  37. }
  38. }
  39. protected override void SetTargetTransform(IKCtrlData.IKSettingData data, Vector3 pos, Quaternion rot)
  40. {
  41. base.SetTargetTransform(data, pos, rot);
  42. Vector3 position = this.m_ShoulderThighData.TargetBone.InverseTransformPoint(this.TargetBone.position);
  43. Vector3 vector = this.TargetBone.InverseTransformPoint(this.m_HandFootData.TargetBone.position);
  44. Transform iktarget = this.m_HandFootData.IKTarget;
  45. Transform iktarget2 = this.m_ShoulderThighData.IKTarget;
  46. if (data.IsPointAttach)
  47. {
  48. if (!this.m_ShoulderThighData.GetIKSettingData(IKCtrlData.IKAttachType.NewPoint).IsIKExec)
  49. {
  50. this.m_ShoulderThighData.PositionWeight = this.PositionWeight;
  51. Vector3 b = base.IKTarget.position - iktarget2.TransformPoint(position);
  52. iktarget2.position += b;
  53. }
  54. if (!this.m_ShoulderThighData.GetIKSettingData(IKCtrlData.IKAttachType.Rotate).IsIKExec)
  55. {
  56. this.m_ShoulderThighData.RotationWeight = this.PositionWeight;
  57. iktarget2.rotation = Quaternion.FromToRotation(this.TargetBone.position - this.ShoulderThighData.TargetBone.position, base.IKTarget.position - iktarget2.position) * iktarget2.rotation;
  58. }
  59. }
  60. }
  61. public void SetChainData(HandFootIKData handfoot_data, ShoulderThighIKData shoulderthigh_data)
  62. {
  63. this.m_HandFootData = handfoot_data;
  64. this.m_ShoulderThighData = shoulderthigh_data;
  65. }
  66. private ShoulderThighIKData m_ShoulderThighData;
  67. private HandFootIKData m_HandFootData;
  68. }