CCDIKCtrlData.cs 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. using System;
  2. using System.Linq;
  3. using RootMotion.FinalIK;
  4. using UnityEngine;
  5. [Serializable]
  6. public class CCDIKCtrlData : IKCtrlData
  7. {
  8. public CCDIKCtrlData(CCDIK ccd_ik, Transform[] chain_bones, FullBodyIKCtrl ik_ctrl, bool weight_fade = true, bool attach_ik = false) : base(ik_ctrl, chain_bones.Last<Transform>(), false, attach_ik)
  9. {
  10. this.CCDIK = ccd_ik;
  11. this.CCDIK.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. if (weight_fade)
  18. {
  19. this.IKSolver.FadeOutBoneWeights();
  20. }
  21. this.CCDIK.enabled = false;
  22. this.m_ForceIKEnable = false;
  23. }
  24. public IKSolverCCD IKSolver
  25. {
  26. get
  27. {
  28. return this.CCDIK.solver;
  29. }
  30. }
  31. public override Transform[] ChainBones
  32. {
  33. get
  34. {
  35. return (from bone in this.IKSolver.bones
  36. select bone.transform).ToArray<Transform>();
  37. }
  38. }
  39. public override float PositionWeight
  40. {
  41. get
  42. {
  43. return this.IKSolver.IKPositionWeight;
  44. }
  45. set
  46. {
  47. this.IKSolver.IKPositionWeight = value;
  48. }
  49. }
  50. public override float RotationWeight { get; set; }
  51. public override void Update()
  52. {
  53. this.CCDIK.solver.Update();
  54. }
  55. public readonly CCDIK CCDIK;
  56. }