#if UNITY_EDITOR using UnityEngine; using UnityEditor; using System.Reflection; public class FogVolumeCreator : Editor { [MenuItem("GameObject/Create Other/Fog Volume")] [MenuItem("Fog Volume/Create Fog Volume")] public static void CreateFogVolume() { var FogVolume = new GameObject(); //Icon stuff var Icon = Resources.Load("FogVolumeIcon") as Texture; //Icon.hideFlags = HideFlags.HideAndDontSave; var editorGUI = typeof(EditorGUIUtility); var bindingFlags = BindingFlags.InvokeMethod | BindingFlags.Static | BindingFlags.NonPublic; var args = new object[] { FogVolume, Icon }; editorGUI.InvokeMember("SetIconForObject", bindingFlags, null, null, args); FogVolume.name = "Fog Volume"; FogVolume.AddComponent(); FogVolume.AddComponent(); FogVolume.GetComponent().shadowCastingMode = UnityEngine.Rendering.ShadowCastingMode.Off; FogVolume.GetComponent().receiveShadows = false; FogVolume.GetComponent().reflectionProbeUsage = UnityEngine.Rendering.ReflectionProbeUsage.Off; FogVolume.GetComponent().lightProbeUsage = UnityEngine.Rendering.LightProbeUsage.Off; Selection.activeObject = FogVolume; if (SceneView.currentDrawingSceneView) { SceneView.currentDrawingSceneView.MoveToView(FogVolume.transform); } } //============================================================================================= // L I G H T S //============================================================================================= [MenuItem("GameObject/Create Other/Fog Volume Light/Fog Volume Point Light")] [MenuItem("Fog Volume/Create Light/Fog Volume Point Light")] public static void CreateFogVolumePointLight() { var fogVolumeLight = new GameObject("FogVolumePointLight"); var light = fogVolumeLight.AddComponent(); light.IsPointLight = true; light.IsAddedToNormalLight = false; } [MenuItem("GameObject/Create Other/Fog Volume Light/Fog Volume Spot Light")] [MenuItem("Fog Volume/Create Light/Fog Volume Spot Light")] public static void CreateFogVolumeSpotLight() { var fogVolumeLight = new GameObject("FogVolumeSpotLight"); var light = fogVolumeLight.AddComponent(); light.IsPointLight = false; light.IsAddedToNormalLight = false; } [MenuItem("Fog Volume/Create Light/Fog Volume Directional Light")] public static void AutoCreateFogVolumeDirectionalLight() { var lights = FindObjectsOfType(); for (var i = 0; i < lights.Length; i++) { var light = lights[i]; if (light.type == LightType.Directional) { if (light.GetComponent() == null) { var dirLight = light.gameObject.AddComponent(); var fogVolumes = FindObjectsOfType(); dirLight._TargetFogVolumes = new FogVolume[fogVolumes.Length]; for (var k = 0; k < fogVolumes.Length; k++) { dirLight._TargetFogVolumes[k] = fogVolumes[k]; } } } } } [MenuItem("Fog Volume/Create Light/Fog Volume Directional Light", true)] public static bool EnableCreateFogVolumeDirectionalLight() { return FindObjectOfType() == null && FindObjectOfType() != null; } [MenuItem("GameObject/Create Other/Fog Volume Light/Normal Point Light")] [MenuItem("Fog Volume/Create Light/Normal Point Light")] public static void CreateNormalPointLight() { var normalPointLight = new GameObject("Point light"); var light = normalPointLight.AddComponent(); light.type = LightType.Point; var fvLight = normalPointLight.AddComponent(); fvLight.IsPointLight = true; fvLight.IsAddedToNormalLight = true; } [MenuItem("GameObject/Create Other/Fog Volume Light/Normal Spot Light")] [MenuItem("Fog Volume/Create Light/Normal Spot Light")] public static void CreateNormalSpotLight() { var normalPointLight = new GameObject("Spot light"); var light = normalPointLight.AddComponent(); light.type = LightType.Spot; var fvLight = normalPointLight.AddComponent(); fvLight.IsPointLight = false; fvLight.IsAddedToNormalLight = true; } //============================================================================================= // P R I M I T I V E S //============================================================================================= [MenuItem("Fog Volume/Create Primitive/Fog Volume Primitive Box")] [MenuItem("GameObject/Create Other/Fog Volume Primitive/Box")] static public void CreateFogVolumePrimitiveBox() { GameObject FogVolumePrimitive = GameObject.CreatePrimitive(PrimitiveType.Cube); //Icon stuff //Texture Icon = Resources.Load("FogVolumePrimitiveIcon") as Texture; //Icon.hideFlags = HideFlags.HideAndDontSave; // var editorGUI = typeof(EditorGUIUtility); // var bindingFlags = BindingFlags.InvokeMethod | BindingFlags.Static | BindingFlags.NonPublic; //var args = new object[] { FogVolumePrimitive, Icon }; //editorGUI.InvokeMember("SetIconForObject", bindingFlags, null, null, args); FogVolumePrimitive.name = "Fog Volume Primitive Box"; FogVolumePrimitive.GetComponent().isTrigger = true; FogVolumePrimitive.GetComponent().shadowCastingMode = UnityEngine.Rendering.ShadowCastingMode.Off; FogVolumePrimitive.GetComponent().receiveShadows = false; FogVolumePrimitive.GetComponent().reflectionProbeUsage = UnityEngine.Rendering.ReflectionProbeUsage.Off; FogVolumePrimitive.GetComponent().lightProbeUsage = UnityEngine.Rendering.LightProbeUsage.Off; Selection.activeObject = FogVolumePrimitive; if (UnityEditor.SceneView.currentDrawingSceneView) UnityEditor.SceneView.currentDrawingSceneView.MoveToView(FogVolumePrimitive.transform); FogVolumePrimitive.AddComponent(); } [MenuItem("Fog Volume/Create Primitive/Fog Volume Primitive Sphere")] [MenuItem("GameObject/Create Other/Fog Volume Primitive/Sphere")] static public void CreateFogVolumePrimitiveSphere() { GameObject FogVolumePrimitive = GameObject.CreatePrimitive(PrimitiveType.Sphere); //Icon stuff //Texture Icon = Resources.Load("FogVolumePrimitiveIcon") as Texture; //Icon.hideFlags = HideFlags.HideAndDontSave; // var editorGUI = typeof(EditorGUIUtility); // var bindingFlags = BindingFlags.InvokeMethod | BindingFlags.Static | BindingFlags.NonPublic; //var args = new object[] { FogVolumePrimitive, Icon }; //editorGUI.InvokeMember("SetIconForObject", bindingFlags, null, null, args); FogVolumePrimitive.name = "Fog Volume Primitive Sphere"; FogVolumePrimitive.GetComponent().isTrigger = true; FogVolumePrimitive.GetComponent().shadowCastingMode = UnityEngine.Rendering.ShadowCastingMode.Off; FogVolumePrimitive.GetComponent().receiveShadows = false; FogVolumePrimitive.GetComponent().reflectionProbeUsage = UnityEngine.Rendering.ReflectionProbeUsage.Off; FogVolumePrimitive.GetComponent().lightProbeUsage = UnityEngine.Rendering.LightProbeUsage.Off; Selection.activeObject = FogVolumePrimitive; if (UnityEditor.SceneView.currentDrawingSceneView) UnityEditor.SceneView.currentDrawingSceneView.MoveToView(FogVolumePrimitive.transform); FogVolumePrimitive.AddComponent(); } } #endif