VignetteEffectManager.cs 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. using UnityEngine;
  2. namespace COM3D2.MeidoPhotoStudio.Plugin
  3. {
  4. internal class VignetteEffectManager : IEffectManager
  5. {
  6. private Vignetting Vignette { get; set; }
  7. private float initialIntensity;
  8. private float initialBlur;
  9. private float initialBlurSpread;
  10. private float initialChromaticAberration;
  11. public bool IsReady { get; private set; }
  12. public bool IsActive { get; private set; }
  13. private float intensity;
  14. public float Intensity
  15. {
  16. get => intensity;
  17. set => intensity = Vignette.intensity = value;
  18. }
  19. private float blur;
  20. public float Blur
  21. {
  22. get => blur;
  23. set => blur = Vignette.blur = value;
  24. }
  25. private float blurSpread;
  26. public float BlurSpread
  27. {
  28. get => blurSpread;
  29. set => blurSpread = Vignette.blurSpread = value;
  30. }
  31. private float chromaticAberration;
  32. public float ChromaticAberration
  33. {
  34. get => chromaticAberration;
  35. set => chromaticAberration = Vignette.chromaticAberration = value;
  36. }
  37. public void Activate()
  38. {
  39. if (Vignette == null)
  40. {
  41. IsReady = true;
  42. Vignette = GameMain.Instance.MainCamera.GetOrAddComponent<Vignetting>();
  43. Vignette.mode = Vignetting.AberrationMode.Simple;
  44. initialIntensity = Vignette.intensity;
  45. initialBlur = Vignette.blur;
  46. initialBlurSpread = Vignette.blurSpread;
  47. initialChromaticAberration = Vignette.chromaticAberration;
  48. }
  49. }
  50. public void Deactivate()
  51. {
  52. Intensity = initialIntensity;
  53. Blur = initialBlur;
  54. BlurSpread = initialBlurSpread;
  55. ChromaticAberration = initialChromaticAberration;
  56. Vignette.enabled = false;
  57. IsActive = false;
  58. }
  59. public void Reset()
  60. {
  61. Vignette.intensity = initialIntensity;
  62. Vignette.blur = initialBlur;
  63. Vignette.blurSpread = initialBlurSpread;
  64. Vignette.chromaticAberration = initialChromaticAberration;
  65. }
  66. public void SetEffectActive(bool active)
  67. {
  68. Vignette.enabled = active;
  69. IsActive = active;
  70. if (this.IsActive)
  71. {
  72. Vignette.intensity = Intensity;
  73. Vignette.blur = Blur;
  74. Vignette.blurSpread = BlurSpread;
  75. Vignette.chromaticAberration = ChromaticAberration;
  76. }
  77. else Reset();
  78. }
  79. public void Update() { }
  80. }
  81. }