FABRIKCtrlData.cs 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. using System;
  2. using System.Linq;
  3. using RootMotion.FinalIK;
  4. using UnityEngine;
  5. [Serializable]
  6. public class FABRIKCtrlData : IKCtrlData
  7. {
  8. public FABRIKCtrlData(FABRIK fabr_ik, Transform[] chain_bones, FullBodyIKCtrl ik_ctrl, bool attach_ik = false) : base(ik_ctrl, chain_bones.Last<Transform>(), false, attach_ik)
  9. {
  10. this.FABRIK = fabr_ik;
  11. this.FABRIK.fixTransforms = false;
  12. this.IKSolver.target = base.IKTarget;
  13. this.IKSolver.useRotationLimits = false;
  14. this.IKSolver.maxIterations = 4;
  15. this.IKSolver.Initiate(chain_bones[0]);
  16. this.IKSolver.SetChain(chain_bones, chain_bones[0]);
  17. this.FABRIK.enabled = false;
  18. this.m_ForceIKEnable = false;
  19. }
  20. public IKSolverFABRIK IKSolver
  21. {
  22. get
  23. {
  24. return this.FABRIK.solver;
  25. }
  26. }
  27. public override Transform[] ChainBones
  28. {
  29. get
  30. {
  31. return (from bone in this.IKSolver.bones
  32. select bone.transform).ToArray<Transform>();
  33. }
  34. }
  35. public override float PositionWeight
  36. {
  37. get
  38. {
  39. return this.IKSolver.IKPositionWeight;
  40. }
  41. set
  42. {
  43. this.IKSolver.IKPositionWeight = value;
  44. }
  45. }
  46. public override float RotationWeight { get; set; }
  47. public override void Update()
  48. {
  49. this.FABRIK.solver.Update();
  50. if (base.RotateIK.IsIKExec)
  51. {
  52. this.TargetBone.rotation = Quaternion.Lerp(this.TargetBone.rotation, base.IKTarget.rotation, this.RotationWeight);
  53. }
  54. }
  55. public readonly FABRIK FABRIK;
  56. }