MaidFreeLookPane.cs 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. using UnityEngine;
  2. namespace COM3D2.MeidoPhotoStudio.Plugin
  3. {
  4. public class MaidFaceLookPane : BasePane
  5. {
  6. private readonly MeidoManager meidoManager;
  7. private readonly Slider lookXSlider;
  8. private readonly Slider lookYSlider;
  9. private readonly Toggle headToCamToggle;
  10. private readonly Toggle eyeToCamToggle;
  11. private string bindLabel;
  12. public MaidFaceLookPane(MeidoManager meidoManager)
  13. {
  14. this.meidoManager = meidoManager;
  15. lookXSlider = new Slider(Translation.Get("freeLookPane", "xSlider"), -0.6f, 0.6f);
  16. lookXSlider.ControlEvent += (s, a) => SetMaidLook();
  17. lookYSlider = new Slider(Translation.Get("freeLookPane", "ySlider"), 0.5f, -0.55f);
  18. lookYSlider.ControlEvent += (s, a) => SetMaidLook();
  19. headToCamToggle = new Toggle(Translation.Get("freeLookPane", "headToCamToggle"));
  20. headToCamToggle.ControlEvent += (s, a) => SetHeadToCam(headToCamToggle.Value, eye: false);
  21. eyeToCamToggle = new Toggle(Translation.Get("freeLookPane", "eyeToCamToggle"));
  22. eyeToCamToggle.ControlEvent += (s, a) => SetHeadToCam(eyeToCamToggle.Value, eye: true);
  23. bindLabel = Translation.Get("freeLookPane", "bindLabel");
  24. }
  25. protected override void ReloadTranslation()
  26. {
  27. lookXSlider.Label = Translation.Get("freeLookPane", "xSlider");
  28. lookYSlider.Label = Translation.Get("freeLookPane", "ySlider");
  29. headToCamToggle.Label = Translation.Get("freeLookPane", "headToCamToggle");
  30. eyeToCamToggle.Label = Translation.Get("freeLookPane", "eyeToCamToggle");
  31. bindLabel = Translation.Get("freeLookPane", "bindLabel");
  32. }
  33. public void SetHeadToCam(bool value, bool eye = false)
  34. {
  35. if (updating) return;
  36. Meido meido = meidoManager.ActiveMeido;
  37. if (eye) meido.EyeToCam = value;
  38. else meido.HeadToCam = value;
  39. }
  40. public void SetMaidLook()
  41. {
  42. if (updating) return;
  43. TBody body = meidoManager.ActiveMeido.Body;
  44. body.offsetLookTarget = new Vector3(lookYSlider.Value, 1f, lookXSlider.Value);
  45. }
  46. public void SetBounds()
  47. {
  48. float left = 0.5f;
  49. float right = -0.55f;
  50. if (meidoManager.ActiveMeido.Stop)
  51. {
  52. left *= 0.6f;
  53. right *= 0.6f;
  54. }
  55. lookYSlider.SetBounds(left, right);
  56. }
  57. public override void UpdatePane()
  58. {
  59. Meido meido = meidoManager.ActiveMeido;
  60. updating = true;
  61. SetBounds();
  62. lookXSlider.Value = meido.Body.offsetLookTarget.z;
  63. lookYSlider.Value = meido.Body.offsetLookTarget.x;
  64. eyeToCamToggle.Value = meido.EyeToCam;
  65. headToCamToggle.Value = meido.HeadToCam;
  66. updating = false;
  67. }
  68. public override void Draw()
  69. {
  70. GUI.enabled = meidoManager.HasActiveMeido && meidoManager.ActiveMeido.FreeLook;
  71. GUILayout.BeginHorizontal();
  72. lookXSlider.Draw();
  73. lookYSlider.Draw();
  74. GUILayout.EndHorizontal();
  75. GUI.enabled = meidoManager.HasActiveMeido;
  76. GUILayout.BeginHorizontal();
  77. GUILayout.Label(bindLabel, GUILayout.ExpandWidth(false));
  78. eyeToCamToggle.Draw();
  79. headToCamToggle.Draw();
  80. GUILayout.EndHorizontal();
  81. GUI.enabled = true;
  82. }
  83. }
  84. }