/// <summary> /// Load a template but delay short period of time after updating /// the infoPanel text to force it to be displayed /// For URP/LWRP/HDRP all trees will be forced to be billboarded /// as currently we are only using built-in SRP trees. /// </summary> /// <param name="templateNumber"></param> /// <returns></returns> IEnumerator LoadTemplateWithUIDelay(int templateNumber) { bool showSRPWarning = false; if (lbTemplates != null) { int numTemplates = lbTemplates.Length; if (templateNumber < numTemplates) { LBTemplate lbTemplate = lbTemplates[templateNumber]; if (lbTemplate != null) { // Disable buttons EnableButton(quality1Button, false); EnableButton(quality2Button, false); EnableButton(quality3Button, false); EnableButton(quality4Button, false); EnableButton(infoButton, false); EnableButton(gpuButton, false); DisplayBackgroundPanel(true); currentTemplateName = lbTemplate.name; SetInfoTitle("Loading Template... PLEASE WAIT"); string infoText = "Applying template... "; SetInfoText(infoText); DisplayInfoPanel(true); yield return(new WaitForSeconds(0.1f)); // Remove any camera animators LBCameraAnimator.RemoveCameraAnimatorsFromScene(lbLandscape, false); yield return(new WaitForSeconds(0.1f)); // if LBLighting is in the scene, remove all references to terrains to // prevent errors when the current landscape is deleted. LBLighting lbLighting = GameObject.FindObjectOfType <LBLighting>(); if (lbLighting != null) { lbLighting.ClearAllTerrains(); } if (lbLandscape != null) { DestroyImmediate(lbLandscape.gameObject); } lbLandscape = lbTemplate.CreateLandscapeFromTemplate("DemoLandscape"); Camera mainCamera = Camera.main; if (mainCamera != null) { mainCamera.transform.position = new Vector3(2000f, 2000f, 0f); mainCamera.transform.LookAt(lbLandscape.transform); } // Currently, when applying template ignore water if LWRP, URP or HDRP are enabled // This could be updated if we had a LWRP/HDRP-compatible water asset if (lbTemplate.ApplyTemplateToLandscape(lbLandscape, ignoreStartPosition, true, (isURP || isLWRP || isHDRP) ? null : waterPrefab, true)) { infoText += "DONE\n\n"; SetInfoText(infoText); yield return(new WaitForSeconds(0.1f)); lbLandscape.showTiming = false; lbLandscape.SetLandscapeTerrains(true); // Build the landscape int numTerrains = (lbLandscape.landscapeTerrains == null ? 0 : lbLandscape.landscapeTerrains.Length); if (numTerrains > 0) { // Our older templates don't use GPU for Topography and Path. If it is fully capable // of using the GPU, list it here. bool isModernTemplate = lbTemplate.name.StartsWith("DemoStoneCottage"); // Override the template GPU settings lbLandscape.useGPUTopography = isModernTemplate ? enableGPU : false; lbLandscape.useGPUTexturing = enableGPU; lbLandscape.useGPUGrass = enableGPU; lbLandscape.useGPUPath = isModernTemplate ? enableGPU : false; // Check for URP/LWRP/HDRP or do we need to create a default material for U2019.2.0 or newer if (isURP || isLWRP || isHDRP || is201920Plus) { float pixelError = 0f; Terrain terrain = null; LBLandscape.TerrainMaterialType terrainMaterialType = isURP ? LBLandscape.TerrainMaterialType.URP : (isLWRP ? LBLandscape.TerrainMaterialType.LWRP : (terrainMaterialType = isHDRP ? LBLandscape.TerrainMaterialType.HDRP : LBLandscape.TerrainMaterialType.BuiltInStandard)); for (int tIdx = 0; tIdx < numTerrains; tIdx++) { terrain = lbLandscape.landscapeTerrains[tIdx]; lbLandscape.SetTerrainMaterial(terrain, tIdx, (tIdx == numTerrains - 1), terrain.terrainData.size.x, ref pixelError, terrainMaterialType); // For URP/LWRP/HDRP all trees will be forced to be billboarded // as currently we are only using built-in SRP trees. if (isURP || isLWRP || isHDRP) { // Force all trees to be billboards terrain.treeBillboardDistance = 0f; terrain.treeMaximumFullLODCount = 0; showSRPWarning = true; } } } // These are the cut-down versions without progress bars and minimal validation infoText += "Building Topography" + (lbLandscape.useGPUTopography ? " (GPU)..." : "..."); SetInfoText(infoText); yield return(new WaitForSeconds(0.1f)); lbLandscape.ApplyTopography(true, true); infoText += "DONE\n\n"; infoText += "Adding Textures" + (lbLandscape.useGPUTexturing ? " (GPU)..." : "..."); SetInfoText(infoText); yield return(new WaitForSeconds(0.1f)); lbLandscape.ApplyTextures(true, true); infoText += "DONE\n\n"; infoText += "Placing Trees... "; SetInfoText(infoText); yield return(new WaitForSeconds(0.1f)); lbLandscape.ApplyTrees(true, true); infoText += "DONE\n\n"; infoText += "Placing Grass" + (lbLandscape.useGPUGrass ? " (GPU)..." : "..."); SetInfoText(infoText); yield return(new WaitForSeconds(0.1f)); lbLandscape.ApplyGrass(true, true); infoText += "DONE\n\n"; SetInfoText(infoText); yield return(new WaitForSeconds(0.1f)); if (lbLandscape.lbGroupList != null && lbLandscape.lbGroupList.Count > 0) { infoText += "Placing Groups" + (lbLandscape.useGPUTopography ? " (GPU)..." : "..."); SetInfoText(infoText); yield return(new WaitForSeconds(0.1f)); lbLandscape.ApplyGroups(false, false); } // Apply lighting last as it needs the Camera Paths (and Animator camera to set up WeatherFX) if (lbTemplate.isLBLightingIncluded) { infoText += "Applying lighting... "; SetInfoText(infoText); yield return(new WaitForSeconds(0.1f)); //if (lbLighting != null) { DestroyImmediate(lbLighting.gameObject); } if (lbLighting == null) { // If LBLighting isn't already in the scene, add it. lbLighting = LBLighting.AddLightingToScene(true); } if (lbLighting != null) { // Restore the lighting settings from the template lbTemplate.ApplyLBLightingSettings(lbLandscape, ref lbLighting, mainCamera, true); } infoText += "DONE\n\n"; SetInfoText(infoText); yield return(new WaitForSeconds(0.1f)); // Prior to Unity 5.4, ImageFX and/or camera clear flags are not updated correctly // when the WeatherFX with celestials is added to the scene after a configuration without // celestials. The workaround, is to force the GameView to repaint or be re-initalised. // To be effective, a "reasonable" delay is required between switching away from Game view // and back. The exact cause of the issue is unknown... #if !UNITY_5_4_OR_NEWER && UNITY_EDITOR if (lbLighting.useCelestials) { bool wasMaximized = LBEditorHelper.GameViewMaximize(this.GetType(), false); LBEditorHelper.ShowSceneView(this.GetType(), true); yield return(new WaitForSeconds(0.5f)); LBEditorHelper.GameViewMaximize(this.GetType(), wasMaximized); } #endif } // Find the first animation and start it (there should be only one in a demo template) LBCameraAnimator lbCameraAnimator = LBCameraAnimator.GetFirstCameraAnimatorInLandscape(lbLandscape); if (lbCameraAnimator != null) { if (lbTemplate.name.StartsWith("FPS Forest Demo")) { // This uses the old Unity 4 trees which don't work so well with anti-aliasing QualitySettings.antiAliasing = 0; if (lbCameraAnimator.animatorCamera != null) { lbCameraAnimator.SetMoveSpeed(2f); lbCameraAnimator.animatorCamera.renderingPath = RenderingPath.Forward; lbCameraAnimator.animateSpeed = false; } } else if (lbTemplate.name.StartsWith("DemoStoneCottage")) { lbCameraAnimator.minMoveSpeed = 1f; lbCameraAnimator.maxMoveSpeed = 3f; lbCameraAnimator.animateSpeed = true; } else { lbCameraAnimator.animateSpeed = true; } // Reset LBImageFX timing so clouds always appear the same if (lbCameraAnimator.animatorCamera != null) { LBImageFX lbImageFX = lbCameraAnimator.animatorCamera.GetComponent <LBImageFX>(); if (lbImageFX != null) { //Debug.Log("LBDemoLoader.LoadTemplateWithUIDelay - Resetting LBImageFX cloud positions"); lbImageFX.ResetCloudPosition(); } } //Debug.Log("LBDemoLoader " + lbTemplate.name + " renderpath: " + lbCameraAnimator.animatorCamera.renderingPath); lbCameraAnimator.pauseAtEndDuration = 999f; lbCameraAnimator.BeginAnimation(true, 0f); } else { Debug.LogWarning("LBDemoLoader.LoadTemplateWithUIDelay - Couldn't find a camera animator in the demo template"); } } } // Re-enable buttons EnableButton(quality1Button, true); EnableButton(quality2Button, true); EnableButton(quality3Button, true); EnableButton(quality4Button, true); EnableButton(infoButton, true); EnableButton(gpuButton, true); UpdateInfoButtonText("Show Info"); } } } if (showSRPWarning) { SetInfoTitle("SRP WARNING"); SetInfoText("This demo scene is designed for the built-in RP.\n\nSee SRP folder for into on URP and HDRP"); } else { DisplayInfoPanel(false); } DisplayBackgroundPanel(false); }