fxvVolumeFogEditor.cs 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268
  1. using System.Linq;
  2. using UnityEditor;
  3. using UnityEditor.SceneManagement;
  4. using UnityEngine;
  5. namespace FXV
  6. {
  7. [CanEditMultipleObjects]
  8. [CustomEditor(typeof(VolumeFog))]
  9. public class fxvVolumeFogEditor : UnityEditor.Editor
  10. {
  11. [MenuItem("GameObject/FXV/Fog - Spherical", false, 0)]
  12. internal static void CreateSphericalFog(MenuCommand menuCommand)
  13. {
  14. GameObject selected = Selection.activeObject as GameObject;
  15. GameObject go = new GameObject("SphericalFog");
  16. go.AddComponent<MeshFilter>();
  17. go.AddComponent<MeshRenderer>();
  18. VolumeFog fog = go.AddComponent<VolumeFog>();
  19. fog.FogMax = 1.0f;
  20. VolumeFog.SetFogType(fog, VolumeFog.FogType.SphericalPos);
  21. GameObjectUtility.SetParentAndAlign(go, selected);
  22. Undo.RegisterCreatedObjectUndo(go, "Created Fog " + go.name);
  23. }
  24. [MenuItem("GameObject/FXV/Fog - Height", false, 0)]
  25. internal static void CreateHeightFog(MenuCommand menuCommand)
  26. {
  27. GameObject selected = Selection.activeObject as GameObject;
  28. GameObject go = new GameObject("HeightFog");
  29. go.AddComponent<MeshFilter>();
  30. go.AddComponent<MeshRenderer>();
  31. VolumeFog fog = go.AddComponent<VolumeFog>();
  32. fog.SetFogBoxSize(new Vector3(10.0f, 1.0f, 10.0f));
  33. fog.FogMax = 1.0f;
  34. VolumeFog.SetFogType(fog, VolumeFog.FogType.Height);
  35. GameObjectUtility.SetParentAndAlign(go, selected);
  36. Undo.RegisterCreatedObjectUndo(go, "Created Fog " + go.name);
  37. }
  38. [MenuItem("GameObject/FXV/Fog - Box", false, 0)]
  39. internal static void CreateBoxFog(MenuCommand menuCommand)
  40. {
  41. GameObject selected = Selection.activeObject as GameObject;
  42. GameObject go = new GameObject("BoxFog");
  43. go.AddComponent<MeshFilter>();
  44. go.AddComponent<MeshRenderer>();
  45. VolumeFog fog = go.AddComponent<VolumeFog>();
  46. fog.SetFogBoxSize(new Vector3(1.0f, 1.0f, 1.0f));
  47. fog.FogMax = 0.5f;
  48. VolumeFog.SetFogType(fog, VolumeFog.FogType.BoxDist);
  49. GameObjectUtility.SetParentAndAlign(go, selected);
  50. Undo.RegisterCreatedObjectUndo(go, "Created Fog " + go.name);
  51. }
  52. [MenuItem("GameObject/FXV/Fog - View Aligned", false, 0)]
  53. internal static void CreateBasicFog(MenuCommand menuCommand)
  54. {
  55. GameObject selected = Selection.activeObject as GameObject;
  56. GameObject go = new GameObject("ViewAlignedFog");
  57. go.AddComponent<MeshFilter>();
  58. go.AddComponent<MeshRenderer>();
  59. VolumeFog fog = go.AddComponent<VolumeFog>();
  60. fog.SetFogBoxSize(new Vector3(1.0f, 1.0f, 1.0f));
  61. VolumeFog.SetFogType(fog, VolumeFog.FogType.ViewAligned);
  62. GameObjectUtility.SetParentAndAlign(go, selected);
  63. Undo.RegisterCreatedObjectUndo(go, "Created Fog " + go.name);
  64. }
  65. public static int DrawSortingLayersPopup(int layerID)
  66. {
  67. var layers = SortingLayer.layers;
  68. var names = layers.Select(l => l.name).ToArray();
  69. if (!SortingLayer.IsValid(layerID))
  70. {
  71. layerID = layers[0].id;
  72. }
  73. var layerValue = SortingLayer.GetLayerValueFromID(layerID);
  74. var newLayerValue = EditorGUILayout.Popup("Sorting Layer", layerValue, names);
  75. return layers[newLayerValue].id;
  76. }
  77. public override void OnInspectorGUI()
  78. {
  79. GUIStyle wrapLabel = new GUIStyle(EditorStyles.boldLabel);
  80. wrapLabel.wordWrap = true;
  81. GUIStyle wrapLabelRed = new GUIStyle(EditorStyles.boldLabel);
  82. wrapLabelRed.wordWrap = true;
  83. wrapLabelRed.normal.textColor = new Color(0.8f, 0.2f, 0.0f);
  84. GUIStyle groupControlledLabel = new GUIStyle(EditorStyles.label);
  85. groupControlledLabel.wordWrap = true;
  86. groupControlledLabel.normal.textColor = new Color(0.7f, 0.7f, 0.7f);
  87. VolumeFog fogObject = (VolumeFog)target;
  88. VolumeFogGroup fogGroup = fogObject.GetParentFogGroup();
  89. for (int i = 0; i < targets.Length; i++)
  90. {
  91. VolumeFog.SetupFogMaterial((VolumeFog)targets[i]);
  92. }
  93. EditorGUILayout.Separator();
  94. GUILayout.Label("Fog Properties: ", EditorStyles.boldLabel);
  95. VolumeFog.FogType oldType = fogObject.GetFogType();
  96. EditorGUILayout.PropertyField(serializedObject.FindProperty("fogType"));
  97. if (fogObject.IsUsingSecondaryParams())
  98. {
  99. string[] names = fogObject.GetFogType().ToString().Split('X');
  100. string prefix1 = "[" + names[0] + "] ";
  101. string prefix2 = "[" + names[1] + "] ";
  102. if (fogObject.IsUsingDepthWorkflow())
  103. {
  104. EditorGUILayout.PropertyField(serializedObject.FindProperty("fogMax"), new GUIContent(prefix1 + "Fog Max"));
  105. EditorGUILayout.PropertyField(serializedObject.FindProperty("_fogDepth"), new GUIContent(prefix1 + "Fog Depth"));
  106. }
  107. else
  108. {
  109. EditorGUILayout.PropertyField(serializedObject.FindProperty("fogMin"), new GUIContent(prefix1 + "Fog Min"));
  110. EditorGUILayout.PropertyField(serializedObject.FindProperty("fogMax"), new GUIContent(prefix1 + "Fog Max"));
  111. }
  112. EditorGUILayout.PropertyField(serializedObject.FindProperty("secFogMin"), new GUIContent(prefix2 + "Fog Min"));
  113. EditorGUILayout.PropertyField(serializedObject.FindProperty("secFogMax"), new GUIContent(prefix2 + "Fog Max"));
  114. }
  115. else
  116. {
  117. if (fogObject.IsUsingDepthWorkflow())
  118. {
  119. EditorGUILayout.PropertyField(serializedObject.FindProperty("fogMax"));
  120. EditorGUILayout.PropertyField(serializedObject.FindProperty("_fogDepth"));
  121. }
  122. else
  123. {
  124. EditorGUILayout.PropertyField(serializedObject.FindProperty("fogMin"));
  125. EditorGUILayout.PropertyField(serializedObject.FindProperty("fogMax"));
  126. }
  127. }
  128. EditorGUILayout.PropertyField(serializedObject.FindProperty("blendType"));
  129. EditorGUILayout.PropertyField(serializedObject.FindProperty("fogMeshType"));
  130. if (fogObject.IsCustomMesh())
  131. {
  132. EditorGUILayout.PropertyField(serializedObject.FindProperty("customMesh"));
  133. }
  134. else
  135. {
  136. if (fogObject.IsBoxShape())
  137. {
  138. EditorGUILayout.PropertyField(serializedObject.FindProperty("worldSize"), new GUIContent("Fog Box Size"));
  139. }
  140. }
  141. if (fogGroup && fogGroup.IsControllingColor())
  142. {
  143. GUILayout.Label(" - Color controlled by parent group.", groupControlledLabel);
  144. }
  145. EditorGUILayout.PropertyField(serializedObject.FindProperty("fogColor"));
  146. EditorGUILayout.PropertyField(serializedObject.FindProperty("fogFalloffType"), new GUIContent("Fog Falloff Type"));
  147. if (fogGroup && fogGroup.IsControllingFalloffParam())
  148. {
  149. GUILayout.Label(" - Falloff param is multiplied by parent group.", groupControlledLabel);
  150. }
  151. EditorGUILayout.PropertyField(serializedObject.FindProperty("fogFalloffCurve"), new GUIContent("Fog Falloff Param"));
  152. EditorGUILayout.PropertyField(serializedObject.FindProperty("fogClipping"), new GUIContent("Fog Clipping Mode"));
  153. {
  154. EditorGUILayout.Separator();
  155. GUILayout.Label("Default render mode will fit all camera scenarios, while Simplified is faster but will not render properly from every camera view", wrapLabel);
  156. EditorGUILayout.PropertyField(serializedObject.FindProperty("renderMode"), new GUIContent("Fog Render Mode"));
  157. }
  158. EditorGUILayout.Separator();
  159. GUILayout.Label("Switch between Lit/Unlit version. ", wrapLabel);
  160. if (fogGroup && fogGroup.IsControllingLighting())
  161. {
  162. GUILayout.Label(" - Lighting params controlled by parent group.", groupControlledLabel);
  163. }
  164. else
  165. {
  166. EditorGUILayout.PropertyField(serializedObject.FindProperty("affectedByLights"));
  167. if (fogObject.IsAffectedByLights())
  168. {
  169. EditorGUILayout.PropertyField(serializedObject.FindProperty("lightScatteringFactor"));
  170. EditorGUILayout.PropertyField(serializedObject.FindProperty("lightReflectivity"));
  171. EditorGUILayout.PropertyField(serializedObject.FindProperty("lightTransmission"));
  172. }
  173. }
  174. EditorGUILayout.Separator();
  175. GUILayout.Label("Rendering properties. ", wrapLabel);
  176. EditorGUILayout.PropertyField(serializedObject.FindProperty("sortingLayer"));
  177. EditorGUILayout.PropertyField(serializedObject.FindProperty("sortingOrder"));
  178. // GUILayout.Label("Render fog after transparent objects (> 3000): ", wrapLabel);
  179. // fogObject.renderQueue = EditorGUILayout.IntField("Render Queue", fogObject.renderQueue);
  180. if (GUI.changed || oldType != fogObject.GetFogType())
  181. {
  182. serializedObject.ApplyModifiedProperties();
  183. EditorUtility.SetDirty(fogObject);
  184. if (!Application.isPlaying)
  185. {
  186. EditorSceneManager.MarkSceneDirty(fogObject.gameObject.scene);
  187. var prefabStage = PrefabStageUtility.GetCurrentPrefabStage();
  188. if (prefabStage != null)
  189. {
  190. EditorSceneManager.MarkSceneDirty(prefabStage.scene);
  191. }
  192. }
  193. }
  194. }
  195. }
  196. }