ShoulderTwist.cs 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. using System;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. public class ShoulderTwist : ATwistCtrl
  5. {
  6. public ShoulderTwist(bool is_left, TBody body) : base((!is_left) ? Maid.AutoTwist.ShoulderR : Maid.AutoTwist.ShoulderL, 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 UpperArm" : " L UpperArm";
  18. base.bone = body.GetBone(str + str2);
  19. base.mrBone = base.GetMRBone(str + str2);
  20. if (body.IsCrcBody)
  21. {
  22. for (int i = 0; i < 5; i++)
  23. {
  24. string name = (!is_left) ? string.Format("UpperTwist{0}_R", i + 1) : string.Format("UpperTwist{0}_L", i + 1);
  25. Transform transform = base.bone.Find(name);
  26. if (transform)
  27. {
  28. Transform transform2 = base.mrBone.Find(name);
  29. if (transform2)
  30. {
  31. base.twistBones.Add(new KeyValuePair<Transform, Transform>(transform2, transform));
  32. }
  33. }
  34. }
  35. string text = (!is_left) ? "Kata_R" : "Kata_L";
  36. Transform bone = body.GetBone(text);
  37. Transform mrbone = base.GetMRBone(text);
  38. if (bone && mrbone)
  39. {
  40. this.KataPair = new KeyValuePair<Transform, Transform>(mrbone, bone);
  41. }
  42. }
  43. }
  44. public void SetCalcMode(ShoulderTwist.CalcType calc_mode)
  45. {
  46. this.TwistCalcType = calc_mode;
  47. }
  48. public override void ApplyTwist()
  49. {
  50. Quaternion quaternion = base.bone.parent.rotation;
  51. quaternion = Quaternion.FromToRotation(quaternion * Vector3.right, base.bone.rotation * Vector3.right) * quaternion;
  52. for (int i = 0; i < base.twistBones.Count; i++)
  53. {
  54. KeyValuePair<Transform, Transform> keyValuePair = base.twistBones[i];
  55. float t = (float)(i + 1) / (float)base.twistBones.Count;
  56. keyValuePair.Value.rotation = Quaternion.Lerp(quaternion, base.bone.rotation, t);
  57. }
  58. if (base.twistBones.Count > 0 && this.KataPair.Key && this.KataPair.Value)
  59. {
  60. if (this.TwistCalcType == ShoulderTwist.CalcType.Normal)
  61. {
  62. this.KataPair.Value.localRotation = this.KataPair.Key.localRotation;
  63. this.KataPair.Value.rotation = Quaternion.Lerp(this.KataPair.Value.rotation, base.twistBones[0].Value.rotation, 0.5f);
  64. }
  65. else
  66. {
  67. this.KataPair.Value.rotation = Quaternion.Lerp(quaternion, base.twistBones[0].Value.rotation, 0.5f);
  68. }
  69. }
  70. }
  71. private KeyValuePair<Transform, Transform> KataPair;
  72. private const float KATA_BLEND_VAL = 0.5f;
  73. private ShoulderTwist.CalcType TwistCalcType;
  74. public enum CalcType
  75. {
  76. Normal,
  77. Behind
  78. }
  79. }