VolumetricFogGaiaExtension.cs 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172
  1. #if GAIA_PRESENT && UNITY_EDITOR
  2. using UnityEngine;
  3. using System.Collections;
  4. using System;
  5. using System.Reflection;
  6. using VolumetricFogAndMist;
  7. using UnityEditor;
  8. namespace Gaia.GX.Kronnect
  9. {
  10. /// <summary>
  11. /// Volumetric Fog & Mist extension for Gaia.
  12. /// </summary>
  13. public class VolumetricFogGaiaExtension : MonoBehaviour
  14. {
  15. #region Generic informational methods
  16. /// <summary>
  17. /// Returns the publisher name if provided.
  18. /// This will override the publisher name in the namespace ie Gaia.GX.PublisherName
  19. /// </summary>
  20. /// <returns>Publisher name</returns>
  21. public static string GetPublisherName()
  22. {
  23. return "Kronnect";
  24. }
  25. /// <summary>
  26. /// Returns the package name if provided
  27. /// This will override the package name in the class name ie public class PackageName.
  28. /// </summary>
  29. /// <returns>Package name</returns>
  30. public static string GetPackageName()
  31. {
  32. return "Volumetric Fog & Mist";
  33. }
  34. #endregion
  35. #region Methods exposed by Gaia as buttons must be prefixed with GX_
  36. public static void GX_About()
  37. {
  38. EditorUtility.DisplayDialog("About Volumetric Fog & Mist", "Volumetric Fog & Mist is a full-screen image effect that adds realistic, live, moving fog, mist, dust, clouds and sky haze to your scenes making them less dull and boring.", "OK");
  39. }
  40. static VolumetricFog CheckFog() {
  41. VolumetricFog fog = VolumetricFog.instance;
  42. // Checks Volumetric Fog image effect is attached
  43. if (fog==null) {
  44. Camera camera = Camera.main;
  45. if (camera == null)
  46. {
  47. camera = FindObjectOfType<Camera>();
  48. }
  49. if (camera == null)
  50. {
  51. Debug.LogError("Could not find camera to add camera effects to. Please add a camera to your scene.");
  52. return null;
  53. }
  54. fog = camera.gameObject.AddComponent<VolumetricFog>();
  55. }
  56. // Finds a suitable Sun light
  57. if (fog.sun==null) {
  58. Light[] lights = FindObjectsOfType<Light>();
  59. for (int k=0;k<lights.Length;k++) {
  60. Light light = lights[k];
  61. if (light.name.Equals("Sun")) {
  62. fog.sun = light.gameObject;
  63. break;
  64. }
  65. }
  66. if (fog.sun==null) {
  67. for (int k=0;k<lights.Length;k++) {
  68. Light light = lights[k];
  69. if (light.type == LightType.Directional) {
  70. fog.sun = light.gameObject;
  71. break;
  72. }
  73. }
  74. }
  75. }
  76. return fog;
  77. }
  78. public static void GX_WorldEdge() {
  79. VolumetricFog fog = CheckFog();
  80. if (fog==null) return;
  81. fog.preset = FOG_PRESET.WorldEdge;
  82. fog.preset = FOG_PRESET.Custom; // enable to make modifications and preserve them
  83. }
  84. public static void GX_WindyMist() {
  85. VolumetricFog fog = CheckFog();
  86. if (fog==null) return;
  87. fog.preset = FOG_PRESET.WindyMist;
  88. fog.preset = FOG_PRESET.Custom; // enable to make modifications and preserve them
  89. }
  90. public static void GX_SeaOfClouds() {
  91. VolumetricFog fog = CheckFog();
  92. if (fog==null) return;
  93. fog.preset = FOG_PRESET.SeaClouds;
  94. fog.preset = FOG_PRESET.Custom; // enable to make modifications and preserve them
  95. }
  96. public static void GX_Fog() {
  97. VolumetricFog fog = CheckFog();
  98. if (fog==null) return;
  99. fog.preset = FOG_PRESET.Fog;
  100. fog.preset = FOG_PRESET.Custom; // enable to make modifications and preserve them
  101. }
  102. public static void GX_HeavyFog() {
  103. VolumetricFog fog = CheckFog();
  104. if (fog==null) return;
  105. fog.preset = FOG_PRESET.HeavyFog;
  106. fog.preset = FOG_PRESET.Custom; // enable to make modifications and preserve them
  107. }
  108. public static void GX_FrostedWater() {
  109. VolumetricFog fog = CheckFog();
  110. if (fog==null) return;
  111. fog.preset = FOG_PRESET.FrostedGround;
  112. fog.preset = FOG_PRESET.Custom; // enable to make modifications and preserve them
  113. fog.color = Color.white;
  114. fog.height = 1.5f;
  115. }
  116. public static void GX_GroundFog() {
  117. VolumetricFog fog = CheckFog();
  118. if (fog==null) return;
  119. fog.preset = FOG_PRESET.GroundFog;
  120. fog.preset = FOG_PRESET.Custom; // enable to make modifications and preserve them
  121. }
  122. public static void GX_ToxicSwamps() {
  123. VolumetricFog fog = CheckFog();
  124. if (fog==null) return;
  125. fog.preset = FOG_PRESET.ToxicSwamp;
  126. fog.preset = FOG_PRESET.Custom; // enable to make modifications and preserve them
  127. }
  128. public static void GX_FoggyLakes() {
  129. VolumetricFog fog = CheckFog();
  130. if (fog==null) return;
  131. fog.preset = FOG_PRESET.FoggyLake;
  132. fog.preset = FOG_PRESET.Custom; // enable to make modifications and preserve them
  133. }
  134. public static void GX_SandStorm1() {
  135. VolumetricFog fog = CheckFog();
  136. if (fog==null) return;
  137. fog.preset = FOG_PRESET.SandStorm1;
  138. fog.preset = FOG_PRESET.Custom; // enable to make modifications and preserve them
  139. }
  140. public static void GX_SandStorm2() {
  141. VolumetricFog fog = CheckFog();
  142. if (fog==null) return;
  143. fog.preset = FOG_PRESET.SandStorm2;
  144. fog.preset = FOG_PRESET.Custom; // enable to make modifications and preserve them
  145. }
  146. #endregion
  147. }
  148. }
  149. #endif