FogEffectManager.cs 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. using UnityEngine;
  2. namespace MeidoPhotoStudio.Plugin
  3. {
  4. public class FogEffectManager : IEffectManager
  5. {
  6. public const string header = "EFFECT_FOG";
  7. private GlobalFog Fog { get; set; }
  8. public bool Ready { get; private set; }
  9. public bool Active { get; private set; }
  10. private readonly float initialDistance = 4f;
  11. private readonly float initialDensity = 1f;
  12. private readonly float initialHeightScale = 1f;
  13. private readonly float initialHeight = 0f;
  14. private readonly Color initialColour = Color.white;
  15. private float distance;
  16. public float Distance
  17. {
  18. get => distance;
  19. set => distance = Fog.startDistance = value;
  20. }
  21. private float density;
  22. public float Density
  23. {
  24. get => density;
  25. set => density = Fog.globalDensity = value;
  26. }
  27. private float heightScale;
  28. public float HeightScale
  29. {
  30. get => heightScale;
  31. set => heightScale = Fog.heightScale = value;
  32. }
  33. private float height;
  34. public float Height
  35. {
  36. get => height;
  37. set => height = Fog.height = value;
  38. }
  39. public float FogColourRed
  40. {
  41. get => FogColour.r;
  42. set
  43. {
  44. Color fogColour = FogColour;
  45. FogColour = new Color(value, fogColour.g, fogColour.b);
  46. }
  47. }
  48. public float FogColourGreen
  49. {
  50. get => FogColour.g;
  51. set
  52. {
  53. Color fogColour = FogColour;
  54. FogColour = new Color(fogColour.r, value, fogColour.b);
  55. }
  56. }
  57. public float FogColourBlue
  58. {
  59. get => FogColour.b;
  60. set
  61. {
  62. Color fogColour = FogColour;
  63. FogColour = new Color(fogColour.r, fogColour.g, value);
  64. }
  65. }
  66. private Color fogColour;
  67. public Color FogColour
  68. {
  69. get => fogColour;
  70. set => fogColour = Fog.globalFogColor = value;
  71. }
  72. public void Activate()
  73. {
  74. if (Fog == null)
  75. {
  76. Ready = true;
  77. Fog = GameMain.Instance.MainCamera.GetOrAddComponent<GlobalFog>();
  78. if (Fog.fogShader == null) Fog.fogShader = Shader.Find("Hidden/GlobalFog");
  79. Distance = initialDistance;
  80. Density = initialDensity;
  81. HeightScale = initialHeightScale;
  82. Height = initialHeight;
  83. FogColour = initialColour;
  84. }
  85. SetEffectActive(false);
  86. }
  87. public void Deactivate()
  88. {
  89. Distance = initialDistance;
  90. Density = initialDensity;
  91. HeightScale = initialHeightScale;
  92. Height = initialHeight;
  93. FogColour = initialColour;
  94. Fog.enabled = false;
  95. Active = false;
  96. }
  97. public void Reset()
  98. {
  99. Fog.startDistance = initialDistance;
  100. Fog.globalDensity = initialDensity;
  101. Fog.heightScale = initialHeightScale;
  102. Fog.height = initialHeight;
  103. Fog.globalFogColor = initialColour;
  104. }
  105. public void SetEffectActive(bool active)
  106. {
  107. Fog.enabled = active;
  108. if (Active = active)
  109. {
  110. Fog.startDistance = Distance;
  111. Fog.globalDensity = Density;
  112. Fog.heightScale = HeightScale;
  113. Fog.height = Height;
  114. Fog.globalFogColor = FogColour;
  115. }
  116. else Reset();
  117. }
  118. public void Update() { }
  119. }
  120. }