ShoulderThighIKCtrl.cs 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. using System;
  2. using RootMotion.FinalIK;
  3. using UnityEngine;
  4. [Serializable]
  5. public class ShoulderThighIKCtrl : ALimbIKCtrl
  6. {
  7. public ShoulderThighIKCtrl(IKEffector root_effector, FBIKChain chain, IKMappingLimb ik_mapping, FullBodyIKMgr ik_ctrl, FullBodyIKMgr.IKEffectorType effector_type) : base(ik_ctrl, chain, ik_mapping, effector_type)
  8. {
  9. this.effector = root_effector;
  10. this.effector.target = base.constraintTarget;
  11. base.isUpperBody = (effector_type == FullBodyIKMgr.IKEffectorType.UpperArm_L || effector_type == FullBodyIKMgr.IKEffectorType.UpperArm_R);
  12. }
  13. public override bool isLeft
  14. {
  15. get
  16. {
  17. return this.effectorType == FullBodyIKMgr.IKEffectorType.UpperArm_L || this.effectorType == FullBodyIKMgr.IKEffectorType.Thigh_L;
  18. }
  19. }
  20. public override ALimbIKCtrl pairIK
  21. {
  22. get
  23. {
  24. FullBodyIKMgr.IKEffectorType effector_type;
  25. if (base.isUpperBody)
  26. {
  27. effector_type = ((!this.isLeft) ? FullBodyIKMgr.IKEffectorType.UpperArm_L : FullBodyIKMgr.IKEffectorType.UpperArm_R);
  28. }
  29. else
  30. {
  31. effector_type = ((!this.isLeft) ? FullBodyIKMgr.IKEffectorType.Thigh_L : FullBodyIKMgr.IKEffectorType.Thigh_R);
  32. }
  33. return this.myIKMgr.GetIKCtrl<ALimbIKCtrl>(effector_type);
  34. }
  35. }
  36. public ElbowKneeIKCtrl elbowKneeCtrl { get; private set; }
  37. public HandFootIKCtrl handFootCtrl { get; private set; }
  38. public void SetChain(HandFootIKCtrl handfoot_data, ElbowKneeIKCtrl elbowknee_data)
  39. {
  40. this.handFootCtrl = handfoot_data;
  41. this.elbowKneeCtrl = elbowknee_data;
  42. this.ChainChildCtrl = elbowknee_data;
  43. }
  44. public override void ApplyIKSetting()
  45. {
  46. this.BackLocalPos = base.bone.localPosition;
  47. base.ApplyIKSetting();
  48. }
  49. public override void OnPostIKUpdate()
  50. {
  51. base.OnPostIKUpdate();
  52. base.bone.localPosition = this.BackLocalPos;
  53. }
  54. protected override void OnPostSetPositionWeight(float val)
  55. {
  56. if (this.IsPullBody)
  57. {
  58. this.effector.positionWeight = val;
  59. }
  60. }
  61. protected override void OnPostSetRotationWeight(float val)
  62. {
  63. if (this.IsPullBody)
  64. {
  65. this.effector.rotationWeight = val;
  66. }
  67. }
  68. public readonly IKEffector effector;
  69. private Vector3 BackLocalPos = Vector3.zero;
  70. }