MaidIKPane.cs 2.5 KB

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