DragPointTorso.cs 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. using System;
  2. using UnityEngine;
  3. namespace COM3D2.MeidoPhotoStudio.Plugin
  4. {
  5. internal class DragPointTorso : DragPointMeido
  6. {
  7. private static readonly float[] blah = new[] { 0.03f, 0.1f, 0.09f, 0.07f };
  8. private static readonly float[] something = new[] { 0.08f, 0.15f };
  9. private Transform[] spine = new Transform[4];
  10. private Quaternion[] spineRotation = new Quaternion[4];
  11. public override void Set(Transform spine1a)
  12. {
  13. base.Set(spine1a);
  14. Transform spine = spine1a;
  15. for (int i = 0; i < this.spine.Length; i++)
  16. {
  17. this.spine[i] = spine;
  18. spine = spine.parent;
  19. }
  20. }
  21. protected override void ApplyDragType()
  22. {
  23. if (CurrentDragType == DragType.Ignore) ApplyProperties();
  24. else if (IsBone) ApplyProperties(false, false, false);
  25. else ApplyProperties(CurrentDragType != DragType.None, false, false);
  26. }
  27. protected override void UpdateDragType()
  28. {
  29. if (Input.GetKey(KeyCode.Space) || OtherDragType())
  30. {
  31. CurrentDragType = DragType.Ignore;
  32. }
  33. else if (Utility.GetModKey(Utility.ModKey.Alt) && !Utility.GetModKey(Utility.ModKey.Control))
  34. {
  35. bool shift = Utility.GetModKey(Utility.ModKey.Shift);
  36. CurrentDragType = shift ? DragType.RotLocalY : DragType.RotLocalXZ;
  37. }
  38. else
  39. {
  40. CurrentDragType = DragType.None;
  41. }
  42. }
  43. protected override void OnMouseDown()
  44. {
  45. base.OnMouseDown();
  46. for (int i = 0; i < spine.Length; i++)
  47. {
  48. spineRotation[i] = spine[i].localRotation;
  49. }
  50. }
  51. protected override void Drag()
  52. {
  53. if (CurrentDragType == DragType.None) return;
  54. if (isPlaying) meido.IsStop = true;
  55. Vector3 mouseDelta = MouseDelta();
  56. if (CurrentDragType == DragType.RotLocalXZ)
  57. {
  58. for (int i = 0; i < spine.Length; i++)
  59. {
  60. spine[i].localRotation = spineRotation[i];
  61. spine[i].Rotate(
  62. camera.transform.forward, -mouseDelta.x / 1.5f * blah[i], Space.World
  63. );
  64. spine[i].Rotate(camera.transform.right, mouseDelta.y * blah[i], Space.World);
  65. }
  66. }
  67. if (CurrentDragType == DragType.RotLocalY)
  68. {
  69. for (int i = 0; i < spine.Length; i++)
  70. {
  71. spine[i].localRotation = spineRotation[i];
  72. spine[i].Rotate(Vector3.right * (mouseDelta.x / 1.5f * something[i / 2]));
  73. }
  74. }
  75. }
  76. }
  77. }