/// <summary> /// Returns terrain names of terrains that intersect with the given bounds object /// </summary> /// <param name="bounds">A bounds object to check against the terrains. Needs to be in absolute world space position, mind the current origin offset!</param> /// <returns></returns> public static string[] GetTerrainsIntersectingBounds(BoundsDouble bounds) { //Reduce the bounds size a bit to prevent selecting terrains that are perfectly aligned with the bounds border //-this leads to too many terrains being logged as affected by an operation otherwise. Bounds intersectingBounds = new BoundsDouble(); intersectingBounds.center = bounds.center; intersectingBounds.size = bounds.size - new Vector3Double(0.001f, 0.001f, 0.001f); if (GaiaUtils.HasDynamicLoadedTerrains()) { GaiaSessionManager sessionManager = GaiaSessionManager.GetSessionManager(); if (sessionManager == null) { Debug.LogError("Trying to get terrains that intersect with bounds, but there is no session manager in scene."); return(null); } return(TerrainLoaderManager.TerrainScenes.Where(x => x.m_bounds.Intersects(intersectingBounds)).Select(x => x.GetTerrainName()).ToArray()); } else { List <string> affectedTerrainNames = new List <string>(); foreach (Terrain t in Terrain.activeTerrains) { if (intersectingBounds.Intersects(TerrainHelper.GetWorldSpaceBounds(t))) { affectedTerrainNames.Add(t.name); } } return(affectedTerrainNames.ToArray()); } }
/// <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); } } } }
public override void OnInspectorGUI() { if (redStyle == null || redStyle.normal.background == null || greenStyle == null || greenStyle.normal.background == null) { redStyle = new GUIStyle(); redStyle.normal.background = GaiaUtils.GetBGTexture(Color.red, m_tempTextureList); greenStyle = new GUIStyle(); greenStyle.normal.background = GaiaUtils.GetBGTexture(Color.green, m_tempTextureList); } //Init editor utils if (m_editorUtils == null) { // Get editor utils for this m_editorUtils = PWApp.GetEditorUtils(this); } m_editorUtils.Initialize(); // Do not remove this! if (GaiaUtils.HasDynamicLoadedTerrains()) { m_editorUtils.Panel("GeneralSettings", DrawGeneralSettings, true); m_editorUtils.Panel("LoaderPanel", DrawLoaders, false); m_editorUtils.Panel("PlaceholderPanel", DrawTerrains, false); } else { EditorGUILayout.HelpBox(m_editorUtils.GetTextValue("NoTerrainLoadingMessage"), MessageType.Info); } }
public static Stamper GetOrCreateSyncedStamper(string stamperName) { Stamper stamper = null; //No stamper passed in, does a session Stamper exist? if (stamper == null) { GameObject stamperObj = GameObject.Find(stamperName); if (stamperObj == null) { GameObject wmeTempTools = GaiaUtils.GetOrCreateWorldMapTempTools(); stamperObj = new GameObject(stamperName); stamperObj.transform.parent = wmeTempTools.transform; } if (stamperObj.GetComponent <Stamper>() == null) { stamper = stamperObj.AddComponent <Stamper>(); #if GAIA_PRO_PRESENT if (GaiaUtils.HasDynamicLoadedTerrains()) { //We got placeholders, activate terrain loading stamper.m_loadTerrainMode = LoadMode.EditorSelected; } #endif } stamper = stamperObj.GetComponent <Stamper>(); } return(stamper); }
public static void FinalizePlayerObjectEditor(GameObject playerObj, GaiaSettings gaiaSettings) { if (playerObj != null) { playerObj.transform.SetParent(GaiaUtils.GetPlayerObject().transform); #if UNITY_EDITOR //Adjust the scene view to see the camera if (SceneView.lastActiveSceneView != null) { if (gaiaSettings.m_focusPlayerOnSetup) { SceneView.lastActiveSceneView.LookAtDirect(playerObj.transform.position, playerObj.transform.rotation); } } #endif } GaiaSessionManager session = GaiaSessionManager.GetSessionManager(); if (session != null) { if (session.m_session != null) { if (playerObj.transform.position.y < session.m_session.m_seaLevel) { playerObj.transform.position = new Vector3(playerObj.transform.position.x, session.m_session.m_seaLevel + 5f, playerObj.transform.position.z); } } } #if GAIA_PRO_PRESENT //Add the simple terrain culling script, useful in any case if (GaiaUtils.CheckIfSceneProfileExists()) { GaiaGlobal.Instance.SceneProfile.m_terrainCullingEnabled = true; } #endif bool dynamicLoadedTerrains = GaiaUtils.HasDynamicLoadedTerrains(); if (dynamicLoadedTerrains) { #if GAIA_PRO_PRESENT TerrainLoader loader = playerObj.GetComponent <TerrainLoader>(); if (loader == null) { loader = playerObj.AddComponent <TerrainLoader>(); } loader.LoadMode = LoadMode.RuntimeAlways; float tileSize = 512; if (TerrainLoaderManager.Instance.TerrainSceneStorage.m_terrainTilesSize > 0) { tileSize = TerrainLoaderManager.Instance.TerrainSceneStorage.m_terrainTilesSize; } float size = tileSize * 1.25f * 2f; loader.m_loadingBoundsRegular = new BoundsDouble(playerObj.transform.position, new Vector3(size, size, size)); loader.m_loadingBoundsImpostor = new BoundsDouble(playerObj.transform.position, new Vector3(size * 3f, size * 3f, size * 3f)); loader.m_loadingBoundsCollider = new BoundsDouble(playerObj.transform.position, new Vector3(size, size, size)); #endif } }
public void LoadStamperSettings(Stamper stamper, bool instantiateSettings) { stamper.LoadSettings(m_connectedStamperSettings, instantiateSettings); stamper.m_worldMapStampToken = this; #if GAIA_PRO_PRESENT if (GaiaUtils.HasDynamicLoadedTerrains()) { //We got placeholders, activate terrain loading stamper.m_loadTerrainMode = LoadMode.EditorSelected; } #endif }
public void LookUpLoadingScreen() { #if GAIA_PRO_PRESENT if (m_loadingScreen == null && GaiaUtils.HasDynamicLoadedTerrains()) { var loadingScreens = Resources.FindObjectsOfTypeAll <GaiaLoadingScreen>(); if (loadingScreens.Length > 0) { m_loadingScreen = loadingScreens[0]; } } #endif }
public void SetOriginByTargetTile(int tileX = -99, int tileZ = -99) { if (tileX == -99) { tileX = m_originTargetTileX; } if (tileZ == -99) { tileZ = m_originTargetTileZ; } if (GaiaUtils.HasDynamicLoadedTerrains()) { //Get the terrain tile by X / Z tile in the scene path TerrainScene targetScene = TerrainLoaderManager.TerrainScenes.Find(x => x.m_scenePath.Contains("Terrain_" + tileX.ToString() + "_" + tileZ.ToString())); if (targetScene != null) { SetOrigin(new Vector3Double(targetScene.m_pos.x + (m_terrainSceneStorage.m_terrainTilesSize / 2f), 0f, targetScene.m_pos.z + (m_terrainSceneStorage.m_terrainTilesSize / 2f))); string terrainName = targetScene.GetTerrainName(); GameObject go = GameObject.Find(terrainName); if (go != null) { #if UNITY_EDITOR Selection.activeObject = go; #endif } } else { Debug.LogWarning("Could not find a terrain with the tile coordinates " + tileX.ToString() + "-" + tileZ.ToString() + " in the available terrains. Please check if these coordinates are within the available bounds."); } } else { Terrain t = Terrain.activeTerrains.Where(x => x.name.Contains("Terrain_" + tileX.ToString() + "_" + tileZ.ToString())).First(); if (t != null) { SetOrigin(new Vector3Double(t.transform.position.x + (t.terrainData.size.x / 2f), 0f, t.transform.position.z + (t.terrainData.size.z / 2f))); #if UNITY_EDITOR Selection.activeObject = t.gameObject; #endif } else { Debug.LogWarning("Could not find a terrain with the tile coordinates " + tileX.ToString() + "-" + tileZ.ToString() + " in the scene."); } } }
public void UpdateTerrainLoaderFromProfile(ref TerrainLoader tl) { if (GaiaUtils.HasDynamicLoadedTerrains()) { if (tl != null) { tl.LoadMode = m_terrainLoaderLoadMode; tl.m_minRefreshDistance = m_terrainLoaderMinRefreshDistance; tl.m_maxRefreshDistance = m_terrainLoaderMaxRefreshDistance; tl.m_minRefreshMS = m_terrainLoaderMinRefreshMS; tl.m_maxRefreshMS = m_terrainLoaderMaxRefreshMS; tl.m_followTransform = m_terrainLoaderFollowTransform; tl.m_loadingBoundsRegular = m_terrainLoaderLoadingBoundsRegular; tl.m_loadingBoundsImpostor = m_terrainLoaderLoadingBoundsImpostor; tl.m_loadingBoundsCollider = m_terrainLoaderLoadingBoundsCollider; } } }
/// <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); } } } } }
public void Start() { if (instance == null) { instance = this; } else { if (instance != this) { Destroy(this); } } //Nothing to do if no terrain loading if (!GaiaUtils.HasDynamicLoadedTerrains()) { return; } LookUpLoadingScreen(); //Process the runtime deactivation if the "Collider Only" mode is active if (TerrainSceneStorage.m_colliderOnlyLoading) { DeactivateIfRequested(m_terrainSceneStorage.m_deactivateRuntimePlayer, GaiaConstants.gaiaPlayerObject); DeactivateIfRequested(m_terrainSceneStorage.m_deactivateRuntimeLighting, GaiaConstants.gaiaLightingObject); DeactivateIfRequested(m_terrainSceneStorage.m_deactivateRuntimeAudio, GaiaConstants.gaiaAudioObject); DeactivateIfRequested(m_terrainSceneStorage.m_deactivateRuntimeWeather, GaiaConstants.gaiaWeatherObject); DeactivateIfRequested(m_terrainSceneStorage.m_deactivateRuntimeWater, GaiaConstants.gaiaWaterObject); DeactivateIfRequested(m_terrainSceneStorage.m_deactivateRuntimeScreenShotter, GaiaConstants.gaiaScreenshotter); } UnloadAll(); m_runtimeInitialized = true; #if GAIA_PRO_PRESENT if (m_loadingScreen != null) { m_loadingScreen.gameObject.SetActive(true); } StartTrackingProgress(); #endif }
/// <summary> /// Get the number of active terrain tiles in this scene /// </summary> /// <returns>Number of terrains in the scene</returns> public static int GetActiveTerrainCount() { if (GaiaUtils.HasDynamicLoadedTerrains()) { //with terrain loading, we can simply count the loaded scenes, those should be the active terrains return(TerrainLoaderManager.TerrainScenes.Where(x => x.m_regularLoadState == LoadState.Loaded).Count() + TerrainLoaderManager.TerrainScenes.Where(x => x.m_impostorLoadState == LoadState.Loaded).Count()); } else { //For non-terrain loading we need to take a look at what we can find in the scene //Regular terrains Terrain terrain; int terrainCount = 0; for (int idx = 0; idx < Terrain.activeTerrains.Length; idx++) { terrain = Terrain.activeTerrains[idx]; if (terrain != null && terrain.isActiveAndEnabled) { terrainCount++; } } //Mesh Terrains from a terrain export GameObject exportContainer = GaiaUtils.GetTerrainExportObject(false); if (exportContainer != null) { //Iterate through the objects in here, if it is active and the name checks out we can assume it is a mesh terrain. foreach (Transform t in exportContainer.transform) { if (t.gameObject.GetComponent <MeshRenderer>() != null) { if (t.gameObject.activeInHierarchy && (t.name.StartsWith(GaiaConstants.MeshTerrainName) || t.name.StartsWith(GaiaConstants.MeshTerrainLODGroupPrefix))) { terrainCount++; } } } } return(terrainCount); } }
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); } } } }
public static void FinalizePlayerObjectRuntime(GameObject playerObj) { GaiaSessionManager session = GaiaSessionManager.GetSessionManager(); if (session != null) { if (session.m_session != null) { if (playerObj.transform.position.y < session.m_session.m_seaLevel) { playerObj.transform.position = new Vector3(playerObj.transform.position.x, session.m_session.m_seaLevel + 5f, playerObj.transform.position.z); } } } #if GAIA_PRO_PRESENT //Add the simple terrain culling script, useful in any case if (GaiaUtils.CheckIfSceneProfileExists()) { GaiaGlobal.Instance.SceneProfile.m_terrainCullingEnabled = true; } #endif bool dynamicLoadedTerrains = GaiaUtils.HasDynamicLoadedTerrains(); if (dynamicLoadedTerrains) { #if GAIA_PRO_PRESENT Terrain terrain = TerrainHelper.GetActiveTerrain(); TerrainLoader loader = playerObj.GetComponent <TerrainLoader>(); if (loader == null) { loader = playerObj.AddComponent <TerrainLoader>(); } loader.LoadMode = LoadMode.RuntimeAlways; float size = terrain.terrainData.size.x * 1.25f * 2f; loader.m_loadingBoundsRegular = new BoundsDouble(playerObj.transform.position, new Vector3(size, size, size)); loader.m_loadingBoundsImpostor = new BoundsDouble(playerObj.transform.position, new Vector3(size * 3f, size * 3f, size * 3f)); #endif } }
/// <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); } } } }
/// <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); } } } } }
private void GlobalSettings(bool helpEnabled) { if (GaiaGlobal.Instance.SceneProfile.m_lightingProfiles.Count > 0) { if (m_profile.m_selectedLightingProfileValuesIndex != -99) { profile = GaiaGlobal.Instance.SceneProfile.m_lightingProfiles[m_profile.m_selectedLightingProfileValuesIndex]; } } if (m_gaiaSettings.m_currentRenderer == GaiaConstants.EnvironmentRenderer.BuiltIn) { bool postfx = m_profile.m_setupPostFX; m_profile.m_setupPostFX = m_editorUtils.Toggle("SetupPostFX", m_profile.m_setupPostFX, helpEnabled); if (postfx != m_profile.m_setupPostFX) { if (m_profile.m_setupPostFX) { if (profile != null) { GaiaLighting.SetupPostProcessing(profile, m_profile, GaiaUtils.GetActivePipeline(), true); } } else { GaiaLighting.RemoveAllPostProcessV2CameraLayer(); } } } m_profile.m_spawnPlayerAtCurrentLocation = m_editorUtils.Toggle("SpawnPlayerAtCurrentLocation", m_profile.m_spawnPlayerAtCurrentLocation, helpEnabled); GaiaConstants.EnvironmentControllerType controller = m_profile.m_controllerType; controller = (GaiaConstants.EnvironmentControllerType)m_editorUtils.EnumPopup("ControllerType", controller, helpEnabled); if (controller != m_profile.m_controllerType) { m_gaiaSettings.m_currentController = controller; switch (controller) { case GaiaConstants.EnvironmentControllerType.FirstPerson: GaiaSceneManagement.CreatePlayer(m_gaiaSettings, GaiaConstants.playerFirstPersonName, m_profile.m_spawnPlayerAtCurrentLocation, null, null, true); break; case GaiaConstants.EnvironmentControllerType.FlyingCamera: GaiaSceneManagement.CreatePlayer(m_gaiaSettings, GaiaConstants.playerFlyCamName, m_profile.m_spawnPlayerAtCurrentLocation, null, null, true); break; case GaiaConstants.EnvironmentControllerType.ThirdPerson: GaiaSceneManagement.CreatePlayer(m_gaiaSettings, GaiaConstants.playerThirdPersonName, m_profile.m_spawnPlayerAtCurrentLocation, null, null, true); break; case GaiaConstants.EnvironmentControllerType.Car: GaiaSceneManagement.CreatePlayer(m_gaiaSettings, GaiaConstants.m_carPlayerPrefabName, m_profile.m_spawnPlayerAtCurrentLocation, null, null, true); break; case GaiaConstants.EnvironmentControllerType.XRController: #if GAIA_XR GaiaSceneManagement.CreatePlayer(m_gaiaSettings, "XRController", m_profile.m_spawnPlayerAtCurrentLocation); #else EditorUtility.DisplayDialog("XR Support not enabled", "The XR Controller is a default player for Virtual / Augmented Reality projects. Please open the Setup Panel in the Gaia Manager Standard Tab to enable XR Support in order to use the XR Player Controller. Please also make sure you have the Unity XR Interaction Toolkit package installed before doing so.", "OK"); controller = GaiaConstants.EnvironmentControllerType.FlyingCamera; m_gaiaSettings.m_currentController = GaiaConstants.EnvironmentControllerType.FlyingCamera; #endif break; } SetPostProcessing(profile); #if GAIA_PRO_PRESENT if (GaiaUtils.HasDynamicLoadedTerrains()) { TerrainLoader tl = ((GaiaScenePlayer)target).GetComponentInChildren <TerrainLoader>(); if (tl != null) { m_profile.UpdateTerrainLoaderFromProfile(ref tl); } } #endif m_profile.m_controllerType = controller; } if (controller == GaiaConstants.EnvironmentControllerType.Custom) { m_profile.m_customPlayer = (GameObject)m_editorUtils.ObjectField("MainPlayer", m_profile.m_customPlayer, typeof(GameObject), true, helpEnabled); m_profile.m_customCamera = (Camera)m_editorUtils.ObjectField("MainCamera", m_profile.m_customCamera, typeof(Camera), true, helpEnabled); if (m_editorUtils.Button("ApplySetup")) { GaiaSceneManagement.CreatePlayer(m_gaiaSettings, "Custom", m_profile.m_spawnPlayerAtCurrentLocation, m_profile.m_customPlayer, m_profile.m_customCamera, true); SetPostProcessing(profile); #if GAIA_PRO_PRESENT if (GaiaUtils.HasDynamicLoadedTerrains()) { TerrainLoader tl = ((GaiaScenePlayer)target).GetComponentInChildren <TerrainLoader>(); if (tl != null) { m_profile.UpdateTerrainLoaderFromProfile(ref tl); } } #endif } } EditorGUILayout.BeginHorizontal(); if (m_editorUtils.Button("MoveCameraToPlayer")) { GaiaSceneManagement.MoveCameraToPlayer(m_gaiaSettings); } if (m_editorUtils.Button("MovePlayerToCamera")) { GaiaSceneManagement.MovePlayerToCamera(m_gaiaSettings); } EditorGUILayout.EndHorizontal(); EditorGUILayout.Space(); m_editorUtils.Panel("AutoDepthOfFieldSettings", AutoDepthOfField); m_editorUtils.Panel("LocationManagerSettings", LocationManagerSettings); m_editorUtils.Panel("PlayerCameraCullingSettings", CameraCullingSettings); if (GaiaUtils.HasDynamicLoadedTerrains()) { m_editorUtils.Panel("TerrainLoadingSettings", TerrainLoadingSettings); } }
/// <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; } }
/// <summary> /// Draws the data fields for each operation /// </summary> /// <param name="op"></param> public static void DrawOperationFields(GaiaOperation op, EditorUtils editorUtils, GaiaSessionManager sessionManager, bool helpEnabled, int currentIndex) { //shared default fields first //op.m_isActive = m_editorUtils.Toggle("Active", op.m_isActive, helpEnabled); bool currentGUIState = GUI.enabled; GUI.enabled = op.m_isActive; op.m_description = editorUtils.TextField("Description", op.m_description, helpEnabled); editorUtils.LabelField("DateTime", new GUIContent(op.m_operationDateTime), helpEnabled); EditorGUI.indentLevel++; op.m_terrainsFoldedOut = editorUtils.Foldout(op.m_terrainsFoldedOut, "AffectedTerrains", helpEnabled); if (op.m_terrainsFoldedOut) { foreach (string name in op.m_affectedTerrainNames) { EditorGUILayout.LabelField(name); } } EditorGUI.indentLevel--; //type specific fields, switch by op type to draw additional fields suitable for the op type switch (op.m_operationType) { case GaiaOperation.OperationType.CreateWorld: editorUtils.LabelField("xTiles", new GUIContent(op.WorldCreationSettings.m_xTiles.ToString()), helpEnabled); editorUtils.LabelField("zTiles", new GUIContent(op.WorldCreationSettings.m_zTiles.ToString()), helpEnabled); editorUtils.LabelField("TileSize", new GUIContent(op.WorldCreationSettings.m_tileSize.ToString()), helpEnabled); break; case GaiaOperation.OperationType.Spawn: editorUtils.LabelField("NumberOfSpawners", new GUIContent(op.SpawnOperationSettings.m_spawnerSettingsList.Count.ToString()), helpEnabled); float size = (float)Mathd.Max(op.SpawnOperationSettings.m_spawnArea.size.x, op.SpawnOperationSettings.m_spawnArea.size.z); editorUtils.LabelField("SpawnSize", new GUIContent(size.ToString()), helpEnabled); break; } GUI.enabled = currentGUIState; //Button controls EditorGUILayout.BeginHorizontal(); GUILayout.Space(20); if (editorUtils.Button("Delete")) { if (EditorUtility.DisplayDialog(editorUtils.GetTextValue("PopupDeleteTitle"), editorUtils.GetTextValue("PopupDeleteText"), editorUtils.GetTextValue("OK"), editorUtils.GetTextValue("Cancel"))) { try { if (!String.IsNullOrEmpty(op.scriptableObjectAssetGUID)) { AssetDatabase.DeleteAsset(AssetDatabase.GUIDToAssetPath(op.scriptableObjectAssetGUID)); } } catch (Exception ex) { Debug.LogError("Error while deleting one of the operation data files: " + ex.Message + " Stack Trace:" + ex.StackTrace); } sessionManager.RemoveOperation(currentIndex); EditorGUIUtility.ExitGUI(); } } GUI.enabled = op.m_isActive; if (editorUtils.Button("Play")) { if (EditorUtility.DisplayDialog(editorUtils.GetTextValue("PopupPlayTitle"), editorUtils.GetTextValue("PopupPlayText"), editorUtils.GetTextValue("OK"), editorUtils.GetTextValue("Cancel"))) { GaiaSessionManager.ExecuteOperation(op); //Destroy all temporary tools used while executing //not if it is a spawn operation since that is asynchronous if (op.m_operationType != GaiaOperation.OperationType.Spawn) { GaiaSessionManager.DestroyTempSessionTools(); } } } GUI.enabled = currentGUIState; //EditorGUILayout.EndHorizontal(); //EditorGUILayout.BeginHorizontal(); //GUILayout.Space(20); if (editorUtils.Button("ViewData")) { switch (op.m_operationType) { case GaiaOperation.OperationType.CreateWorld: Selection.activeObject = op.WorldCreationSettings; break; case GaiaOperation.OperationType.Stamp: Selection.activeObject = op.StamperSettings; break; case GaiaOperation.OperationType.Spawn: Selection.activeObject = op.SpawnOperationSettings; break; case GaiaOperation.OperationType.FlattenTerrain: Selection.activeObject = op.FlattenOperationSettings; break; case GaiaOperation.OperationType.StampUndo: Selection.activeObject = op.UndoRedoOperationSettings; break; case GaiaOperation.OperationType.StampRedo: Selection.activeObject = op.UndoRedoOperationSettings; break; case GaiaOperation.OperationType.ClearSpawns: Selection.activeObject = op.ClearOperationSettings; break; case GaiaOperation.OperationType.RemoveNonBiomeResources: Selection.activeObject = op.RemoveNonBiomeResourcesSettings; break; case GaiaOperation.OperationType.MaskMapExport: Selection.activeObject = op.ExportMaskMapOperationSettings; break; } EditorGUIUtility.PingObject(Selection.activeObject); } switch (op.m_operationType) { case GaiaOperation.OperationType.Stamp: if (editorUtils.Button("PreviewInStamper")) { Stamper stamper = GaiaSessionManager.GetOrCreateSessionStamper(); stamper.LoadSettings(op.StamperSettings); #if GAIA_PRO_PRESENT if (GaiaUtils.HasDynamicLoadedTerrains()) { //We got placeholders, activate terrain loading stamper.m_loadTerrainMode = LoadMode.EditorSelected; } #endif Selection.activeObject = stamper.gameObject; } break; case GaiaOperation.OperationType.Spawn: if (editorUtils.Button("PreviewInSpawner")) { BiomeController bmc = null; List <Spawner> spawnerList = null; Selection.activeObject = GaiaSessionManager.GetOrCreateSessionSpawners(op.SpawnOperationSettings, ref bmc, ref spawnerList); } break; case GaiaOperation.OperationType.MaskMapExport: #if GAIA_PRO_PRESENT if (editorUtils.Button("PreviewInExport")) { MaskMapExport mme = null; Selection.activeObject = GaiaSessionManager.GetOrCreateMaskMapExporter(op.ExportMaskMapOperationSettings.m_maskMapExportSettings, ref mme); } #endif break; } EditorGUILayout.EndHorizontal(); }
/// <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); } } }
/// <summary> /// Get the bounds of the terrain at this location or fail with a null /// </summary> /// <param name="locationWU">Location to check and get terrain for</param> /// <returns>Bounds of selected terrain or null if invalid for some reason</returns> public static bool GetTerrainBounds(ref BoundsDouble bounds, bool activeTerrainsOnly = false) { //Terrain terrain = GetTerrain(locationWU); //if (terrain == null) //{ // return false; //} //bounds.center = terrain.transform.position; //bounds.size = terrain.terrainData.size; //bounds.center += bounds.extents; Vector3Double accumulatedCenter = new Vector3Double(); //Do we use dynamic loaded terrains in the scene? if (GaiaUtils.HasDynamicLoadedTerrains() && !activeTerrainsOnly) { #if GAIA_PRO_PRESENT //we do have dynamic terrains -> calculate the bounds according to the terrain scene data in the session GaiaSessionManager gsm = GaiaSessionManager.GetSessionManager(false); foreach (TerrainScene t in TerrainLoaderManager.TerrainScenes) { accumulatedCenter += t.m_bounds.center; } bounds.center = accumulatedCenter / TerrainLoaderManager.TerrainScenes.Count; foreach (TerrainScene t in TerrainLoaderManager.TerrainScenes) { bounds.Encapsulate(t.m_bounds); } #endif } else { //no placeholder -> calculate bounds according to the active terrains in the scene if (Terrain.activeTerrains.Length > 0) { foreach (Terrain t in Terrain.activeTerrains) { if (!TerrainHelper.IsWorldMapTerrain(t)) { if (t.terrainData != null) { accumulatedCenter += new Vector3Double(t.transform.position) + new Vector3Double(t.terrainData.bounds.extents); } else { Debug.LogWarning("Terrain " + t.name + " in the scene is missing the terrain data object!"); } } } bounds.center = accumulatedCenter / Terrain.activeTerrains.Length; foreach (Terrain t in Terrain.activeTerrains) { if (!TerrainHelper.IsWorldMapTerrain(t)) { if (t.terrainData != null) { Bounds newBounds = new Bounds(); newBounds.center = t.transform.position; newBounds.size = t.terrainData.size; newBounds.center += t.terrainData.bounds.extents; bounds.Encapsulate(newBounds); } } } } else { bounds = new BoundsDouble(Vector3Double.zero, Vector3Double.zero); //No active terrains? There might be mesh terrains we can use then GameObject meshTerrainExportObject = GaiaUtils.GetTerrainExportObject(false); if (meshTerrainExportObject != null) { foreach (Transform t in meshTerrainExportObject.transform) { MeshRenderer mr = t.GetComponent <MeshRenderer>(); if (mr != null) { bounds.Encapsulate(mr.bounds); } } } } } return(true); }