Beispiel #1
0
        /// <summary>
        /// Clears reflection probes created
        /// </summary>
        public static void ClearCreatedReflectionProbes()
        {
            GameObject oldReflectionProbe = GameObject.Find("Global Reflection Probe");

            if (oldReflectionProbe != null)
            {
                UnityEngine.Object.DestroyImmediate(oldReflectionProbe);
                Debug.Log("Old Reflection Probe Destroyed");
            }

            if (GaiaUtils.HasDynamicLoadedTerrains())
            {
                Action <Terrain> terrAction = (t) => DeleteProbeGroup(t);
                GaiaUtils.CallFunctionOnDynamicLoadedTerrains(terrAction, true, null, "Clearning Reflection Probes");
            }
            else
            {
                if (Terrain.activeTerrains.Length < 1)
                {
                    Debug.LogError("No terrains we're found, unable to generate reflection probes.");
                }
                else
                {
                    foreach (var activeTerrain in Terrain.activeTerrains)
                    {
                        DeleteProbeGroup(activeTerrain);
                    }
                }
            }
        }
Beispiel #2
0
        /// <summary>
        /// Setup for the automatically probe spawning
        /// </summary>
        /// <param name="profile"></param>
        public static void CreateAutomaticProbes(ReflectionProbeData profile)
        {
            int numberTerrains = Terrain.activeTerrains.Length;

            if (numberTerrains == 0)
            {
                Debug.LogError("Unable to initiate probe spawning systen. No terrain found");
            }
            else
            {
                if (profile.lightProbesPerRow < 2)
                {
                    Debug.LogError("Please set Light Probes Per Row to a value of 2 or higher");
                }
                else
                {
                    LoadProbesFromScene();

                    m_probeLocations = null;
                    ClearCreatedLightProbes();

                    float seaLevel = 0f;

                    PWS_WaterSystem gaiawater = GameObject.FindObjectOfType <PWS_WaterSystem>();
                    if (gaiawater != null)
                    {
                        seaLevel = gaiawater.SeaLevel;
                    }

                    if (GaiaUtils.HasDynamicLoadedTerrains())
                    {
                        Action <Terrain> terrAction = (t) => GenerateProbesOnTerrain(t, profile, seaLevel);
                        GaiaUtils.CallFunctionOnDynamicLoadedTerrains(terrAction, true, null, "Generating Light Probes");
                    }
                    else
                    {
                        foreach (var activeTerrain in Terrain.activeTerrains)
                        {
                            GenerateProbesOnTerrain(activeTerrain, profile, seaLevel);
                        }
                    }
                }
            }
        }
Beispiel #3
0
        public void SyncLocalMapToWorldMap()
        {
            BoundsDouble bounds = new BoundsDouble();

            TerrainHelper.GetTerrainBounds(ref bounds);
            if (GaiaUtils.HasDynamicLoadedTerrains())
            {
                Action <Terrain> act = (t) => CopyLocalMapToWorldMap(bounds, t);
                GaiaUtils.CallFunctionOnDynamicLoadedTerrains(act, false);
            }
            else
            {
                foreach (Terrain t in Terrain.activeTerrains)
                {
                    if (t != m_worldMapTerrain)
                    {
                        CopyLocalMapToWorldMap(bounds, t);
                    }
                }
            }
        }
Beispiel #4
0
 /// <summary>
 /// Clears reflection probes created
 /// </summary>
 public static void ClearCreatedLightProbes()
 {
     if (GaiaUtils.HasDynamicLoadedTerrains())
     {
         Action <Terrain> terrAction = (t) => DeleteProbeGroup(t);
         GaiaUtils.CallFunctionOnDynamicLoadedTerrains(terrAction, true, null, "Clearing Light Probes");
     }
     else
     {
         if (Terrain.activeTerrains.Length < 1)
         {
             Debug.LogError("No terrains we're found, unable to clear light probes.");
         }
         else
         {
             foreach (var activeTerrain in Terrain.activeTerrains)
             {
                 DeleteProbeGroup(activeTerrain);
             }
         }
     }
 }
Beispiel #5
0
        /// <summary>
        /// Syncs the heightmap of the world map to the local terrain tiles, preserving correct height scale, heightmap resolution, etc.
        /// </summary>
        /// <param name="validLocalTerrainNames">A list of local terrain tile names that are valid to change for the sync operation. If the list is null, all tiles will be assumed valid.</param>
        public void SyncWorldMapToLocalMap(List <string> validLocalTerrainNames = null)
        {
            BoundsDouble bounds = new BoundsDouble();

            TerrainHelper.GetTerrainBounds(ref bounds);
            if (GaiaUtils.HasDynamicLoadedTerrains())
            {
                Action <Terrain> act = (t) => CopyWorldMapToLocalMap(bounds, t);
                GaiaUtils.CallFunctionOnDynamicLoadedTerrains(act, false, validLocalTerrainNames);
            }
            else
            {
                foreach (Terrain t in Terrain.activeTerrains)
                {
                    if (t != m_worldMapTerrain)
                    {
                        if (validLocalTerrainNames == null || validLocalTerrainNames.Contains(t.name))
                        {
                            CopyWorldMapToLocalMap(bounds, t);
                        }
                    }
                }
            }
        }
Beispiel #6
0
        /// <summary>
        /// Setup for the automatically probe spawning
        /// </summary>
        /// <param name="reflectionProbeData"></param>
        public static void CreateAutomaticProbes(ReflectionProbeData reflectionProbeData, GaiaConstants.EnvironmentRenderer renderPipelineSettings)
        {
            if (reflectionProbeData == null)
            {
                return;
            }

            if (reflectionProbeData.reflectionProbeRefresh == GaiaConstants.ReflectionProbeRefreshModePW.ProbeManager && reflectionProbeData.reflectionProbeMode == ReflectionProbeMode.Realtime)
            {
#if GAIA_PRO_PRESENT
                ReflectionProbeManager manager = ReflectionProbeManager.GetOrCreateProbeManager();
                if (manager != null)
                {
                    manager.ProbeLayerMask = reflectionProbeData.reflectionprobeCullingMask;
                }
#endif
            }
            else
            {
#if GAIA_PRO_PRESENT
                ReflectionProbeManager.RemoveReflectionProbeManager();
#endif
            }

            ClearCreatedReflectionProbes();

            GameObject oldReflectionProbe = GameObject.Find("Global Reflection Probe");
            if (oldReflectionProbe != null)
            {
                UnityEngine.Object.DestroyImmediate(oldReflectionProbe);
                Debug.Log("Old Reflection Probe Destroyed");
            }

            if (reflectionProbeData.reflectionProbesPerRow < 2)
            {
                Debug.LogError("Please set Probes Per Row to a value of 2 or higher");
            }
            else
            {
                m_currentProbeCount = 0;

                float seaLevel       = 0f;
                bool  seaLevelActive = false;

                PWS_WaterSystem gaiawater = GameObject.FindObjectOfType <PWS_WaterSystem>();
                if (gaiawater != null)
                {
                    seaLevel       = gaiawater.SeaLevel;
                    seaLevelActive = true;
                }

                if (GaiaUtils.HasDynamicLoadedTerrains())
                {
                    Action <Terrain> terrAction = (t) => GenerateProbesOnTerrain(t, reflectionProbeData, seaLevelActive, seaLevel, renderPipelineSettings);
                    GaiaUtils.CallFunctionOnDynamicLoadedTerrains(terrAction, true, null, "Generating Reflection Probes");
                }
                else
                {
                    if (Terrain.activeTerrains.Length < 1)
                    {
                        Debug.LogError("No terrains we're found, unable to generate reflection probes.");
                    }
                    else
                    {
                        foreach (var activeTerrain in Terrain.activeTerrains)
                        {
                            GenerateProbesOnTerrain(activeTerrain, reflectionProbeData, seaLevelActive, seaLevel, renderPipelineSettings);
                        }
                    }
                }
                m_probeRenderActive = true;
            }
        }
Beispiel #7
0
        /// <summary>
        /// Clear all the trees on all the terrains
        /// </summary>
        public static void ClearSpawns(SpawnerResourceType resourceType, ClearSpawnFor clearSpawnFor, ClearSpawnFrom clearSpawnFrom, List <string> terrainNames = null, Spawner spawner = null)
        {
            if (terrainNames == null)
            {
                if (clearSpawnFor == ClearSpawnFor.AllTerrains)
                {
                    if (GaiaUtils.HasDynamicLoadedTerrains())
                    {
                        GaiaSessionManager sessionManager = GaiaSessionManager.GetSessionManager();
                        terrainNames = TerrainLoaderManager.TerrainScenes.Select(x => x.GetTerrainName()).ToList();
                    }
                    else
                    {
                        terrainNames = Terrain.activeTerrains.Select(x => x.name).ToList();
                    }
                }
                else
                {
                    terrainNames = new List <string> {
                        spawner.GetCurrentTerrain().name
                    };
                }
            }

            string progressBarTitle = "Clearing...";

            Action <Terrain> act = null;

            switch (resourceType)
            {
            case SpawnerResourceType.TerrainTexture:
                progressBarTitle = "Clearing Textures";
                //Not supported, should not be required
                throw new NotSupportedException("Clearing of Textures is currently not supported via the terrain helper");

            case SpawnerResourceType.TerrainDetail:
                progressBarTitle = "Clearing Terrain Details";
                act = (t) => ClearDetailsOnSingleTerrain(t, spawner, clearSpawnFrom);
                break;

            case SpawnerResourceType.TerrainTree:
                progressBarTitle = "Clearing Trees";
                act = (t) => ClearTreesOnSingleTerrain(t, spawner, clearSpawnFrom);
                break;

            case SpawnerResourceType.GameObject:
                progressBarTitle = "Clearing Game Objects";
                act = (t) => ClearGameObjectsOnSingleTerrain(t, spawner, clearSpawnFrom);
                break;

            case SpawnerResourceType.Probe:
                progressBarTitle = "Clearing Probes";
                act = (t) => ClearGameObjectsOnSingleTerrain(t, spawner, clearSpawnFrom);
                break;

            case SpawnerResourceType.SpawnExtension:
                progressBarTitle = "Clearing Spawn Extensions";
                act = (t) => ClearSpawnExtensionsOnSingleTerrain(t, spawner, clearSpawnFrom);
                break;

            case SpawnerResourceType.StampDistribution:
                //Not supported, should not be required
                throw new NotSupportedException("Clearing of Stamps is currently not supported via the terrain helper");
            }

            if (GaiaUtils.HasDynamicLoadedTerrains())
            {
                GaiaUtils.CallFunctionOnDynamicLoadedTerrains(act, true, terrainNames);
            }
            else
            {
                for (int idx = 0; idx < terrainNames.Count; idx++)
                {
                    ProgressBar.Show(ProgressBarPriority.Spawning, progressBarTitle, progressBarTitle, idx + 1, terrainNames.Count(), true);

                    GameObject go = GameObject.Find(terrainNames[idx]);
                    if (go != null)
                    {
                        Terrain terrain = go.GetComponent <Terrain>();
                        act(terrain);
                    }
                    ProgressBar.Clear(ProgressBarPriority.Spawning);
                }
            }
        }