ThighTwist.cs 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. using System;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. public class ThighTwist : ATwistCtrl
  5. {
  6. public ThighTwist(bool is_left, TBody body) : base((!is_left) ? Maid.AutoTwist.ThighR : Maid.AutoTwist.ThighL, body)
  7. {
  8. string str;
  9. if (body.IsCrcBody)
  10. {
  11. str = "Bip01";
  12. }
  13. else
  14. {
  15. str = (body.boMAN ? "ManBip" : "Bip01");
  16. }
  17. string str2 = (!is_left) ? " R Thigh" : " L Thigh";
  18. base.bone = body.GetBone(str + str2);
  19. base.mrBone = base.GetMRBone(str + str2);
  20. this.Pelvis = body.GetBone(str + " Pelvis");
  21. if (body.IsCrcBody)
  22. {
  23. for (int i = 0; i < 5; i++)
  24. {
  25. string name = (!is_left) ? string.Format("ThighTwist{0}_R", i + 1) : string.Format("ThighTwist{0}_L", i + 1);
  26. Transform transform = base.bone.Find(name);
  27. if (transform)
  28. {
  29. Transform transform2 = base.mrBone.Find(name);
  30. if (transform2)
  31. {
  32. base.twistBones.Add(new KeyValuePair<Transform, Transform>(transform2, transform));
  33. }
  34. }
  35. }
  36. string text = (!is_left) ? "Hip_R" : "Hip_L";
  37. Transform bone = body.GetBone(text);
  38. Transform mrbone = base.GetMRBone(text);
  39. if (bone && mrbone)
  40. {
  41. this.HipPair = new KeyValuePair<Transform, Transform>(mrbone, bone);
  42. }
  43. }
  44. }
  45. public override void ApplyTwist()
  46. {
  47. Quaternion quaternion = base.bone.parent.rotation * base.mrBone.localRotation;
  48. quaternion = Quaternion.FromToRotation(quaternion * Vector3.right, base.bone.right) * quaternion;
  49. for (int i = 0; i < base.twistBones.Count; i++)
  50. {
  51. KeyValuePair<Transform, Transform> keyValuePair = base.twistBones[i];
  52. float t = (float)(i + 1) / (float)base.twistBones.Count;
  53. keyValuePair.Value.rotation = Quaternion.Lerp(quaternion, base.bone.rotation, t);
  54. }
  55. if (base.twistBones.Count > 0 && this.HipPair.Key && this.HipPair.Value)
  56. {
  57. this.HipPair.Value.localRotation = this.HipPair.Key.localRotation;
  58. this.HipPair.Value.rotation = Quaternion.Lerp(this.HipPair.Value.rotation, base.twistBones[0].Value.rotation, 0.67f);
  59. }
  60. }
  61. private KeyValuePair<Transform, Transform> HipPair;
  62. private const float HIP_BLEND_VAL = 0.67f;
  63. private Transform Pelvis;
  64. }