BipedIKSolvers.cs 2.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. using UnityEngine;
  2. using System.Collections;
  3. using System;
  4. namespace RootMotion.FinalIK {
  5. /// <summary>
  6. /// BipedIK solver collection.
  7. /// </summary>
  8. [System.Serializable]
  9. public class BipedIKSolvers {
  10. /// <summary>
  11. /// The left foot
  12. /// </summary>
  13. public IKSolverLimb leftFoot = new IKSolverLimb(AvatarIKGoal.LeftFoot);
  14. /// <summary>
  15. /// The right foot.
  16. /// </summary>
  17. public IKSolverLimb rightFoot = new IKSolverLimb(AvatarIKGoal.RightFoot);
  18. /// <summary>
  19. /// The left hand.
  20. /// </summary>
  21. public IKSolverLimb leftHand = new IKSolverLimb(AvatarIKGoal.LeftHand);
  22. /// <summary>
  23. /// The right hand.
  24. /// </summary>
  25. public IKSolverLimb rightHand = new IKSolverLimb(AvatarIKGoal.RightHand);
  26. /// <summary>
  27. /// The spine.
  28. /// </summary>
  29. public IKSolverFABRIK spine = new IKSolverFABRIK();
  30. /// <summary>
  31. /// The Look At %IK.
  32. /// </summary>
  33. public IKSolverLookAt lookAt = new IKSolverLookAt();
  34. /// <summary>
  35. /// The Aim %IK. Rotates the spine to aim a transform's forward towards the target.
  36. /// </summary>
  37. public IKSolverAim aim = new IKSolverAim();
  38. /// <summary>
  39. /// %Constraints for manipulating the character's pelvis.
  40. /// </summary>
  41. public Constraints pelvis = new Constraints();
  42. /// <summary>
  43. /// Gets the array containing all the limbs.
  44. /// </summary>
  45. public IKSolverLimb[] limbs {
  46. get {
  47. if (_limbs == null || (_limbs != null && _limbs.Length != 4)) _limbs = new IKSolverLimb[4] { leftFoot, rightFoot, leftHand, rightHand };
  48. return _limbs;
  49. }
  50. }
  51. private IKSolverLimb[] _limbs;
  52. /// <summary>
  53. /// Gets the array containing all %IK solvers.
  54. /// </summary>
  55. public IKSolver[] ikSolvers {
  56. get {
  57. if (_ikSolvers == null || (_ikSolvers != null && _ikSolvers.Length != 7)) _ikSolvers = new IKSolver[7] { leftFoot, rightFoot, leftHand, rightHand, spine, lookAt, aim };
  58. return _ikSolvers;
  59. }
  60. }
  61. private IKSolver[] _ikSolvers;
  62. public void AssignReferences(BipedReferences references) {
  63. // Assigning limbs from references
  64. leftHand.SetChain(references.leftUpperArm, references.leftForearm, references.leftHand, references.root);
  65. rightHand.SetChain(references.rightUpperArm, references.rightForearm, references.rightHand, references.root);
  66. leftFoot.SetChain(references.leftThigh, references.leftCalf, references.leftFoot, references.root);
  67. rightFoot.SetChain(references.rightThigh, references.rightCalf, references.rightFoot, references.root);
  68. // Assigning spine bones from references
  69. spine.SetChain(references.spine, references.root);
  70. // Assigning lookAt bones from references
  71. lookAt.SetChain(references.spine, references.head, references.eyes, references.root);
  72. // Assigning Aim bones from references
  73. aim.SetChain(references.spine, references.root);
  74. leftFoot.goal = AvatarIKGoal.LeftFoot;
  75. rightFoot.goal = AvatarIKGoal.RightFoot;
  76. leftHand.goal = AvatarIKGoal.LeftHand;
  77. rightHand.goal = AvatarIKGoal.RightHand;
  78. }
  79. }
  80. }