FBBIKSettings.cs 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. using UnityEngine;
  2. using System.Collections;
  3. using RootMotion.FinalIK;
  4. namespace RootMotion.Demos {
  5. /// <summary>
  6. /// Manages FBBIK settings that are not visible in the FBBIK custom inspector.
  7. /// </summary>
  8. public class FBBIKSettings : MonoBehaviour {
  9. /// <summary>
  10. /// Settings for a limb
  11. /// </summary>
  12. [System.Serializable]
  13. public class Limb {
  14. public FBIKChain.Smoothing reachSmoothing; // Smoothing of the Reach effect (since 0.2)
  15. public float maintainRelativePositionWeight; // Weight of maintaining the limb's position relative to the body part that it is attached to (since 0.2, used to be IKEffector.Mode.MaintainRelativePosition)
  16. public float mappingWeight = 1f;
  17. // Apply the settings
  18. public void Apply(FullBodyBipedChain chain, IKSolverFullBodyBiped solver) {
  19. solver.GetChain(chain).reachSmoothing = reachSmoothing;
  20. solver.GetEndEffector(chain).maintainRelativePositionWeight = maintainRelativePositionWeight;
  21. solver.GetLimbMapping(chain).weight = mappingWeight;
  22. }
  23. }
  24. public FullBodyBipedIK ik; // Reference to the FBBIK component
  25. public bool disableAfterStart; // If true, will not update after Start
  26. public Limb leftArm, rightArm, leftLeg, rightLeg; // The Limbs
  27. public float rootPin = 0f; // Weight of pinning the root node to it's animated position
  28. public bool bodyEffectChildNodes = true; // If true, the body effector will also drag the thigh effectors
  29. // Apply all the settings to the FBBIK solver
  30. public void UpdateSettings() {
  31. if (ik == null) return;
  32. leftArm.Apply(FullBodyBipedChain.LeftArm, ik.solver);
  33. rightArm.Apply(FullBodyBipedChain.RightArm, ik.solver);
  34. leftLeg.Apply(FullBodyBipedChain.LeftLeg, ik.solver);
  35. rightLeg.Apply(FullBodyBipedChain.RightLeg, ik.solver);
  36. ik.solver.chain[0].pin = rootPin;
  37. ik.solver.bodyEffector.effectChildNodes = bodyEffectChildNodes;
  38. }
  39. void Start() {
  40. Debug.Log("FBBIKSettings is deprecated, you can now edit all the settings from the custom inspector of the FullBodyBipedIK component.");
  41. UpdateSettings();
  42. if (disableAfterStart) this.enabled = false;
  43. }
  44. void Update() {
  45. UpdateSettings();
  46. }
  47. }
  48. }