FogEffectManager.cs 3.7 KB

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