コード例 #1
0
        /// <summary>
        /// Creates the reflection prrobe parent object
        /// </summary>
        /// <param name="parentWithAmbientSkies"></param>
        /// <returns></returns>
        private static GameObject ReflectionProbeParenting(bool parentWithAmbientSkies)
        {
            GameObject reflectionProbeParent = GameObject.Find("Scene Reflection Probes");
            GameObject ambientSkiesParent    = GameObject.Find("Ambient Skies Environment");

            if (reflectionProbeParent == null)
            {
                reflectionProbeParent = new GameObject("Scene Reflection Probes");

                if (parentWithAmbientSkies)
                {
                    if (ambientSkiesParent == null)
                    {
                        ambientSkiesParent = SkyboxUtils.GetOrCreateParentObject("Ambient Skies Environment", false);
                        reflectionProbeParent.transform.SetParent(ambientSkiesParent.transform);
                    }
                    else
                    {
                        reflectionProbeParent.transform.SetParent(ambientSkiesParent.transform);
                    }
                }

                return(reflectionProbeParent);
            }
            else
            {
                return(reflectionProbeParent);
            }
        }
コード例 #2
0
        /// <summary>
        /// Add realtime global reflection probes
        /// </summary>
        public static void AddGlobalReflectionProbeRealtime()
        {
            AmbientSkyProfiles profiles = AssetDatabase.LoadAssetAtPath <AmbientSkyProfiles>(SkyboxUtils.GetAssetPath("Ambient Skies Volume 1"));

            GameObject theParent = SkyboxUtils.GetOrCreateParentObject("Ambient Skies Environment", false);

            //Get the camera
            GameObject mainCamera = SkyboxUtils.GetOrCreateMainCamera();

            //Sets up the probe to terrain size & location
            Vector3 probeLocation = Vector3.zero;
            Vector3 probeSize     = new Vector3(3000f, 1250f, 3000f);
            Terrain terrain       = Terrain.activeTerrain;

            if (terrain != null && GameObject.Find("Ambient Skies Water System") == null)
            {
                probeSize    = terrain.terrainData.size;
                probeSize.x += 50f;
                probeSize.z += 50f;

                probeLocation   = terrain.transform.position + (probeSize * 0.5f);
                probeLocation.y = terrain.SampleHeight(probeLocation) + 100f;
            }

            GameObject globalProbeGo = GameObject.Find("Global Reflection Probe");

            if (globalProbeGo == null)
            {
                globalProbeGo = new GameObject("Global Reflection Probe");
                globalProbeGo.AddComponent <ReflectionProbe>();
            }

            ReflectionProbe globalProbe = globalProbeGo.GetComponent <ReflectionProbe>();
            Camera          camera      = mainCamera.GetComponent <Camera>();

            globalProbeGo.transform.parent = theParent.transform;
            if (terrain != null)
            {
                globalProbeGo.transform.localPosition = probeLocation;
            }
            else
            {
                globalProbeGo.transform.localPosition = new Vector3(0f, 60f, 0f);
            }
            globalProbeGo.transform.localRotation = new Quaternion(0f, 0f, 0f, 0f);

            //Configure probe settings
            if (globalProbe != null)
            {
                if (terrain != null)
                {
                    globalProbe.size = new Vector3(8f, terrain.terrainData.size.y / 2, 8f);
                }
                else
                {
                    globalProbe.size = new Vector3(8f, 400f, 8f);
                }
                globalProbe.farClipPlane = camera.farClipPlane / 1.4f;
            }

            //Configures all probes
            if (Object.FindObjectsOfType <ReflectionProbe>() != null)
            {
                if (profiles != null)
                {
                    if (profiles.m_selectedRenderPipeline == AmbientSkiesConsts.RenderPipelineSettings.HighDefinition)
                    {
#if HDPipeline && UNITY_2018_3_OR_NEWER
                        HDAdditionalReflectionData[] reflectionData = Object.FindObjectsOfType <HDAdditionalReflectionData>();
                        foreach (HDAdditionalReflectionData data in reflectionData)
                        {
#if UNITY_2019_1_OR_NEWER
                            data.mode = ProbeSettings.Mode.Baked;
#elif UNITY_2018_3_OR_NEWER
                            data.mode = ReflectionProbeMode.Baked;
#endif
                        }
#endif
                    }
                    else
                    {
                        ReflectionProbe[] allProbes = Object.FindObjectsOfType <ReflectionProbe>();
                        foreach (ReflectionProbe theReflectionProbes in allProbes)
                        {
                            theReflectionProbes.clearFlags = ReflectionProbeClearFlags.Skybox;
                            theReflectionProbes.mode       = ReflectionProbeMode.Baked;
                        }
                    }
                }
                else
                {
                    ReflectionProbe[] allProbes = Object.FindObjectsOfType <ReflectionProbe>();
                    foreach (ReflectionProbe theReflectionProbes in allProbes)
                    {
                        theReflectionProbes.clearFlags = ReflectionProbeClearFlags.Skybox;
                        theReflectionProbes.mode       = ReflectionProbeMode.Baked;
                    }
                }
            }

            //Updated reflection probes to realtime support
            QualitySettings.realtimeReflectionProbes = true;
        }
コード例 #3
0
        /// <summary>
        /// Add static global reflection probes
        /// </summary>
        public static void AddGlobalReflectionProbeStatic()
        {
            GameObject theParent = SkyboxUtils.GetOrCreateParentObject("Ambient Skies Environment", false);

            //Get the camera
            GameObject mainCamera = SkyboxUtils.GetOrCreateMainCamera();

            //Sets up the probe to terrain size & location
            Vector3 probeLocation = Vector3.zero;
            Vector3 probeSize     = new Vector3(3000f, 1250f, 3000f);
            Terrain terrain       = Terrain.activeTerrain;

            if (terrain != null)
            {
                probeSize    = terrain.terrainData.size;
                probeSize.x += 50f;
                probeSize.z += 50f;

                probeLocation   = terrain.transform.position + (probeSize * 0.5f);
                probeLocation.y = terrain.SampleHeight(probeLocation) + 100f;
            }

            GameObject globalProbeGo = GameObject.Find("Global Reflection Probe");

            if (globalProbeGo == null)
            {
                globalProbeGo = new GameObject("Global Reflection Probe");
                globalProbeGo.AddComponent <ReflectionProbe>();
            }

            globalProbeGo.transform.parent = theParent.transform;
            if (terrain != null)
            {
                globalProbeGo.transform.localPosition = probeLocation;
            }
            else
            {
                globalProbeGo.transform.localPosition = new Vector3(0f, 60f, 0f);
            }

            globalProbeGo.transform.localRotation = new Quaternion(0f, 0f, 0f, 0f);
            ReflectionProbe globalProbe = globalProbeGo.GetComponent <ReflectionProbe>();
            Camera          camera      = mainCamera.GetComponent <Camera>();

            //Configure probe settings
            if (globalProbe != null)
            {
                globalProbe.size         = probeSize;
                globalProbe.farClipPlane = camera.farClipPlane / 1.4f;
            }

            //Configures all probes
            if (Object.FindObjectsOfType <ReflectionProbe>() != null)
            {
                ReflectionProbe[] allProbes = Object.FindObjectsOfType <ReflectionProbe>();
                foreach (ReflectionProbe theReflectionProbes in allProbes)
                {
                    theReflectionProbes.mode        = ReflectionProbeMode.Realtime;
                    theReflectionProbes.refreshMode = ReflectionProbeRefreshMode.OnAwake;
                }
            }

            //Updated reflection probes to realtime support
            QualitySettings.realtimeReflectionProbes = true;
        }