ScreenEffectManager.cs 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. namespace ShotSimulator.Screen
  5. {
  6. public class ScreenEffectManager : MonoSingleton<ScreenEffectManager>
  7. {
  8. private ScreenEffect[] m_ScreenEffects;
  9. private float brightness;
  10. private float saturation;
  11. private float contrast;
  12. private Color[] targetColors = new Color[]
  13. {
  14. new Color(20f/255f,191f/255f,237f/255f),
  15. new Color(20f/255f,237f/255f,149f/255f),
  16. new Color(237f/255f,237f/255f,20f/255f),
  17. new Color(239f/255f,17f/255f,17f/255f),
  18. };
  19. private int targetColorIndex;
  20. public override void InitManager()
  21. {
  22. base.InitManager();
  23. m_ScreenEffects = FindObjectsOfType<ScreenEffect>();
  24. SetBrightness(PlayerPrefs.HasKey("Brightness") ? PlayerPrefs.GetFloat("Brightness") : 1);
  25. SetSaturation(PlayerPrefs.HasKey("Saturation") ? PlayerPrefs.GetFloat("Saturation") : 1);
  26. SetTargetColorIndex(PlayerPrefs.HasKey("TargetColorIndex") ? PlayerPrefs.GetInt("TargetColorIndex") : 0);
  27. }
  28. public float GetBrightness()
  29. {
  30. return brightness;
  31. }
  32. public void SetBrightness(float value)
  33. {
  34. brightness = Mathf.Clamp(value, 0f, 4f);
  35. foreach(var effect in m_ScreenEffects)
  36. {
  37. effect.brightness = brightness;
  38. }
  39. PlayerPrefs.SetFloat("Brightness", brightness);
  40. }
  41. public float GetSaturation()
  42. {
  43. return saturation;
  44. }
  45. public void SetSaturation(float value)
  46. {
  47. saturation = Mathf.Clamp(value, 0f, 4f);
  48. foreach (var effect in m_ScreenEffects)
  49. {
  50. effect.saturation = saturation;
  51. }
  52. PlayerPrefs.SetFloat("Saturation", brightness);
  53. }
  54. public int GetTargetColorIndex()
  55. {
  56. return targetColorIndex;
  57. }
  58. public void SetTargetColorIndex(int index)
  59. {
  60. targetColorIndex = index;
  61. PlayerPrefs.SetInt("TargetColorIndex", index);
  62. }
  63. public Color GetTargetColor()
  64. {
  65. return targetColors[targetColorIndex];
  66. }
  67. private Color TryParseHtmlColor(string colorString)
  68. {
  69. Color outColor;
  70. ColorUtility.TryParseHtmlString(colorString, out outColor);
  71. return outColor;
  72. }
  73. private void SetContrast(float value)
  74. {
  75. contrast = Mathf.Clamp(value, 0f, 4f);
  76. foreach (var effect in m_ScreenEffects)
  77. {
  78. effect.contrast = contrast;
  79. }
  80. }
  81. }
  82. }