CameraPane.cs 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. using System.Linq;
  2. using UnityEngine;
  3. namespace COM3D2.MeidoPhotoStudio.Plugin
  4. {
  5. public class CameraPane : BasePane
  6. {
  7. private readonly CameraManager cameraManager;
  8. private readonly SelectionGrid cameraGrid;
  9. private readonly Slider zRotationSlider;
  10. private readonly Slider fovSlider;
  11. private string header;
  12. public CameraPane(CameraManager cameraManager)
  13. {
  14. this.cameraManager = cameraManager;
  15. this.cameraManager.CameraChange += (s, a) => UpdatePane();
  16. Camera camera = CameraUtility.MainCamera.camera;
  17. Vector3 eulerAngles = camera.transform.eulerAngles;
  18. zRotationSlider = new Slider(Translation.Get("cameraPane", "zRotation"), 0f, 360f, eulerAngles.z)
  19. {
  20. HasReset = true, HasTextField = true
  21. };
  22. zRotationSlider.ControlEvent += (s, a) =>
  23. {
  24. if (updating) return;
  25. Vector3 newRotation = camera.transform.eulerAngles;
  26. newRotation.z = zRotationSlider.Value;
  27. camera.transform.rotation = Quaternion.Euler(newRotation);
  28. };
  29. var fieldOfView = camera.fieldOfView;
  30. fovSlider = new Slider(Translation.Get("cameraPane", "fov"), 20f, 150f, fieldOfView, fieldOfView)
  31. {
  32. HasReset = true, HasTextField = true
  33. };
  34. fovSlider.ControlEvent += (s, a) =>
  35. {
  36. if (updating) return;
  37. camera.fieldOfView = fovSlider.Value;
  38. };
  39. cameraGrid = new SelectionGrid(
  40. Enumerable.Range(1, cameraManager.CameraCount).Select(x => x.ToString()).ToArray()
  41. );
  42. cameraGrid.ControlEvent += (s, a) =>
  43. {
  44. if (updating) return;
  45. cameraManager.CurrentCameraIndex = cameraGrid.SelectedItemIndex;
  46. };
  47. header = Translation.Get("cameraPane", "header");
  48. }
  49. protected override void ReloadTranslation()
  50. {
  51. zRotationSlider.Label = Translation.Get("cameraPane", "zRotation");
  52. fovSlider.Label = Translation.Get("cameraPane", "fov");
  53. header = Translation.Get("cameraPane", "header");
  54. }
  55. public override void Draw()
  56. {
  57. MpsGui.Header(header);
  58. MpsGui.WhiteLine();
  59. cameraGrid.Draw();
  60. zRotationSlider.Draw();
  61. fovSlider.Draw();
  62. }
  63. public override void UpdatePane()
  64. {
  65. updating = true;
  66. Camera camera = CameraUtility.MainCamera.camera;
  67. zRotationSlider.Value = camera.transform.eulerAngles.z;
  68. fovSlider.Value = camera.fieldOfView;
  69. cameraGrid.SelectedItemIndex = cameraManager.CurrentCameraIndex;
  70. updating = false;
  71. }
  72. }
  73. }