FogVolumeExtensions.cs 1.1 KB

1234567891011121314151617181920212223242526272829303132
  1. using UnityEngine;
  2. using UnityEditor;
  3. using System.Collections;
  4. namespace VolumetricFogAndMist {
  5. public class FogVolumeExtensions : MonoBehaviour {
  6. [MenuItem("GameObject/Create Other/Volumetric Fog Volume")]
  7. static void CreateFogVolume (MenuCommand menuCommand) {
  8. GameObject fogVolume = Resources.Load<GameObject> ("Prefabs/FogVolume");
  9. if (fogVolume == null) {
  10. Debug.LogError ("Could not load FogVolume from Resources/Prefabs folder!");
  11. return;
  12. }
  13. GameObject newFogVolume = Instantiate (fogVolume);
  14. newFogVolume.name = "Volumetric Fog Volume";
  15. // Ensure it gets reparented if this was a context click (otherwise does nothing)
  16. GameObjectUtility.SetParentAndAlign (newFogVolume, menuCommand.context as GameObject);
  17. // Register root object for undo.
  18. Undo.RegisterCreatedObjectUndo (newFogVolume, "Create Volumetric Fog Volume");
  19. Selection.activeObject = newFogVolume;
  20. // Enables fog volumes in fog component
  21. VolumetricFog fog = Camera.main.GetComponent<VolumetricFog> ();
  22. if (fog != null)
  23. fog.useFogVolumes = true;
  24. }
  25. }
  26. }