DragPointMeido.cs 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. using System;
  2. using UnityEngine;
  3. using static MeidoPhotoStudio.Plugin.CustomGizmo;
  4. namespace MeidoPhotoStudio.Plugin;
  5. public abstract class DragPointMeido : DragPoint
  6. {
  7. public static readonly Vector3 BoneScale = Vector3.one * 0.04f;
  8. protected const int JointUpper = 0;
  9. protected const int JointMiddle = 1;
  10. protected const int JointLower = 2;
  11. protected Meido meido;
  12. protected Maid maid;
  13. protected bool isPlaying;
  14. protected bool isBone;
  15. private const string IkDataTag = "左手";
  16. public virtual bool IsBone
  17. {
  18. get => isBone;
  19. set
  20. {
  21. if (value == isBone)
  22. return;
  23. isBone = value;
  24. ApplyDragType();
  25. }
  26. }
  27. // TODO: Come up with an intermediary fix for this until I can rewrite the IK system.
  28. // WARN: This does NOT work and is only done so the compiler does not complain
  29. protected
  30. #if COM25
  31. AIKCtrl IkCtrlData => meido.Body.fullBodyIK.GetIKCtrl(IkDataTag);
  32. #else
  33. IKCtrlData IkCtrlData => meido.Body.IKCtrl.GetIKData(IkDataTag);
  34. #endif
  35. public virtual void Initialize(Meido meido, Func<Vector3> position, Func<Vector3> rotation)
  36. {
  37. Initialize(position, rotation);
  38. this.meido = meido;
  39. maid = meido.Maid;
  40. isPlaying = !meido.Stop;
  41. }
  42. public override void AddGizmo(float scale = 0.25f, GizmoMode mode = GizmoMode.Local)
  43. {
  44. base.AddGizmo(scale, mode);
  45. Gizmo.GizmoDrag += (_, _) =>
  46. {
  47. meido.Stop = true;
  48. isPlaying = false;
  49. };
  50. }
  51. protected override void OnMouseDown()
  52. {
  53. base.OnMouseDown();
  54. isPlaying = !meido.Stop;
  55. }
  56. protected void InitializeIK(TBody.IKCMO iKCmo, Transform upper, Transform middle, Transform lower) =>
  57. iKCmo.Init(upper, middle, lower, maid.body0);
  58. // WARN: This does NOT work and is only done so the compiler does not complain
  59. protected void Porc(
  60. TBody.IKCMO ikCmo,
  61. #if COM25
  62. AIKCtrl
  63. #else
  64. IKCtrlData
  65. #endif
  66. ikData,
  67. Transform upper,
  68. Transform middle,
  69. Transform lower) =>
  70. ikCmo.Porc(upper, middle, lower, CursorPosition(), Vector3.zero, ikData);
  71. }