WristTwist.cs 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. using System;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. public class WristTwist : ATwistCtrl
  5. {
  6. public WristTwist(bool is_left, TBody body) : base((!is_left) ? Maid.AutoTwist.WristR : Maid.AutoTwist.WristL, 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 Hand" : " L Hand";
  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 < 6; i++)
  23. {
  24. string name = (!is_left) ? string.Format("ForeTwist{0}_R", i + 1) : string.Format("ForeTwist{0}_L", i + 1);
  25. Transform transform = base.bone.parent.Find(name);
  26. if (transform)
  27. {
  28. Transform transform2 = base.mrBone.parent.Find(name);
  29. if (transform2)
  30. {
  31. base.twistBones.Add(new KeyValuePair<Transform, Transform>(transform2, transform));
  32. }
  33. }
  34. }
  35. }
  36. }
  37. public override void ApplyTwist()
  38. {
  39. Vector3 vector = base.bone.rotation * Vector3.forward;
  40. Vector3 vector2 = base.bone.parent.rotation * base.mrBone.localRotation * Vector3.forward;
  41. Vector3 normalized = (base.bone.position - base.bone.parent.position).normalized;
  42. vector2 = (vector2 - normalized * Vector3.Dot(vector2, normalized)).normalized;
  43. vector = (vector - normalized * Vector3.Dot(vector, normalized)).normalized;
  44. float f = Vector3.Dot(vector2, vector);
  45. float num = Mathf.Acos(f) * 57.29578f;
  46. if (float.IsNaN(num))
  47. {
  48. num = 0f;
  49. }
  50. else
  51. {
  52. Vector3 lhs = Vector3.Cross(normalized, vector2);
  53. if (Vector3.Dot(lhs, vector) < 0f)
  54. {
  55. num = -num;
  56. }
  57. }
  58. for (int i = 0; i < base.twistBones.Count; i++)
  59. {
  60. KeyValuePair<Transform, Transform> keyValuePair = base.twistBones[i];
  61. float num2 = (float)i / (float)(base.twistBones.Count - 1);
  62. keyValuePair.Value.localRotation = keyValuePair.Key.localRotation;
  63. keyValuePair.Value.rotation = Quaternion.AngleAxis(num * num2, normalized) * keyValuePair.Value.rotation;
  64. }
  65. }
  66. }