BlurEffectManager.cs 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. namespace COM3D2.MeidoPhotoStudio.Plugin
  2. {
  3. public class BlurEffectManager : IEffectManager
  4. {
  5. public const string header = "EFFECT_BLUR";
  6. private Blur Blur { get; set; }
  7. public bool Ready { get; private set; }
  8. public bool Active { get; private set; }
  9. private float initialBlurSize;
  10. private int initialBlurIterations;
  11. private int initialDownsample;
  12. private float blurSize;
  13. public float BlurSize
  14. {
  15. get => blurSize;
  16. set
  17. {
  18. blurSize = value;
  19. Blur.blurSize = blurSize / 10f;
  20. if (blurSize >= 3f)
  21. {
  22. Blur.blurSize -= 0.3f;
  23. Blur.blurIterations = 1;
  24. Blur.downsample = 1;
  25. }
  26. else
  27. {
  28. Blur.blurIterations = 0;
  29. Blur.downsample = 0;
  30. }
  31. }
  32. }
  33. public void Activate()
  34. {
  35. if (Blur == null)
  36. {
  37. Ready = true;
  38. Blur = GameMain.Instance.MainCamera.GetComponent<Blur>();
  39. initialBlurSize = Blur.blurSize;
  40. initialBlurIterations = Blur.blurIterations;
  41. initialDownsample = Blur.downsample;
  42. }
  43. SetEffectActive(false);
  44. }
  45. public void Deactivate()
  46. {
  47. BlurSize = 0f;
  48. Reset();
  49. Blur.enabled = false;
  50. Active = false;
  51. }
  52. public void SetEffectActive(bool active)
  53. {
  54. if (Blur.enabled = Active = active) BlurSize = BlurSize;
  55. else Reset();
  56. }
  57. public void Reset()
  58. {
  59. Blur.blurSize = initialBlurSize;
  60. Blur.blurIterations = initialBlurIterations;
  61. Blur.downsample = initialDownsample;
  62. }
  63. public void Update() { }
  64. }
  65. }