static DynamicFog CheckFog() { DynamicFog fog = DynamicFog.instance; // Checks Dynamic Fog image effect is attached if (fog == null) { Camera camera = Camera.main; if (camera == null) { camera = FindObjectOfType <Camera>(); } if (camera == null) { Debug.LogError("Could not find camera to add camera effects to. Please add a camera to your scene."); return(null); } fog = camera.gameObject.AddComponent <DynamicFog>(); } // set nice default params fog.height = 20; fog.distanceFallOff = 0.4f; // Finds a suitable Sun light and set color1 to it Light[] lights = FindObjectsOfType <Light>(); Light sun = null; for (int k = 0; k < lights.Length; k++) { Light light = lights[k]; if (light.name.Equals("Sun")) { sun = light; break; } } if (sun == null) { for (int k = 0; k < lights.Length; k++) { Light light = lights[k]; if (light.type == LightType.Directional) { sun = light; break; } } } if (sun != null) { fog.color = sun.color; } // Set fog base-line height to water level GaiaSceneInfo sceneInfo = GaiaSceneInfo.GetSceneInfo(); fog.baselineHeight = sceneInfo.m_seaLevel; return(fog); }
public static void GX_Volumes_GlobalAnisotropyNoise() { GaiaSceneInfo gaiaSceneInfo = GaiaSceneInfo.GetSceneInfo(); GameObject globalVolumeObject = AuraVolume.CreateGameObject("Aura Global Volume", VolumeTypeEnum.Global); globalVolumeObject.transform.position = gaiaSceneInfo.m_centrePointOnTerrain; AuraVolume globalVolume = globalVolumeObject.GetComponent <AuraVolume>(); SetupVolumeDefaultNoise(globalVolume); globalVolume.density.injectionParameters.enable = false; globalVolume.color.injectionParameters.enable = false; SetupVolumeDefaultAnisotropy(globalVolume); }
//<summary> //Opens AQUAS's Setup Wizard //</summary> public static void GX_OpenSetupWizard() { //Get scene info GaiaSceneInfo sceneInfo = GaiaSceneInfo.GetSceneInfo(); //Find camera Camera camera = Camera.main; if (camera == null) { camera = FindObjectOfType <Camera>(); } float waterLevel = sceneInfo.m_seaLevel; AQUAS_SetupWizard setup = (AQUAS_SetupWizard)EditorWindow.GetWindow(typeof(AQUAS_SetupWizard), false); setup.camera = camera.transform.gameObject; setup.waterLevel = waterLevel; setup.Show(); }
//<summary> //Adds AQUAS to the Scene //</summary> public static void GX_AddAquas() { //Get scene info GaiaSceneInfo sceneInfo = GaiaSceneInfo.GetSceneInfo(); //Find camera Camera camera = Camera.main; if (camera == null) { camera = FindObjectOfType <Camera>(); } //Add the AQUAS prefab to the scene //Check if AQUAS is imported GameObject aquasPrefab = Gaia.Utils.GetAssetPrefab("AQUASWater"); if (aquasPrefab == null) { EditorUtility.DisplayDialog("Unable to locate AQUAS", "Unable to locate AQUAS - Aborting", "Ok"); return; } //Check if AQUAS is already in the scene if (GameObject.Find("AQUAS Waterplane") != null) { EditorUtility.DisplayDialog("Can't add water", "AQUAS is already in the scene", "Ok"); return; } //Try to add AQUAS GameObject aquasObj = Instantiate(aquasPrefab); if (aquasObj == null) { EditorUtility.DisplayDialog("Can't add water", "Unable to create AQUAS object", "Ok"); return; } //Position the waterplane correctly else { aquasObj.name = "AQUAS Waterplane"; aquasObj.transform.position = new Vector3(sceneInfo.m_centrePointOnTerrain.x, sceneInfo.m_seaLevel, sceneInfo.m_centrePointOnTerrain.z); aquasObj.transform.localScale = sceneInfo.m_sceneBounds.extents * 150; if (camera.gameObject.GetComponent <AQUAS_Camera>() == null) { camera.gameObject.AddComponent <AQUAS_Camera>(); } //Check if Tenkoku is in the scene if (GameObject.Find("Tenkoku DynamicSky") != null) { } else { GameObject refProbe = new GameObject("Reflection Probe"); refProbe.transform.position = new Vector3(sceneInfo.m_centrePointOnTerrain.x, sceneInfo.m_seaLevel, sceneInfo.m_centrePointOnTerrain.z); refProbe.AddComponent <ReflectionProbe>(); refProbe.GetComponent <ReflectionProbe>().intensity = 0.3f; refProbe.transform.SetParent(aquasObj.transform); refProbe.GetComponent <ReflectionProbe>().mode = UnityEngine.Rendering.ReflectionProbeMode.Realtime; } //Add caustics GameObject primaryCausticsPrefab = Gaia.Utils.GetAssetPrefab("PrimaryCausticsProjector"); GameObject primaryCausticsObj = Instantiate(primaryCausticsPrefab); primaryCausticsObj.name = "PrimaryCausticsProjector"; GameObject secondaryCausticsPrefab = Gaia.Utils.GetAssetPrefab("SecondaryCausticsProjector"); GameObject secondaryCausticsObj = Instantiate(secondaryCausticsPrefab); secondaryCausticsObj.name = "SecondaryCausticsProjector"; primaryCausticsObj.transform.position = new Vector3(sceneInfo.m_centrePointOnTerrain.x, sceneInfo.m_seaLevel, sceneInfo.m_centrePointOnTerrain.z); secondaryCausticsObj.transform.position = new Vector3(sceneInfo.m_centrePointOnTerrain.x, sceneInfo.m_seaLevel, sceneInfo.m_centrePointOnTerrain.z); primaryCausticsObj.GetComponent <Projector>().orthographicSize = sceneInfo.m_sceneBounds.extents.x; secondaryCausticsObj.GetComponent <Projector>().orthographicSize = sceneInfo.m_sceneBounds.extents.x; primaryCausticsObj.transform.SetParent(aquasObj.transform); secondaryCausticsObj.transform.SetParent(aquasObj.transform); //Set some material parameters based on whether Tenkoku is in the scene or not if (GameObject.Find("Tenkoku DynamicSky") != null) { aquasObj.GetComponent <Renderer>().sharedMaterial.SetFloat("_EnableCustomFog", 1); aquasObj.GetComponent <Renderer>().sharedMaterial.SetFloat("_Specular", 0.5f); } else { aquasObj.GetComponent <Renderer>().sharedMaterial.SetFloat("_EnableCustomFog", 0); aquasObj.GetComponent <Renderer>().sharedMaterial.SetFloat("_Specular", 1); } } }
//<summary> //Adds Underwater Effects to the scene //</summary> public static void GX_AddUnderwaterEffects() { //Collect Scene info GaiaSceneInfo sceneInfo = GaiaSceneInfo.GetSceneInfo(); GameObject underwaterPrefab = Gaia.Utils.GetAssetPrefab("UnderWaterCameraEffects"); //Check if AQUAS is already in the scene if (GameObject.Find("AQUAS Waterplane") == null) { EditorUtility.DisplayDialog("AQUAS is not in the scene", "Please add water first", "Ok"); return; } //Try to add underwater effects else { if (GameObject.Find("UnderWaterCameraEffects") != null) { EditorUtility.DisplayDialog("Can't add underwater effects", "Underwater Effects are already in the scene", "Ok"); return; } GameObject underwaterObj = Instantiate(underwaterPrefab); underwaterObj.name = "UnderWaterCameraEffects"; //Find camera Camera camera = Camera.main; if (camera == null) { camera = FindObjectOfType <Camera>(); } camera.farClipPlane = sceneInfo.m_sceneBounds.extents.x * 2; //Underwater effects setup underwaterObj.transform.SetParent(camera.transform); underwaterObj.transform.localPosition = new Vector3(0, 0, 0); underwaterObj.transform.localEulerAngles = new Vector3(0, 0, 0); underwaterObj.GetComponent <AQUAS_LensEffects>().gameObjects.mainCamera = camera.gameObject; underwaterObj.GetComponent <AQUAS_LensEffects>().gameObjects.waterPlanes[0] = GameObject.Find("AQUAS Waterplane"); if (GameObject.Find("AQUAS Waterplane").GetComponent <MeshFilter>().sharedMesh.name == "Plane" || GameObject.Find("AQUAS Waterplane").GetComponent <MeshFilter>().sharedMesh.name == "Plane Instance") { underwaterObj.GetComponent <AQUAS_LensEffects>().gameObjects.useSquaredPlanes = true; } else { underwaterObj.GetComponent <AQUAS_LensEffects>().gameObjects.useSquaredPlanes = false; } //Add and configure image effects neccessary for AQUAS if (camera.gameObject.GetComponent <PostProcessingBehaviour>() == null) { camera.gameObject.AddComponent <PostProcessingBehaviour>(); } if (camera.gameObject.GetComponent <AudioSource>() == null) { camera.gameObject.AddComponent <AudioSource>(); } //Add borders to the scene for correct fog if (GameObject.Find("Borders") != null) { return; } GameObject borders = new GameObject(); borders.name = "Borders"; GameObject borderLeft = GameObject.CreatePrimitive(PrimitiveType.Cube); borderLeft.name = "Left Border"; borderLeft.transform.localScale = new Vector3(sceneInfo.m_sceneBounds.extents.x * 2, sceneInfo.m_seaLevel, 0.1f); borderLeft.transform.position = new Vector3(sceneInfo.m_sceneBounds.center.x, sceneInfo.m_seaLevel - (sceneInfo.m_seaLevel / 2), sceneInfo.m_sceneBounds.extents.z); GameObject borderRight = GameObject.CreatePrimitive(PrimitiveType.Cube); borderRight.name = "Right Border"; borderRight.transform.localScale = new Vector3(sceneInfo.m_sceneBounds.extents.x * 2, sceneInfo.m_seaLevel, 0.1f); borderRight.transform.position = new Vector3(sceneInfo.m_sceneBounds.center.x, sceneInfo.m_seaLevel - (sceneInfo.m_seaLevel / 2), -sceneInfo.m_sceneBounds.extents.z); GameObject borderTop = GameObject.CreatePrimitive(PrimitiveType.Cube); borderTop.name = "Top Border"; borderTop.transform.localScale = new Vector3(0.1f, sceneInfo.m_seaLevel, sceneInfo.m_sceneBounds.extents.z * 2); borderTop.transform.position = new Vector3(sceneInfo.m_sceneBounds.extents.x, sceneInfo.m_seaLevel - (sceneInfo.m_seaLevel / 2), sceneInfo.m_sceneBounds.center.z); GameObject borderBottom = GameObject.CreatePrimitive(PrimitiveType.Cube); borderBottom.name = "Bottom Border"; borderBottom.transform.localScale = new Vector3(0.1f, sceneInfo.m_seaLevel, sceneInfo.m_sceneBounds.extents.z * 2); borderBottom.transform.position = new Vector3(-sceneInfo.m_sceneBounds.extents.x, sceneInfo.m_seaLevel - (sceneInfo.m_seaLevel / 2), -sceneInfo.m_sceneBounds.center.z); borderLeft.transform.SetParent(borders.transform); borderRight.transform.SetParent(borders.transform); borderTop.transform.SetParent(borders.transform); borderBottom.transform.SetParent(borders.transform); borders.transform.SetParent(GameObject.Find("AQUAS Waterplane").transform); } }
public static void GX_CreateRiverReference() { //Get scene info GaiaSceneInfo sceneInfo = GaiaSceneInfo.GetSceneInfo(); //Find camera Camera camera = Camera.main; //Check if required objects (camera & river plane) are specified and abort if not if (camera == null) { EditorUtility.DisplayDialog("Camera Missing!", "Please specify the main camera before creating a river reference.", "OK"); return; } if (GameObject.Find("AQUAS Waterplane") == null) { EditorUtility.DisplayDialog("River Plane Missing", "Please add a river plane before creating a river reference.", "OK"); return; } #region Screenshot setup //Cache the camera's parameters Vector3 cameraPosition = camera.transform.position; Quaternion cameraRotation = camera.transform.rotation; bool projection = camera.GetComponent <Camera>().orthographic; float orthographicSize = camera.GetComponent <Camera>().orthographicSize; //Set the camera's position and parameters for taking a screenshot camera.transform.position = new Vector3(sceneInfo.m_centrePointOnTerrain.x, sceneInfo.m_seaLevel + (camera.GetComponent <Camera>().farClipPlane - 50), sceneInfo.m_centrePointOnTerrain.z); camera.transform.rotation = Quaternion.Euler(90, 0, 0); camera.GetComponent <Camera>().orthographic = true; camera.GetComponent <Camera>().orthographicSize = sceneInfo.m_sceneBounds.extents.x; //Cache the material from the river plane and set the material with the reference texture on it Material cachedMaterial = GameObject.Find("AQUAS Waterplane").GetComponent <UnityEngine.Renderer>().sharedMaterial; Material referenceTexMat = (Material)AssetDatabase.LoadAssetAtPath("Assets/AQUAS/Materials/RiverRef.mat", typeof(Material)); GameObject.Find("AQUAS Waterplane").GetComponent <UnityEngine.Renderer>().sharedMaterial = referenceTexMat; #endregion #region Take & save screenshot //Take a screenshot from the river plane and save it to use as a reference texture to help paint flowmaps //Source: http://answers.unity3d.com/questions/22954/how-to-save-a-picture-take-screenshot-from-a-camer.html RenderTexture rt = new RenderTexture(1024, 1024, 24); camera.GetComponent <Camera>().targetTexture = rt; Texture2D riverReference = new Texture2D(1024, 1024, TextureFormat.RGB24, false); camera.GetComponent <Camera>().Render(); RenderTexture.active = rt; riverReference.ReadPixels(new Rect(0, 0, 1024, 1024), 0, 0); camera.GetComponent <Camera>().targetTexture = null; RenderTexture.active = null; DestroyImmediate(rt); byte[] bytes = riverReference.EncodeToJPG(); string filename = string.Format("{0}/RiverReferences/Reference_{1}.jpg", Application.dataPath, System.DateTime.Now.ToString("yyyy-MM-dd-HH-mm-ss")); if (!System.IO.Directory.Exists(string.Format("{0}/RiverReferences", Application.dataPath))) { System.IO.Directory.CreateDirectory(string.Format("{0}/RiverReferences", Application.dataPath)); } System.IO.File.WriteAllBytes(filename, bytes); #endregion #region Revert scene to original state camera.transform.position = cameraPosition; camera.transform.rotation = cameraRotation; camera.GetComponent <Camera>().orthographic = projection; camera.GetComponent <Camera>().orthographicSize = orthographicSize; GameObject.Find("AQUAS Waterplane").GetComponent <UnityEngine.Renderer>().sharedMaterial = cachedMaterial; #endregion AssetDatabase.Refresh(); }
//<summary> //Adds a river plane to the Scene //</summary> public static void GX_AddRiver() { //Get scene info GaiaSceneInfo sceneInfo = GaiaSceneInfo.GetSceneInfo(); //Find camera Camera camera = Camera.main; if (camera == null) { camera = FindObjectOfType <Camera>(); } //Try to add AQUAS river GameObject aquasObj = GameObject.CreatePrimitive(PrimitiveType.Plane); if (aquasObj == null) { EditorUtility.DisplayDialog("Can't add water", "Unable to create AQUAS object", "Ok"); return; } //Position the waterplane correctly else { aquasObj.name = "AQUAS Waterplane"; aquasObj.transform.position = new Vector3(sceneInfo.m_centrePointOnTerrain.x, sceneInfo.m_seaLevel, sceneInfo.m_centrePointOnTerrain.z); aquasObj.transform.localScale = sceneInfo.m_sceneBounds.extents / 5; DestroyImmediate(aquasObj.GetComponent <MeshCollider>()); aquasObj.GetComponent <MeshRenderer>().shadowCastingMode = UnityEngine.Rendering.ShadowCastingMode.Off; aquasObj.GetComponent <Renderer>().material = (Material)AssetDatabase.LoadAssetAtPath("Assets/AQUAS/Materials/Water/Desktop&Web/River.mat", typeof(Material)); aquasObj.AddComponent <AQUAS_Reflection>(); aquasObj.AddComponent <AQUAS_RenderQueueEditor>(); if (camera.gameObject.GetComponent <AQUAS_Camera>() == null) { camera.gameObject.AddComponent <AQUAS_Camera>(); } //Check if Tenkoku is in the scene if (GameObject.Find("Tenkoku DynamicSky") != null) { } else { GameObject refProbe = new GameObject("Reflection Probe"); refProbe.transform.position = new Vector3(sceneInfo.m_centrePointOnTerrain.x, sceneInfo.m_seaLevel, sceneInfo.m_centrePointOnTerrain.z); refProbe.AddComponent <ReflectionProbe>(); refProbe.GetComponent <ReflectionProbe>().intensity = 0.3f; refProbe.transform.SetParent(aquasObj.transform); refProbe.GetComponent <ReflectionProbe>().mode = UnityEngine.Rendering.ReflectionProbeMode.Realtime; } //Add caustics GameObject primaryCausticsPrefab = Gaia.Utils.GetAssetPrefab("PrimaryCausticsProjector"); GameObject primaryCausticsObj = Instantiate(primaryCausticsPrefab); primaryCausticsObj.name = "PrimaryCausticsProjector"; GameObject secondaryCausticsPrefab = Gaia.Utils.GetAssetPrefab("SecondaryCausticsProjector"); GameObject secondaryCausticsObj = Instantiate(secondaryCausticsPrefab); secondaryCausticsObj.name = "SecondaryCausticsProjector"; primaryCausticsObj.transform.position = new Vector3(sceneInfo.m_centrePointOnTerrain.x, sceneInfo.m_seaLevel, sceneInfo.m_centrePointOnTerrain.z); secondaryCausticsObj.transform.position = new Vector3(sceneInfo.m_centrePointOnTerrain.x, sceneInfo.m_seaLevel, sceneInfo.m_centrePointOnTerrain.z); primaryCausticsObj.GetComponent <Projector>().orthographicSize = sceneInfo.m_sceneBounds.extents.x; secondaryCausticsObj.GetComponent <Projector>().orthographicSize = sceneInfo.m_sceneBounds.extents.x; primaryCausticsObj.transform.SetParent(aquasObj.transform); secondaryCausticsObj.transform.SetParent(aquasObj.transform); //Set some material parameters based on whether Tenkoku is in the scene or not if (GameObject.Find("Tenkoku DynamicSky") != null) { aquasObj.GetComponent <Renderer>().sharedMaterial.SetFloat("_EnableCustomFog", 1); aquasObj.GetComponent <Renderer>().sharedMaterial.SetFloat("_Specular", 0.5f); } else { aquasObj.GetComponent <Renderer>().sharedMaterial.SetFloat("_EnableCustomFog", 0); aquasObj.GetComponent <Renderer>().sharedMaterial.SetFloat("_Specular", 1); } } }
/// <summary> /// Add Suimono to the scene /// </summary> public static void GX_AddSuimono() { //Add the Suimono objects to the scene //Get scene info GaiaSceneInfo sceneInfo = GaiaSceneInfo.GetSceneInfo(); //INSTALL Suimono Module GameObject suimonoPrefab = Gaia.Utils.GetAssetPrefab("SUIMONO_Module"); if (suimonoPrefab == null) { Debug.LogWarning("Unable to locate SuimonoModule - Aborting!"); return; } //See if we can locate it if (GameObject.Find("SUIMONO_Module") != null) { Debug.LogWarning("Suimono Module already in scene - Aborting!"); return; } //See if we can create it GameObject suimonoObj = Instantiate(suimonoPrefab); if (suimonoObj == null) { Debug.LogWarning("Unable to create Suimono Module object - Aborting!"); return; } else { suimonoObj.name = "SUIMONO_Module"; } //INSTALL Suimono Surface GameObject surfacePrefab = Gaia.Utils.GetAssetPrefab("SUIMONO_Surface"); if (suimonoPrefab == null) { Debug.LogWarning("Unable to locate SuimonoSurface - Aborting!"); return; } //See if we can locate it if (GameObject.Find("SUIMONO_Surface") != null) { Debug.LogWarning("Suimono Surface already in scene - Aborting!"); return; } //See if we can create it GameObject surfaceObj = Instantiate(surfacePrefab); if (surfaceObj == null) { Debug.LogWarning("Unable to create Suimono Surface object - Aborting!"); return; } else { //set surface surfaceObj.name = "SUIMONO_Surface"; //set surface position surfaceObj.transform.position = new Vector3(0.0f, 0.0f, 0.0f); //Set Water Y-Height and expansion if (sceneInfo != null) { surfaceObj.transform.position = new Vector3(sceneInfo.m_centrePointOnTerrain.x, sceneInfo.m_seaLevel, sceneInfo.m_centrePointOnTerrain.z); surfaceObj.transform.localScale = sceneInfo.m_sceneBounds.extents * 1; } //set surface-specific settings var surfaceObject = surfaceObj.GetComponent("SuimonoObject"); if (surfaceObject != null) { //set surface as infinite ocean FieldInfo typeIndex = surfaceObject.GetType().GetField("typeIndex", BindingFlags.Public | BindingFlags.Instance); if (typeIndex != null) { typeIndex.SetValue(surfaceObject, 0); } } } //See if we can configure Module - via reflection as JS and C# dont play nice var suimonoModule = suimonoObj.GetComponent("SuimonoModule"); if (suimonoModule != null) { //Set the camera Camera camera = Camera.main; if (camera == null) { camera = FindObjectOfType <Camera>(); } if (camera != null) { FieldInfo manualCamera = suimonoModule.GetType().GetField("manualCamera", BindingFlags.Public | BindingFlags.Instance); if (manualCamera != null) { manualCamera.SetValue(suimonoModule, camera.transform); } } //Add scene directional light if it exists Light lightObj = GameObject.Find("Directional Light").GetComponent <Light>(); if (lightObj != null) { FieldInfo setLight = suimonoModule.GetType().GetField("setLight", BindingFlags.Public | BindingFlags.Instance); if (setLight != null) { setLight.SetValue(suimonoModule, lightObj); } } } }
//Adds new gaia water to your scene public static void GX_Water_AddWater() { if (Application.isPlaying) { Debug.LogWarning("Can only add water when application is not playing!"); return; } //Get relevant information GaiaSceneInfo sceneInfo = GaiaSceneInfo.GetSceneInfo(); GameObject parentObject = GetOrCreateEnvironmentParent(); Terrain activeTerrain = GetActiveTerrain(); Material waterMaterial = GetWaterMaterial("Ambient Water Sample Material"); //Get main directional light and make sure its set up properly var lightObject = GetOrCreateDirectionalLight(); var effectsSettings = lightObject.GetComponent <GaiaUnderWaterEffects>(); if (lightObject.GetComponent <GaiaUnderWaterEffects>() == null) { effectsSettings = lightObject.AddComponent <GaiaUnderWaterEffects>(); } effectsSettings.m_causticsSize = 5; effectsSettings.m_followPlayer = false; effectsSettings.m_framesPerSecond = 25f; effectsSettings.m_sealevel = sceneInfo.m_seaLevel; effectsSettings.m_underWaterFogColor = new Color32(76, 112, 142, 255); effectsSettings.m_underWaterFogDistance = 65f; effectsSettings.LoadCaustics(); #if UNITY_EDITOR effectsSettings.player = effectsSettings.GetThePlayer(); #endif #if UNITY_POST_PROCESSING_STACK_V2 var underwaterPostFxObject = GameObject.Find("Underwater PostFX"); if (underwaterPostFxObject == null) { underwaterPostFxObject = new GameObject("Underwater PostFX"); underwaterPostFxObject.transform.position = new Vector3(0f, sceneInfo.m_seaLevel - 506.5f, 0f); underwaterPostFxObject.transform.parent = parentObject.transform; underwaterPostFxObject.layer = LayerMask.NameToLayer("TransparentFX"); //Add the pp volume var ppVol = underwaterPostFxObject.AddComponent <PostProcessVolume>(); ppVol.sharedProfile = AssetDatabase.LoadAssetAtPath <PostProcessProfile>(GetAssetPath("Ambient Sample Underwater Post Processing")); ppVol.blendDistance = 4f; ppVol.priority = 1; var colliderSettings = underwaterPostFxObject.AddComponent <BoxCollider>(); if (activeTerrain != null) { colliderSettings.size = new Vector3(activeTerrain.terrainData.size.x * 1.5f, 1000f, activeTerrain.terrainData.size.z * 1.5f); } else { colliderSettings.size = new Vector3(2560f, 1000f, 2560f); } colliderSettings.isTrigger = true; } var underwaterTransitionFXObject = GameObject.Find("Underwater Transition PostFX"); if (underwaterTransitionFXObject == null) { underwaterTransitionFXObject = new GameObject("Underwater Transition PostFX"); underwaterTransitionFXObject.transform.position = new Vector3(0f, sceneInfo.m_seaLevel, 0f); underwaterTransitionFXObject.transform.parent = parentObject.transform; underwaterTransitionFXObject.layer = LayerMask.NameToLayer("TransparentFX"); var ppVol = underwaterTransitionFXObject.AddComponent <PostProcessVolume>(); ppVol.sharedProfile = AssetDatabase.LoadAssetAtPath <PostProcessProfile>(GetAssetPath("Ambient Sample Underwater Transaction Post Processing")); ppVol.blendDistance = 0.15f; ppVol.priority = 2; var colliderSettings = underwaterTransitionFXObject.AddComponent <BoxCollider>(); if (activeTerrain != null) { colliderSettings.size = new Vector3(activeTerrain.terrainData.size.x * 1.5f, 0.1f, activeTerrain.terrainData.size.z * 1.5f); } else { colliderSettings.size = new Vector3(2560f, 0.1f, 2560f); } colliderSettings.isTrigger = true; } #endif var underwaterAudioFXObject = GameObject.Find("Underwater SoundFX"); Terrain terrain = GetActiveTerrain(); if (underwaterAudioFXObject == null) { underwaterAudioFXObject = new GameObject("Underwater SoundFX"); underwaterAudioFXObject.transform.parent = parentObject.transform; var audio = underwaterAudioFXObject.AddComponent <AudioSource>(); audio.clip = AssetDatabase.LoadAssetAtPath <AudioClip>(GetAssetPath("Gaia Ambient Underwater Sound Effect")); audio.volume = 0f; audio.loop = true; if (terrain != null) { audio.maxDistance = terrain.terrainData.size.x * 1.5f; } else { audio.maxDistance = 3000f; } } //Grab or create the water GameObject theWaterObject = GameObject.Find("Ambient Water Sample"); if (theWaterObject == null) { theWaterObject = Instantiate(GetAssetPrefab("Ambient Water Sample")); theWaterObject.name = "Ambient Water Sample"; theWaterObject.transform.parent = parentObject.transform; } //And update it Vector3 waterPosition = sceneInfo.m_centrePointOnTerrain; waterPosition.y = sceneInfo.m_seaLevel; theWaterObject.transform.position = waterPosition; if (activeTerrain != null) { theWaterObject.transform.localScale = new Vector3(sceneInfo.m_sceneBounds.size.x, 1f, sceneInfo.m_sceneBounds.size.z); } else { theWaterObject.transform.localScale = new Vector3(256f, 1f, 256f); } //Update water material if (waterMaterial != null) { if (activeTerrain != null) { waterMaterial.SetFloat("_GlobalTiling", sceneInfo.m_sceneBounds.size.x); } else { waterMaterial.SetFloat("_GlobalTiling", 128f); } } //Adds reflection probe updater script if missing GetOrCreateReflectionProbe("Camera Reflection Probe"); GameObject theReflectionProbeObject = GameObject.Find("Camera Reflection Probe"); if (theReflectionProbeObject != null) { if (theReflectionProbeObject.GetComponent <GaiaReflectionProbeUpdate>() == null) { GaiaReflectionProbeUpdate probeObject = theReflectionProbeObject.AddComponent <GaiaReflectionProbeUpdate>(); probeObject.m_followCamera = true; probeObject.SetProbeSettings(); } } }
//<summary> //Adds Underwater Effects to the scene //</summary> public static void GX_AddUnderwaterEffects() { //Collect Scene info GaiaSceneInfo sceneInfo = GaiaSceneInfo.GetSceneInfo(); GameObject underwaterPrefab = Gaia.Utils.GetAssetPrefab("UnderWaterCameraEffects"); //Check if AQUAS is already in the scene if (GameObject.Find("AQUAS Waterplane") == null) { EditorUtility.DisplayDialog("AQUAS is not in the scene", "Please add water first", "Ok"); return; } //Try to add underwater effects else { if (GameObject.Find("UnderWaterCameraEffects") != null) { EditorUtility.DisplayDialog("Can't add underwater effects", "Underwater Effects are already in the scene", "Ok"); return; } GameObject underwaterObj = Instantiate(underwaterPrefab); underwaterObj.name = "UnderWaterCameraEffects"; //Find camera Camera camera = Camera.main; if (camera == null) { camera = FindObjectOfType <Camera>(); } camera.farClipPlane = sceneInfo.m_sceneBounds.extents.x * 2; #if UNITY_POST_PROCESSING_STACK_V2 && AQUAS_PRESENT underwaterObj.GetComponent <AQUAS_LensEffects>().underWaterParameters.underwaterProfile = (PostProcessProfile)AssetDatabase.LoadAssetAtPath("Assets/AQUAS/Post Processing/AQUAS_Underwater_v2.asset", typeof(PostProcessProfile)); underwaterObj.GetComponent <AQUAS_LensEffects>().underWaterParameters.defaultProfile = (PostProcessProfile)AssetDatabase.LoadAssetAtPath("Assets/AQUAS/Post Processing/DefaultPostProcessing_v2.asset", typeof(PostProcessProfile)); #endif //Underwater effects setup underwaterObj.transform.SetParent(camera.transform); underwaterObj.transform.localPosition = new Vector3(0, 0, 0); underwaterObj.transform.localEulerAngles = new Vector3(0, 0, 0); underwaterObj.GetComponent <AQUAS_LensEffects>().gameObjects.mainCamera = camera.gameObject; underwaterObj.GetComponent <AQUAS_LensEffects>().gameObjects.waterPlanes[0] = GameObject.Find("AQUAS Waterplane"); if (GameObject.Find("AQUAS Waterplane").GetComponent <MeshFilter>().sharedMesh.name == "Plane" || GameObject.Find("AQUAS Waterplane").GetComponent <MeshFilter>().sharedMesh.name == "Plane Instance") { underwaterObj.GetComponent <AQUAS_LensEffects>().gameObjects.useSquaredPlanes = true; } else { underwaterObj.GetComponent <AQUAS_LensEffects>().gameObjects.useSquaredPlanes = false; } //Add and configure image effects neccessary for AQUAS #if UNITY_POST_PROCESSING_STACK_V1 && AQUAS_PRESENT if (camera.gameObject.GetComponent <PostProcessingBehaviour>() == null) { camera.gameObject.AddComponent <PostProcessingBehaviour>(); } #endif #if UNITY_POST_PROCESSING_STACK_V2 && AQUAS_PRESENT if (camera.gameObject.GetComponent <PostProcessLayer>() == null) { camera.gameObject.AddComponent <PostProcessLayer>(); PostProcessResources resources; if ((PostProcessResources)AssetDatabase.LoadAssetAtPath("Assets/PostProcessing-2/PostProcessing/PostProcessResources.asset", typeof(PostProcessResources)) != null) { resources = (PostProcessResources)AssetDatabase.LoadAssetAtPath("Assets/PostProcessing-2/PostProcessing/PostProcessResources.asset", typeof(PostProcessResources)); } else if ((PostProcessResources)AssetDatabase.LoadAssetAtPath("Assets/PostProcessing/PostProcessResources.asset", typeof(PostProcessResources)) != null) { resources = (PostProcessResources)AssetDatabase.LoadAssetAtPath("Assets/PostProcessing/PostProcessResources.asset", typeof(PostProcessResources)); } else if ((PostProcessResources)AssetDatabase.LoadAssetAtPath("Assets/PostProcessing-2/PostProcessResources.asset", typeof(PostProcessResources)) != null) { resources = (PostProcessResources)AssetDatabase.LoadAssetAtPath("Assets/PostProcessing-2/PostProcessResources.asset", typeof(PostProcessResources)); } else { EditorUtility.DisplayDialog("Could not locate Post Process Resource file.", "Please make sure your post processing folder is at the top level of the assets folder and named either 'PostProcessing' or 'PostProcessing-2'", "Got It!"); resources = null; } camera.gameObject.GetComponent <PostProcessLayer>().Init(resources); camera.gameObject.GetComponent <PostProcessLayer>().volumeLayer = LayerMask.NameToLayer("Everything"); } if (camera.gameObject.GetComponent <PostProcessVolume>() == null) { camera.gameObject.AddComponent <PostProcessVolume>(); camera.gameObject.GetComponent <PostProcessVolume>().isGlobal = true; } #endif if (camera.gameObject.GetComponent <AudioSource>() == null) { camera.gameObject.AddComponent <AudioSource>(); } //Add borders to the scene for correct fog if (GameObject.Find("Borders") != null) { return; } GameObject borders = new GameObject(); borders.name = "Borders"; GameObject borderLeft = GameObject.CreatePrimitive(PrimitiveType.Cube); borderLeft.name = "Left Border"; borderLeft.transform.localScale = new Vector3(sceneInfo.m_sceneBounds.extents.x * 2, sceneInfo.m_seaLevel, 0.1f); borderLeft.transform.position = new Vector3(sceneInfo.m_sceneBounds.center.x, sceneInfo.m_seaLevel - (sceneInfo.m_seaLevel / 2), sceneInfo.m_sceneBounds.extents.z); GameObject borderRight = GameObject.CreatePrimitive(PrimitiveType.Cube); borderRight.name = "Right Border"; borderRight.transform.localScale = new Vector3(sceneInfo.m_sceneBounds.extents.x * 2, sceneInfo.m_seaLevel, 0.1f); borderRight.transform.position = new Vector3(sceneInfo.m_sceneBounds.center.x, sceneInfo.m_seaLevel - (sceneInfo.m_seaLevel / 2), -sceneInfo.m_sceneBounds.extents.z); GameObject borderTop = GameObject.CreatePrimitive(PrimitiveType.Cube); borderTop.name = "Top Border"; borderTop.transform.localScale = new Vector3(0.1f, sceneInfo.m_seaLevel, sceneInfo.m_sceneBounds.extents.z * 2); borderTop.transform.position = new Vector3(sceneInfo.m_sceneBounds.extents.x, sceneInfo.m_seaLevel - (sceneInfo.m_seaLevel / 2), sceneInfo.m_sceneBounds.center.z); GameObject borderBottom = GameObject.CreatePrimitive(PrimitiveType.Cube); borderBottom.name = "Bottom Border"; borderBottom.transform.localScale = new Vector3(0.1f, sceneInfo.m_seaLevel, sceneInfo.m_sceneBounds.extents.z * 2); borderBottom.transform.position = new Vector3(-sceneInfo.m_sceneBounds.extents.x, sceneInfo.m_seaLevel - (sceneInfo.m_seaLevel / 2), -sceneInfo.m_sceneBounds.center.z); borderLeft.transform.SetParent(borders.transform); borderRight.transform.SetParent(borders.transform); borderTop.transform.SetParent(borders.transform); borderBottom.transform.SetParent(borders.transform); borders.transform.SetParent(GameObject.Find("AQUAS Waterplane").transform); } }
//<summary> //Adds Underwater Effects to the scene //</summary> public static void GX_AddUnderwaterEffects() { //Collect Scene info GaiaSceneInfo sceneInfo = GaiaSceneInfo.GetSceneInfo(); GameObject underwaterPrefab = Gaia.Utils.GetAssetPrefab("UnderWaterCameraEffects"); //Check if AQUAS is already in the scene if (GameObject.Find("AQUAS Waterplane") == null) { EditorUtility.DisplayDialog("AQUAS is not in the scene", "Please add water first", "Ok"); return; } //Try to add underwater effects else { if (GameObject.Find("UnderWaterCameraEffects") != null) { EditorUtility.DisplayDialog("Can't add underwater effects", "Underwater Effects are already in the scene", "Ok"); return; } GameObject underwaterObj = Instantiate(underwaterPrefab); underwaterObj.name = "UnderWaterCameraEffects"; //Find camera Camera camera = Camera.main; if (camera == null) { camera = FindObjectOfType <Camera>(); } camera.farClipPlane = sceneInfo.m_sceneBounds.extents.x * 2; //Underwater effects setup underwaterObj.transform.SetParent(camera.transform); underwaterObj.transform.localPosition = new Vector3(0, 0, 0); underwaterObj.transform.localEulerAngles = new Vector3(0, 0, 0); underwaterObj.GetComponent <AQUAS_LensEffects>().gameObjects.mainCamera = camera.gameObject; underwaterObj.GetComponent <AQUAS_LensEffects>().gameObjects.waterPlanes[0] = GameObject.Find("AQUAS Waterplane"); if (GameObject.Find("AQUAS Waterplane").GetComponent <MeshFilter>().sharedMesh.name == "Plane" || GameObject.Find("AQUAS Waterplane").GetComponent <MeshFilter>().sharedMesh.name == "Plane Instance") { underwaterObj.GetComponent <AQUAS_LensEffects>().gameObjects.useSquaredPlanes = true; } else { underwaterObj.GetComponent <AQUAS_LensEffects>().gameObjects.useSquaredPlanes = false; } //Add and configure image effects neccessary for AQUAS if (camera.gameObject.GetComponent <UnityStandardAssets.ImageEffects.Bloom>() == null) { camera.gameObject.AddComponent <UnityStandardAssets.ImageEffects.Bloom>(); camera.gameObject.GetComponent <UnityStandardAssets.ImageEffects.Bloom>().bloomIntensity = 0.4f; camera.gameObject.GetComponent <UnityStandardAssets.ImageEffects.Bloom>().enabled = true; camera.gameObject.GetComponent <UnityStandardAssets.ImageEffects.Bloom>().bloomThreshold = 0.5f; camera.gameObject.GetComponent <UnityStandardAssets.ImageEffects.Bloom>().bloomBlurIterations = 1; } else { camera.gameObject.GetComponent <UnityStandardAssets.ImageEffects.Bloom>().bloomIntensity = 0.4f; camera.gameObject.GetComponent <UnityStandardAssets.ImageEffects.Bloom>().enabled = true; } if (camera.gameObject.GetComponent <UnityStandardAssets.ImageEffects.BlurOptimized>() == null) { camera.gameObject.AddComponent <UnityStandardAssets.ImageEffects.BlurOptimized>(); camera.gameObject.GetComponent <UnityStandardAssets.ImageEffects.BlurOptimized>().enabled = false; camera.gameObject.GetComponent <UnityStandardAssets.ImageEffects.BlurOptimized>().downsample = 0; camera.gameObject.GetComponent <UnityStandardAssets.ImageEffects.BlurOptimized>().blurSize = 3; camera.gameObject.GetComponent <UnityStandardAssets.ImageEffects.BlurOptimized>().blurIterations = 2; } else { camera.gameObject.GetComponent <UnityStandardAssets.ImageEffects.BlurOptimized>().enabled = false; camera.gameObject.GetComponent <UnityStandardAssets.ImageEffects.BlurOptimized>().downsample = 0; camera.gameObject.GetComponent <UnityStandardAssets.ImageEffects.BlurOptimized>().blurSize = 3; camera.gameObject.GetComponent <UnityStandardAssets.ImageEffects.BlurOptimized>().blurIterations = 2; } if (camera.gameObject.GetComponent <UnityStandardAssets.ImageEffects.VignetteAndChromaticAberration>() == null) { camera.gameObject.AddComponent <UnityStandardAssets.ImageEffects.VignetteAndChromaticAberration>(); camera.gameObject.GetComponent <UnityStandardAssets.ImageEffects.VignetteAndChromaticAberration>().enabled = true; camera.gameObject.GetComponent <UnityStandardAssets.ImageEffects.VignetteAndChromaticAberration>().intensity = 0; camera.gameObject.GetComponent <UnityStandardAssets.ImageEffects.VignetteAndChromaticAberration>().blur = 0.54f; camera.gameObject.GetComponent <UnityStandardAssets.ImageEffects.VignetteAndChromaticAberration>().blurDistance = 1; camera.gameObject.GetComponent <UnityStandardAssets.ImageEffects.VignetteAndChromaticAberration>().chromaticAberration = 0; } else { camera.gameObject.GetComponent <UnityStandardAssets.ImageEffects.VignetteAndChromaticAberration>().enabled = true; camera.gameObject.GetComponent <UnityStandardAssets.ImageEffects.VignetteAndChromaticAberration>().intensity = 0; camera.gameObject.GetComponent <UnityStandardAssets.ImageEffects.VignetteAndChromaticAberration>().blur = 0.54f; camera.gameObject.GetComponent <UnityStandardAssets.ImageEffects.VignetteAndChromaticAberration>().blurDistance = 1; camera.gameObject.GetComponent <UnityStandardAssets.ImageEffects.VignetteAndChromaticAberration>().chromaticAberration = 0; } if (camera.gameObject.GetComponent <UnityStandardAssets.ImageEffects.NoiseAndGrain>() == null) { camera.gameObject.AddComponent <UnityStandardAssets.ImageEffects.NoiseAndGrain>(); camera.gameObject.GetComponent <UnityStandardAssets.ImageEffects.NoiseAndGrain>().enabled = false; camera.gameObject.GetComponent <UnityStandardAssets.ImageEffects.NoiseAndGrain>().dx11Grain = false; camera.gameObject.GetComponent <UnityStandardAssets.ImageEffects.NoiseAndGrain>().monochrome = false; camera.gameObject.GetComponent <UnityStandardAssets.ImageEffects.NoiseAndGrain>().intensityMultiplier = 1.86f; camera.gameObject.GetComponent <UnityStandardAssets.ImageEffects.NoiseAndGrain>().generalIntensity = 0; camera.gameObject.GetComponent <UnityStandardAssets.ImageEffects.NoiseAndGrain>().blackIntensity = 1; camera.gameObject.GetComponent <UnityStandardAssets.ImageEffects.NoiseAndGrain>().whiteIntensity = 1; camera.gameObject.GetComponent <UnityStandardAssets.ImageEffects.NoiseAndGrain>().midGrey = 0.2f; camera.gameObject.GetComponent <UnityStandardAssets.ImageEffects.NoiseAndGrain>().softness = 0.276f; camera.gameObject.GetComponent <UnityStandardAssets.ImageEffects.NoiseAndGrain>().tiling = new Vector3(512, 512, 512); } else { camera.gameObject.GetComponent <UnityStandardAssets.ImageEffects.NoiseAndGrain>().enabled = false; camera.gameObject.GetComponent <UnityStandardAssets.ImageEffects.NoiseAndGrain>().dx11Grain = false; camera.gameObject.GetComponent <UnityStandardAssets.ImageEffects.NoiseAndGrain>().monochrome = false; camera.gameObject.GetComponent <UnityStandardAssets.ImageEffects.NoiseAndGrain>().intensityMultiplier = 1.86f; camera.gameObject.GetComponent <UnityStandardAssets.ImageEffects.NoiseAndGrain>().generalIntensity = 0; camera.gameObject.GetComponent <UnityStandardAssets.ImageEffects.NoiseAndGrain>().blackIntensity = 1; camera.gameObject.GetComponent <UnityStandardAssets.ImageEffects.NoiseAndGrain>().whiteIntensity = 1; camera.gameObject.GetComponent <UnityStandardAssets.ImageEffects.NoiseAndGrain>().midGrey = 0.2f; camera.gameObject.GetComponent <UnityStandardAssets.ImageEffects.NoiseAndGrain>().softness = 0.276f; camera.gameObject.GetComponent <UnityStandardAssets.ImageEffects.NoiseAndGrain>().tiling = new Vector3(512, 512, 512); } if (camera.gameObject.GetComponent <UnityStandardAssets.ImageEffects.SunShafts>() == null) { camera.gameObject.AddComponent <UnityStandardAssets.ImageEffects.SunShafts>(); camera.gameObject.GetComponent <UnityStandardAssets.ImageEffects.SunShafts>().enabled = false; camera.gameObject.GetComponent <UnityStandardAssets.ImageEffects.SunShafts>().sunShaftIntensity = 0.6f; camera.gameObject.GetComponent <UnityStandardAssets.ImageEffects.SunShafts>().sunShaftBlurRadius = 1; camera.gameObject.GetComponent <UnityStandardAssets.ImageEffects.SunShafts>().radialBlurIterations = 3; camera.gameObject.GetComponent <UnityStandardAssets.ImageEffects.SunShafts>().maxRadius = 0.1f; } else { camera.gameObject.GetComponent <UnityStandardAssets.ImageEffects.SunShafts>().enabled = false; camera.gameObject.GetComponent <UnityStandardAssets.ImageEffects.SunShafts>().sunShaftIntensity = 0.6f; camera.gameObject.GetComponent <UnityStandardAssets.ImageEffects.SunShafts>().sunShaftBlurRadius = 1; camera.gameObject.GetComponent <UnityStandardAssets.ImageEffects.SunShafts>().radialBlurIterations = 3; camera.gameObject.GetComponent <UnityStandardAssets.ImageEffects.SunShafts>().maxRadius = 0.1f; } if (camera.gameObject.GetComponent <UnityStandardAssets.ImageEffects.GlobalFog>() == null) { camera.gameObject.AddComponent <UnityStandardAssets.ImageEffects.GlobalFog>(); camera.gameObject.GetComponent <UnityStandardAssets.ImageEffects.GlobalFog>().enabled = false; } if (camera.gameObject.GetComponent <AudioSource>() == null) { camera.gameObject.AddComponent <AudioSource>(); } //Add borders to the scene for correct fog if (GameObject.Find("Borders") != null) { return; } GameObject borders = new GameObject(); borders.name = "Borders"; GameObject borderLeft = GameObject.CreatePrimitive(PrimitiveType.Cube); borderLeft.name = "Left Border"; borderLeft.transform.localScale = new Vector3(sceneInfo.m_sceneBounds.extents.x * 2, sceneInfo.m_seaLevel, 0.1f); borderLeft.transform.position = new Vector3(sceneInfo.m_sceneBounds.center.x, sceneInfo.m_seaLevel - (sceneInfo.m_seaLevel / 2), sceneInfo.m_sceneBounds.extents.z); GameObject borderRight = GameObject.CreatePrimitive(PrimitiveType.Cube); borderRight.name = "Right Border"; borderRight.transform.localScale = new Vector3(sceneInfo.m_sceneBounds.extents.x * 2, sceneInfo.m_seaLevel, 0.1f); borderRight.transform.position = new Vector3(sceneInfo.m_sceneBounds.center.x, sceneInfo.m_seaLevel - (sceneInfo.m_seaLevel / 2), -sceneInfo.m_sceneBounds.extents.z); GameObject borderTop = GameObject.CreatePrimitive(PrimitiveType.Cube); borderTop.name = "Top Border"; borderTop.transform.localScale = new Vector3(0.1f, sceneInfo.m_seaLevel, sceneInfo.m_sceneBounds.extents.z * 2); borderTop.transform.position = new Vector3(sceneInfo.m_sceneBounds.extents.x, sceneInfo.m_seaLevel - (sceneInfo.m_seaLevel / 2), sceneInfo.m_sceneBounds.center.z); GameObject borderBottom = GameObject.CreatePrimitive(PrimitiveType.Cube); borderBottom.name = "Bottom Border"; borderBottom.transform.localScale = new Vector3(0.1f, sceneInfo.m_seaLevel, sceneInfo.m_sceneBounds.extents.z * 2); borderBottom.transform.position = new Vector3(-sceneInfo.m_sceneBounds.extents.x, sceneInfo.m_seaLevel - (sceneInfo.m_seaLevel / 2), -sceneInfo.m_sceneBounds.center.z); borderLeft.transform.SetParent(borders.transform); borderRight.transform.SetParent(borders.transform); borderTop.transform.SetParent(borders.transform); borderBottom.transform.SetParent(borders.transform); borders.transform.SetParent(GameObject.Find("AQUAS Waterplane").transform); } }
/// <summary> /// Add Suimono to the scene /// </summary> public static void GX_AddSuimono() { //Add the Suimono objects to the scene //Get scene info GaiaSceneInfo sceneInfo = GaiaSceneInfo.GetSceneInfo(); //INSTALL Suimono Module GameObject suimonoPrefab = Gaia.Utils.GetAssetPrefab("SUIMONO_Module"); if (suimonoPrefab == null) { Debug.LogWarning("Unable to locate SuimonoModule - Aborting!"); return; } //See if we can locate it if (GameObject.Find("SUIMONO_Module") != null) { Debug.LogWarning("Suimono Module already in scene - Aborting!"); return; } //See if we can create it GameObject suimonoObj = Instantiate(suimonoPrefab); if (suimonoObj == null) { Debug.LogWarning("Unable to create Suimono Module object - Aborting!"); return; } else { suimonoObj.name = "SUIMONO_Module"; } //INSTALL Suimono Surface GameObject surfacePrefab = Gaia.Utils.GetAssetPrefab("SUIMONO_Surface"); if (suimonoPrefab == null) { Debug.LogWarning("Unable to locate SuimonoSurface - Aborting!"); return; } //See if we can locate it if (GameObject.Find("SUIMONO_Surface") != null) { Debug.LogWarning("Suimono Surface already in scene - Aborting!"); return; } //See if we can create it GameObject surfaceObj = Instantiate(surfacePrefab); if (surfaceObj == null) { Debug.LogWarning("Unable to create Suimono Surface object - Aborting!"); return; } else { //set surface surfaceObj.name = "SUIMONO_Surface"; //set surface position surfaceObj.transform.position = new Vector3(0.0f, 0.0f, 0.0f); //Set Water Y-Height and expansion if (sceneInfo != null) { surfaceObj.transform.position = new Vector3(sceneInfo.m_centrePointOnTerrain.x, sceneInfo.m_seaLevel, sceneInfo.m_centrePointOnTerrain.z); surfaceObj.transform.localScale = sceneInfo.m_sceneBounds.extents * 1; } //set surface-specific settings var surfaceObject = surfaceObj.GetComponent <Suimono.Core.SuimonoObject>(); if (surfaceObject != null) { //set surface as infinite ocean surfaceObject.typeIndex = 0; } } //See if we can configure Module var suimonoModule = suimonoObj.GetComponent <Suimono.Core.SuimonoModule>(); if (suimonoModule != null) { //Set the camera Camera camera = Camera.main; if (camera == null) { camera = FindObjectOfType <Camera>(); } if (camera != null) { suimonoModule.manualCamera = camera.transform; } //Add scene directional light if it exists Light lightObj = GameObject.Find("Directional Light").GetComponent <Light>(); if (lightObj != null) { suimonoModule.setLight = lightObj; } } }
public static void GX_Setup_AddGroundFog() { //Pick colour of main light GameObject goLight = GameObject.Find("Directional Light"); Light mainLight = null; if (goLight != null) { mainLight = goLight.GetComponent <Light>(); } else { mainLight = GameObject.FindObjectOfType <Light>(); } Color mainLightColor = Color.white; if (mainLight != null) { mainLightColor = mainLight.color; } //First make sure its not already in scene GameObject fvGroundFog = GameObject.Find("Fog Volume [Ground Fog]"); if (fvGroundFog == null) { fvGroundFog = new GameObject(); fvGroundFog.name = "Fog Volume [Ground Fog]"; fvGroundFog.AddComponent <MeshRenderer>(); fvGroundFog.AddComponent <FogVolume>(); fvGroundFog.GetComponent <Renderer>().shadowCastingMode = UnityEngine.Rendering.ShadowCastingMode.Off; fvGroundFog.GetComponent <Renderer>().receiveShadows = false; fvGroundFog.GetComponent <Renderer>().reflectionProbeUsage = UnityEngine.Rendering.ReflectionProbeUsage.Off; fvGroundFog.GetComponent <Renderer>().lightProbeUsage = UnityEngine.Rendering.LightProbeUsage.Off; } //Adjust its position and size FogVolume fvVolume = fvGroundFog.GetComponent <FogVolume>(); if (fvVolume != null) { GaiaSceneInfo info = GaiaSceneInfo.GetSceneInfo(); Debug.Log(info.m_seaLevel); fvVolume.transform.position = new Vector3(info.m_sceneBounds.center.x, info.m_seaLevel + 0.01f + (info.m_sceneBounds.extents.y / 4f), info.m_sceneBounds.center.z); // info.m_sceneBounds.center; fvVolume.fogVolumeScale = new Vector3(info.m_sceneBounds.size.x * 3, info.m_sceneBounds.extents.y / 2f, info.m_sceneBounds.size.z * 3); //And adjust camera far clip as well float maxClip = Math.Max(info.m_sceneBounds.size.x, info.m_sceneBounds.size.z) * 3f; Camera mainCamera = Camera.main; if (mainCamera != null) { if (mainCamera.farClipPlane < maxClip) { mainCamera.farClipPlane = maxClip + 200f; } } fvVolume.FogMainColor = new Color(53f / 255f, 76f / 255f, 114f / 255f); //fvVolume.Visibility = maxClip; fvVolume.Visibility = 800f; fvVolume.EnableInscattering = true; fvVolume.InscatteringColor = Color.Lerp(mainLightColor, Color.black, 0.8f); fvVolume.VolumeFogInscatteringAnisotropy = 0.59f; fvVolume.InscatteringIntensity = 0.07f; fvVolume.InscatteringStartDistance = 5f; fvVolume.InscatteringTransitionWideness = 300f; //Other fvVolume.DrawOrder = 3; fvVolume._PushAlpha = 1.0025f; fvVolume._ztest = CompareFunction.Always; } }
public static void GX_Setup_AddClouds() { //Pick colour of main light Color mainLightColor = Color.white; GameObject goLight = GameObject.Find("Directional Light"); Light mainLight; if (goLight != null) { mainLight = goLight.GetComponent <Light>(); } else { mainLight = GameObject.FindObjectOfType <Light>(); } if (mainLight != null) { mainLightColor = mainLight.color; } //Get the main camera Camera mainCamera = Camera.main; //First make sure its not already in scene - if it isnt then add it FogVolume fvVolume; GameObject goClouds = GameObject.Find("Fog Volume [Clouds]"); if (goClouds == null) { goClouds = new GameObject(); goClouds.name = "Fog Volume [Clouds]"; goClouds.AddComponent <MeshRenderer>(); fvVolume = goClouds.AddComponent <FogVolume>(); goClouds.GetComponent <Renderer>().shadowCastingMode = UnityEngine.Rendering.ShadowCastingMode.Off; goClouds.GetComponent <Renderer>().receiveShadows = false; goClouds.GetComponent <Renderer>().reflectionProbeUsage = UnityEngine.Rendering.ReflectionProbeUsage.Off; goClouds.GetComponent <Renderer>().lightProbeUsage = UnityEngine.Rendering.LightProbeUsage.Off; //Create the horizon GameObject goHorizon = GameObject.CreatePrimitive(PrimitiveType.Plane); goHorizon.name = "Horizon"; goHorizon.transform.parent = goClouds.transform; goHorizon.transform.localPosition = new Vector3(0f, -79f, 0f); goHorizon.GetComponent <MeshRenderer>().enabled = false; goHorizon.GetComponent <MeshCollider>().enabled = false; //Create the priority script FogVolumePriority fvPriority = goClouds.AddComponent <FogVolumePriority>(); fvPriority.GameCamera = mainCamera; fvPriority.FogOrderCameraAbove = 4; fvPriority.FogOrderCameraBelow = -1; fvPriority.thisFog = fvVolume; fvPriority.Horizon = goHorizon; } //Adjust its position and size fvVolume = goClouds.GetComponent <FogVolume>(); if (fvVolume != null) { GaiaSceneInfo info = GaiaSceneInfo.GetSceneInfo(); //Location and scale fvVolume.transform.position = new Vector3(info.m_sceneBounds.center.x, info.m_seaLevel + 200f, info.m_sceneBounds.center.z);// info.m_sceneBounds.center; fvVolume.fogVolumeScale = new Vector3(info.m_sceneBounds.size.x * 3, 100f, info.m_sceneBounds.size.z * 3); //Camera far clip float maxClip = Math.Max(info.m_sceneBounds.size.x, info.m_sceneBounds.size.z) * 3f; if (mainCamera != null) { if (mainCamera.farClipPlane < maxClip) { mainCamera.farClipPlane = maxClip + 200f; } } //Fog type and blend mode fvVolume._FogType = FogVolume.FogType.Textured; fvVolume._BlendMode = FogVolumeRenderer.BlendMode.PremultipliedTransparency; //Lighting fvVolume._AmbientColor = Color.Lerp(mainLightColor, Color.black, 0.1f); fvVolume.useHeightGradient = true; fvVolume.Absorption = 0.8f; fvVolume.HeightAbsorption = 0.185f; fvVolume.bAbsorption = true; fvVolume.EnableInscattering = true; fvVolume.InscatteringColor = mainLightColor; fvVolume.InscatteringShape = 0.05f; fvVolume.InscatteringIntensity = 0.882f; fvVolume.InscatteringStartDistance = 0f; fvVolume.InscatteringTransitionWideness = 1f; fvVolume._DirectionalLighting = true; fvVolume.LightExtinctionColor = Color.Lerp(mainLightColor, Color.black, 0.8f); fvVolume._DirectionalLightingDistance = 0.0008f; fvVolume.DirectLightingShadowDensity = 6f; fvVolume.DirectLightingShadowSteps = 1; //Renderer fvVolume.NoiseIntensity = 1f; fvVolume.SceneCollision = false; //Faster i suppose ? fvVolume.Iterations = 500; fvVolume.IterationStep = 100; fvVolume._OptimizationFactor = 0.0000005f; fvVolume.GradMin = 0.19f; fvVolume.GradMax = 0.06f; fvVolume.GradMin2 = -0.25f; fvVolume.GradMax2 = 0.21f; //Noise fvVolume.EnableNoise = true; fvVolume._3DNoiseScale = 0.15f; fvVolume.Speed = new Vector4(0.49f, 0f, 0f, 0f); fvVolume.Vortex = 0.47f; fvVolume.RotationSpeed = 0f; fvVolume.rotation = 324f; fvVolume._VortexAxis = FogVolume.VortexAxis.Y; fvVolume.Coverage = 2.44f; fvVolume.NoiseContrast = 12.9f; fvVolume.NoiseDensity = 0.2f; fvVolume.Octaves = 3; fvVolume.BaseTiling = 150f; fvVolume._BaseRelativeSpeed = 0.85f; fvVolume.DetailTiling = 285.3f; fvVolume._DetailRelativeSpeed = 16.6f; fvVolume.DetailDistance = 5000f; fvVolume._NoiseDetailRange = 0.337f; fvVolume._DetailMaskingThreshold = 8f; fvVolume._Curl = 0.364f; //Other fvVolume.DrawOrder = 4; fvVolume._ztest = CompareFunction.LessEqual; fvVolume.CreateSurrogate = true; } }