MaidIKPane.cs 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. using UnityEngine;
  2. namespace MeidoPhotoStudio.Plugin;
  3. public class MaidIKPane : BasePane
  4. {
  5. private readonly MeidoManager meidoManager;
  6. private readonly Toggle ikToggle;
  7. private readonly Toggle releaseIKToggle;
  8. private readonly Toggle boneIKToggle;
  9. private enum IKToggle
  10. {
  11. IK, Release, Bone
  12. }
  13. public MaidIKPane(MeidoManager meidoManager)
  14. {
  15. this.meidoManager = meidoManager;
  16. ikToggle = new(Translation.Get("maidPoseWindow", "ikToggle"), true);
  17. ikToggle.ControlEvent += (s, a) => SetIK(IKToggle.IK, ikToggle.Value);
  18. releaseIKToggle = new(Translation.Get("maidPoseWindow", "releaseToggle"));
  19. releaseIKToggle.ControlEvent += (s, a) => SetIK(IKToggle.Release, releaseIKToggle.Value);
  20. boneIKToggle = new(Translation.Get("maidPoseWindow", "boneToggle"));
  21. boneIKToggle.ControlEvent += (s, a) => SetIK(IKToggle.Bone, boneIKToggle.Value);
  22. }
  23. public override void UpdatePane()
  24. {
  25. updating = true;
  26. ikToggle.Value = meidoManager.ActiveMeido.IK;
  27. releaseIKToggle.Value = meidoManager.ActiveMeido.Stop;
  28. boneIKToggle.Value = meidoManager.ActiveMeido.Bone;
  29. updating = false;
  30. }
  31. public override void Draw()
  32. {
  33. var active = meidoManager.HasActiveMeido;
  34. GUILayout.BeginHorizontal();
  35. GUI.enabled = active;
  36. ikToggle.Draw();
  37. GUI.enabled = active && meidoManager.ActiveMeido.Stop;
  38. releaseIKToggle.Draw();
  39. GUI.enabled = active && ikToggle.Value;
  40. boneIKToggle.Draw();
  41. GUILayout.EndHorizontal();
  42. GUI.enabled = true;
  43. }
  44. protected override void ReloadTranslation()
  45. {
  46. ikToggle.Label = Translation.Get("maidPoseWindow", "ikToggle");
  47. releaseIKToggle.Label = Translation.Get("maidPoseWindow", "releaseToggle");
  48. boneIKToggle.Label = Translation.Get("maidPoseWindow", "boneToggle");
  49. }
  50. private void SetIK(IKToggle toggle, bool value)
  51. {
  52. if (updating)
  53. return;
  54. if (toggle is IKToggle.IK)
  55. meidoManager.ActiveMeido.IK = value;
  56. else if (toggle is IKToggle.Release)
  57. meidoManager.ActiveMeido.Stop = false;
  58. else if (toggle is IKToggle.Bone)
  59. meidoManager.ActiveMeido.Bone = value;
  60. }
  61. }