FogEffectManager.cs 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  1. using UnityEngine;
  2. namespace MeidoPhotoStudio.Plugin;
  3. public class FogEffectManager : IEffectManager
  4. {
  5. public const string Header = "EFFECT_FOG";
  6. private readonly float initialDistance = 4f;
  7. private readonly float initialDensity = 1f;
  8. private readonly float initialHeightScale = 1f;
  9. private readonly float initialHeight = 0f;
  10. private readonly Color initialColour = Color.white;
  11. private float distance;
  12. private float density;
  13. private float heightScale;
  14. private float height;
  15. private Color fogColour;
  16. public bool Ready { get; private set; }
  17. public bool Active { get; private set; }
  18. public float Distance
  19. {
  20. get => distance;
  21. set => distance = Fog.startDistance = value;
  22. }
  23. public float Density
  24. {
  25. get => density;
  26. set => density = Fog.globalDensity = value;
  27. }
  28. public float HeightScale
  29. {
  30. get => heightScale;
  31. set => heightScale = Fog.heightScale = value;
  32. }
  33. public float Height
  34. {
  35. get => height;
  36. set => height = Fog.height = value;
  37. }
  38. public float FogColourRed
  39. {
  40. get => FogColour.r;
  41. set
  42. {
  43. var fogColour = FogColour;
  44. FogColour = new(value, fogColour.g, fogColour.b);
  45. }
  46. }
  47. public float FogColourGreen
  48. {
  49. get => FogColour.g;
  50. set
  51. {
  52. var fogColour = FogColour;
  53. FogColour = new(fogColour.r, value, fogColour.b);
  54. }
  55. }
  56. public float FogColourBlue
  57. {
  58. get => FogColour.b;
  59. set
  60. {
  61. var fogColour = FogColour;
  62. FogColour = new(fogColour.r, fogColour.g, value);
  63. }
  64. }
  65. public Color FogColour
  66. {
  67. get => fogColour;
  68. set => fogColour = Fog.globalFogColor = value;
  69. }
  70. private GlobalFog Fog { get; set; }
  71. public void Activate()
  72. {
  73. if (!Fog)
  74. {
  75. Ready = true;
  76. Fog = GameMain.Instance.MainCamera.GetOrAddComponent<GlobalFog>();
  77. if (!Fog.fogShader)
  78. 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
  117. {
  118. Reset();
  119. }
  120. }
  121. public void Update()
  122. {
  123. }
  124. }