예제 #1
0
        /// <summary>
        /// On Enable
        /// </summary>
        private void OnEnable()
        {
#if UNITY_EDITOR
            m_gaiaSettings = GaiaUtils.GetGaiaSettings();

            m_gaiaSceneInfo = GaiaSceneInfo.GetSceneInfo();

            if (m_gaiaSettings != null)
            {
                m_currentRenderer = m_gaiaSettings.m_currentRenderer;
            }
#if UNITY_POST_PROCESSING_STACK_V2
            transitionPostFX = GameObject.Find("Underwater Transition PostFX").GetComponent <PostProcessVolume>();

            underwaterPostFX = GameObject.Find("Underwater PostFX").GetComponent <PostProcessVolume>();

            if (Application.isPlaying)
            {
                transitionPostFX = GameObject.Find("Underwater Transition PostFX").GetComponent <PostProcessVolume>();
                if (transitionPostFX != null)
                {
                    transitionPostFX.enabled = true;
                }

                underwaterPostFX = GameObject.Find("Underwater PostFX").GetComponent <PostProcessVolume>();
                if (underwaterPostFX != null)
                {
                    underwaterPostFX.enabled = true;
                }
            }
            else
            {
                transitionPostFX = GameObject.Find("Underwater Transition PostFX").GetComponent <PostProcessVolume>();
                if (transitionPostFX != null)
                {
                    transitionPostFX.enabled = false;
                }

                underwaterPostFX = GameObject.Find("Underwater PostFX").GetComponent <PostProcessVolume>();
                if (underwaterPostFX != null)
                {
                    underwaterPostFX.enabled = false;
                }
            }
#endif

#if UNITY_2019_1_OR_NEWER && HDPipeline
            if (m_currentRenderer == GaiaConstants.EnvironmentRenderer.HighDefinition2018x)
            {
                if (m_aboveWaterProfile == null)
                {
                    m_aboveWaterProfile = AssetDatabase.LoadAssetAtPath <VolumeProfile>(GaiaPipelineUtils.GetAssetPath("Gaia HDRP Post Processing Profile"));
                }

                if (m_underwaterProfile == null)
                {
                    m_underwaterProfile = AssetDatabase.LoadAssetAtPath <VolumeProfile>(GaiaPipelineUtils.GetAssetPath("Gaia HDRP Underwater Post Processing Profile"));
                }
            }
#endif
#endif
        }
예제 #2
0
        /// <summary>
        /// Create a terrain tile based on these settings
        /// </summary>
        /// <param name="tx">X location</param>
        /// <param name="tz">Z location</param>
        /// <param name="world">The array managing it</param>
        private void CreateTile(int tx, int tz, ref Terrain[,] world, GaiaResource resources)
        {
            if (tx < 0 || tx >= m_tilesX)
            {
                Debug.LogError("X value out of bounds");
                return;
            }

            if (tz < 0 || tz >= m_tilesZ)
            {
                Debug.LogError("Z value out of bounds");
                return;
            }

            //Look for issues in the terrain settings and fix them
            GetAndFixDefaults();

            //this will center terrain at origin
            Vector2 m_offset = new Vector2(-m_terrainSize * m_tilesX * 0.5f, -m_terrainSize * m_tilesZ * 0.5f);

            //create the terrains if they dont already exist
            if (world.Length < m_tilesX)
            {
                world = new Terrain[m_tilesX, m_tilesZ];
            }

            //Create the terrain
            Terrain     terrain;
            TerrainData terrainData = new TerrainData();

            terrainData.name = string.Format("Terrain_{0}_{1}-{2:yyyyMMdd-HHmmss}", tx, tz, DateTime.Now);
            terrainData.alphamapResolution = m_controlTextureResolution;
            terrainData.baseMapResolution  = m_baseMapSize;
            terrainData.SetDetailResolution(m_detailResolution, m_detailResolutionPerPatch);
            terrainData.heightmapResolution = m_heightmapResolution;
            //terrainData.physicsMaterial = m_physicsMaterial;
            terrainData.wavingGrassAmount   = m_bending;
            terrainData.wavingGrassSpeed    = m_size;
            terrainData.wavingGrassStrength = m_speed;
            terrainData.wavingGrassTint     = m_grassTint;
            terrainData.size = new Vector3(m_terrainSize, m_terrainHeight, m_terrainSize);

#if UNITY_EDITOR
            AssetDatabase.CreateAsset(terrainData, string.Format("Assets/{0}.asset", terrainData.name));
#endif

            terrain      = Terrain.CreateTerrainGameObject(terrainData).GetComponent <Terrain>();
            terrain.name = terrainData.name;
            terrain.transform.position =
                new Vector3(m_terrainSize * tx + m_offset.x, 0, m_terrainSize * tz + m_offset.y);
            terrain.basemapDistance = m_baseMapDist;
#if UNITY_2019_1_OR_NEWER
            terrain.shadowCastingMode = m_shaodwCastingMode;
#else
            terrain.castShadows = m_castShadows;
#endif
            terrain.detailObjectDensity     = m_detailDensity;
            terrain.detailObjectDistance    = m_detailDistance;
            terrain.heightmapPixelError     = m_pixelError;
            terrain.treeBillboardDistance   = m_billboardStart;
            terrain.treeCrossFadeLength     = m_fadeLength;
            terrain.treeDistance            = m_treeDistance;
            terrain.treeMaximumFullLODCount = m_maxMeshTrees;
#if UNITY_EDITOR
            GameObjectUtility.SetStaticEditorFlags(terrain.gameObject,
                                                   StaticEditorFlags.BatchingStatic | StaticEditorFlags.NavigationStatic |
                                                   StaticEditorFlags.OccludeeStatic | StaticEditorFlags.OccluderStatic |
                                                   StaticEditorFlags.OffMeshLinkGeneration | StaticEditorFlags.ReflectionProbeStatic | StaticEditorFlags.LightmapStatic
                                                   );
            terrain.bakeLightProbesForTrees = false;
#if UNITY_2018_3_OR_NEWER
            terrain.drawInstanced = true;
#endif
#endif

            GaiaConstants.EnvironmentRenderer rendererType = GaiaConstants.EnvironmentRenderer.BuiltIn;
            GaiaSettings gaiaSettings = GaiaUtils.GetGaiaSettings();
            if (gaiaSettings != null)
            {
                rendererType = gaiaSettings.m_currentRenderer;
#if !UNITY_2018_1_OR_NEWER
                rendererType = GaiaConstants.EnvironmentRenderer.BuiltIn;
#endif
            }

            if (rendererType == GaiaConstants.EnvironmentRenderer.BuiltIn)
            {
                if (m_material != null)
                {
#if UNITY_EDITOR
                    GaiaPipelineUtils.SetupPipeline(rendererType, null, null, null, "Procedural Worlds/Simple Water", false);
#endif
                }
            }
            else
            {
                terrain.materialType = Terrain.MaterialType.Custom;
                if (rendererType == GaiaConstants.EnvironmentRenderer.LightWeight2018x)
                {
#if UNITY_EDITOR && UNITY_2018_3_OR_NEWER
                    GaiaPipelineUtils.SetupPipeline(rendererType, "Procedural Worlds Lightweight Pipeline Profile", "Pipeline Terrain Material", "Lightweight Render Pipeline/Terrain/Lit", "Procedural Worlds/Simple Water LW", false);
#else
                    Debug.LogWarning("Lightweight Pipeline is only supposted in 2018.3 or newer");
#endif
                }
                else
                {
#if UNITY_EDITOR && UNITY_2018_3_OR_NEWER
                    GaiaPipelineUtils.SetupPipeline(rendererType, "Procedural Worlds HDRenderPipelineAsset", "Pipeline Terrain Material", "HDRP/TerrainLit", "Procedural Worlds/Simple Water HD", false);
#else
                    Debug.LogWarning("Lightweight Pipeline is only supposted in 2018.3 or newer");
#endif
                }
            }

            if (m_physicsMaterial != null)
            {
                TerrainCollider collider = terrain.GetComponent <TerrainCollider>();
                if (collider != null)
                {
                    collider.material = m_physicsMaterial;
                }
                else
                {
                    Debug.LogWarning("Unable to assign physics material to terrain!");
                }
            }

            //Assign prototypes
            if (resources != null)
            {
                resources.ApplyPrototypesToTerrain(terrain);
            }
            else
            {
                terrain.Flush();
            }

            //Save the new tile
            world[tx, tz] = terrain;

            //Parent it to the environment
            GameObject gaiaObj = GameObject.Find("Gaia Environment");
            if (gaiaObj == null)
            {
                gaiaObj = new GameObject("Gaia Environment");
            }
            terrain.transform.parent = gaiaObj.transform;
        }
예제 #3
0
        /// <summary>
        /// On Enable
        /// </summary>
        private void OnEnable()
        {
#if UNITY_EDITOR
            m_gaiaSettings = GaiaUtils.GetGaiaSettings();

            m_gaiaSceneInfo = GaiaSceneInfo.GetSceneInfo();

            if (m_gaiaSettings != null)
            {
                m_currentRenderer = m_gaiaSettings.m_currentRenderer;
            }
#if UNITY_POST_PROCESSING_STACK_V2
            transitionPostFX = GameObject.Find("Underwater Transition PostFX").GetComponent <PostProcessVolume>();

            underwaterPostFX = GameObject.Find("Underwater PostFX").GetComponent <PostProcessVolume>();

            if (Application.isPlaying)
            {
                transitionPostFX = GameObject.Find("Underwater Transition PostFX").GetComponent <PostProcessVolume>();
                if (transitionPostFX != null)
                {
                    transitionPostFX.enabled = true;
                }

                underwaterPostFX = GameObject.Find("Underwater PostFX").GetComponent <PostProcessVolume>();
                if (underwaterPostFX != null)
                {
                    underwaterPostFX.enabled = true;
                }
            }
            else
            {
                transitionPostFX = GameObject.Find("Underwater Transition PostFX").GetComponent <PostProcessVolume>();
                if (transitionPostFX != null)
                {
                    transitionPostFX.enabled = false;
                }

                underwaterPostFX = GameObject.Find("Underwater PostFX").GetComponent <PostProcessVolume>();
                if (underwaterPostFX != null)
                {
                    underwaterPostFX.enabled = false;
                }
            }
#endif

#if UNITY_2019_1_OR_NEWER && HDPipeline
            if (m_currentRenderer == GaiaConstants.EnvironmentRenderer.HighDefinition2018x)
            {
                if (m_aboveWaterProfile == null)
                {
                    m_aboveWaterProfile = AssetDatabase.LoadAssetAtPath <VolumeProfile>(GaiaPipelineUtils.GetAssetPath("Gaia HDRP Post Processing Profile"));
                }

                if (m_underwaterProfile == null)
                {
                    m_underwaterProfile = AssetDatabase.LoadAssetAtPath <VolumeProfile>(GaiaPipelineUtils.GetAssetPath("Gaia HDRP Underwater Post Processing Profile"));
                }
            }
#endif
#endif

            if (m_currentRenderer == GaiaConstants.EnvironmentRenderer.HighDefinition2018x)
            {
                GameObject volumeObject = GameObject.Find("High Definition Environment Volume");
                if (volumeObject != null)
                {
#if !UNITY_2019_1_OR_NEWER && HDPipeline
                    if (volume == null)
                    {
                        volume = GameObject.Find("High Definition Environment Volume").GetComponent <Volume>();
                        if (volume != null)
                        {
                            VolumeProfile profile = volume.sharedProfile;
                            if (profile != null)
                            {
                                VolumetricFog fog;
                                if (profile.TryGet(out fog))
                                {
                                    storedFogColor    = fog.albedo.value;
                                    storedFogDistance = fog.meanFreePath.value;
                                }
                            }
                        }
                    }
#endif
                }
                else
                {
                    Debug.LogWarning("Unabled to find a HDRP environment volume in the scene. Please insure one is set in this scene.");
                }
            }

#if UNITY_2019_1_OR_NEWER && HDPipeline
            postVolume = GameObject.Find("Gaia HDRP Post Processing").GetComponent <Volume>();
#endif
        }