예제 #1
0
        /// <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);
        }
예제 #2
0
        public override void OnInspectorGUI()
        {
            // If the base command is called, all public fields not hidden, will be displayed
            //base.OnInspectorGUI();

            EditorGUIUtility.labelWidth = 150f;

            if (labelFieldRichText == null)
            {
                labelFieldRichText          = new GUIStyle("Label");
                labelFieldRichText.richText = true;
            }

            EditorGUILayout.BeginVertical(EditorStyles.helpBox);

            // Read in all the properties
            serializedObject.Update();

            EditorGUILayout.BeginHorizontal();
            labelText = "<color=" + txtColourName + "><b>Landscape Name</b></color>";
            EditorGUILayout.LabelField(labelText, labelFieldRichText, GUILayout.Width(EditorGUIUtility.labelWidth));
            EditorGUILayout.PropertyField(landscapeNameProp, GUIContent.none);
            EditorGUILayout.EndHorizontal();

            // This is the installed version of LB when the template was created
            EditorGUILayout.BeginHorizontal();
            labelText = "<color=" + txtColourName + "><b>Landscape Version</b></color>";
            EditorGUILayout.LabelField(labelText, labelFieldRichText, GUILayout.Width(EditorGUIUtility.labelWidth));
            labelText = "<color=" + txtColourName + ">" + lastUpdatedVersionProp.stringValue + "</color>";
            EditorGUILayout.LabelField(labelText, labelFieldRichText);
            EditorGUILayout.EndHorizontal();

            // This is the installed version of LB when the template was created
            EditorGUILayout.BeginHorizontal();
            labelText = "<color=" + txtColourName + "><b>LB Version</b></color>";
            EditorGUILayout.LabelField(labelText, labelFieldRichText, GUILayout.Width(EditorGUIUtility.labelWidth));
            labelText = "<color=" + txtColourName + ">" + lbVersionProp.stringValue + "</color>";
            EditorGUILayout.LabelField(labelText, labelFieldRichText);
            EditorGUILayout.EndHorizontal();

            // This is the installed version of Unity when the template was created
            EditorGUILayout.BeginHorizontal();
            labelText = "<color=" + txtColourName + "><b>Unity Version</b></color>";
            EditorGUILayout.LabelField(labelText, labelFieldRichText, GUILayout.Width(EditorGUIUtility.labelWidth));
            labelText = "<color=" + txtColourName + ">" + templateUnityVersionProp.stringValue + "</color>";
            EditorGUILayout.LabelField(labelText, labelFieldRichText);
            EditorGUILayout.EndHorizontal();

            EditorGUILayout.BeginHorizontal();
            labelText = "<color=" + txtColourName + "><b>Landscape Size</b></color>";
            EditorGUILayout.LabelField(labelText, labelFieldRichText, GUILayout.Width(EditorGUIUtility.labelWidth));
            labelText = "<color=" + txtColourName + ">" + sizeProp.vector2Value + "</color>";
            EditorGUILayout.LabelField(labelText, labelFieldRichText);
            EditorGUILayout.EndHorizontal();

            EditorGUILayout.BeginHorizontal();
            labelText = "<color=" + txtColourName + "><b>Start Position</b></color>";
            EditorGUILayout.LabelField(labelText, labelFieldRichText, GUILayout.Width(EditorGUIUtility.labelWidth));
            labelText = "<color=" + txtColourName + ">X: " + startProp.vector3Value.x + " Y: " + startProp.vector3Value.y + " Z: " + startProp.vector3Value.z + "</color>";
            EditorGUILayout.LabelField(labelText, labelFieldRichText);
            EditorGUILayout.EndHorizontal();

            EditorGUILayout.BeginHorizontal();
            labelText = "<color=" + txtColourName + "><b>Heightmap Resolution</b></color>";
            EditorGUILayout.LabelField(labelText, labelFieldRichText, GUILayout.Width(EditorGUIUtility.labelWidth));
            labelText = "<color=" + txtColourName + ">" + heightmapResolutionProp.intValue + "</color>";
            EditorGUILayout.LabelField(labelText, labelFieldRichText);
            EditorGUILayout.EndHorizontal();

            EditorGUILayout.BeginHorizontal();
            labelText = "<color=" + txtColourName + "><b>Terrain Width</b></color>";
            EditorGUILayout.LabelField(labelText, labelFieldRichText, GUILayout.Width(EditorGUIUtility.labelWidth));
            labelText = "<color=" + txtColourName + ">" + terrainWidthProp.floatValue + "</color>";
            EditorGUILayout.LabelField(labelText, labelFieldRichText);
            EditorGUILayout.EndHorizontal();

            EditorGUILayout.BeginHorizontal();
            labelText = "<color=" + txtColourName + "><b>Terrain Height</b></color>";
            EditorGUILayout.LabelField(labelText, labelFieldRichText, GUILayout.Width(EditorGUIUtility.labelWidth));
            labelText = "<color=" + txtColourName + ">" + terrainHeightProp.floatValue + "</color>";
            EditorGUILayout.LabelField(labelText, labelFieldRichText);
            EditorGUILayout.EndHorizontal();

            EditorGUILayout.BeginHorizontal();
            labelText = "<color=" + txtColourName + "><b>Alphamap Resolution</b></color>";
            EditorGUILayout.LabelField(labelText, labelFieldRichText, GUILayout.Width(EditorGUIUtility.labelWidth));
            labelText = "<color=" + txtColourName + ">" + alphaMapResolutionProp.intValue + "</color>";
            EditorGUILayout.LabelField(labelText, labelFieldRichText);
            EditorGUILayout.EndHorizontal();

            EditorGUILayout.BeginHorizontal();
            labelText = "<color=" + txtColourName + "><b>Terrain Material Type</b></color>";
            EditorGUILayout.LabelField(labelText, labelFieldRichText, GUILayout.Width(EditorGUIUtility.labelWidth));
            EditorGUILayout.PropertyField(terrainMaterialTypeProp, GUIContent.none);
            EditorGUILayout.EndHorizontal();

            EditorGUILayout.BeginHorizontal();
            labelText = "<color=" + txtColourName + "><b>Legacy Noise Offset</b></color>";
            EditorGUILayout.LabelField(labelText, labelFieldRichText, GUILayout.Width(EditorGUIUtility.labelWidth));
            labelText = "<color=" + txtColourName + ">" + useLegacyNoiseOffsetProp.boolValue + "</color>";
            EditorGUILayout.LabelField(labelText, labelFieldRichText);
            EditorGUILayout.EndHorizontal();

            labelText = "<color=" + txtColourName + "><b>GPU Acceleration</b></color>";
            EditorGUILayout.LabelField(labelText, labelFieldRichText, GUILayout.Width(EditorGUIUtility.labelWidth));

            EditorGUILayout.BeginHorizontal();
            labelText = "<color=" + txtColourName + "><b>  Topography</b></color>";
            EditorGUILayout.LabelField(labelText, labelFieldRichText, GUILayout.Width(EditorGUIUtility.labelWidth));
            labelText = "<color=" + txtColourName + ">" + useGPUTopographyProp.boolValue + "</color>";
            EditorGUILayout.LabelField(labelText, labelFieldRichText);
            EditorGUILayout.EndHorizontal();

            EditorGUILayout.BeginHorizontal();
            labelText = "<color=" + txtColourName + "><b>  Texturing</b></color>";
            EditorGUILayout.LabelField(labelText, labelFieldRichText, GUILayout.Width(EditorGUIUtility.labelWidth));
            labelText = "<color=" + txtColourName + ">" + useGPUTexturingProp.boolValue + "</color>";
            EditorGUILayout.LabelField(labelText, labelFieldRichText);
            EditorGUILayout.EndHorizontal();

            EditorGUILayout.BeginHorizontal();
            labelText = "<color=" + txtColourName + "><b>  Grass</b></color>";
            EditorGUILayout.LabelField(labelText, labelFieldRichText, GUILayout.Width(EditorGUIUtility.labelWidth));
            labelText = "<color=" + txtColourName + ">" + useGPUGrassProp.boolValue + "</color>";
            EditorGUILayout.LabelField(labelText, labelFieldRichText);
            EditorGUILayout.EndHorizontal();

            EditorGUILayout.BeginHorizontal();
            labelText = "<color=" + txtColourName + "><b>  Path</b></color>";
            EditorGUILayout.LabelField(labelText, labelFieldRichText, GUILayout.Width(EditorGUIUtility.labelWidth));
            labelText = "<color=" + txtColourName + ">" + useGPUPathProp.boolValue + "</color>";
            EditorGUILayout.LabelField(labelText, labelFieldRichText);
            EditorGUILayout.EndHorizontal();

            EditorGUILayout.BeginHorizontal();
            labelText = "<color=" + txtColourName + "><b>Populate Landscape</b></color>";
            EditorGUILayout.LabelField(labelText, labelFieldRichText, GUILayout.Width(EditorGUIUtility.labelWidth));
            EditorGUILayout.PropertyField(isPopulateLandscapeProp, new GUIContent(""), GUILayout.Width(30));
            EditorGUILayout.EndHorizontal();

            if (GUILayout.Button("Create New unpopulated Landscape from Template"))
            {
                if (lbTemplate == null)
                {
                    Debug.LogWarning("LBTemplateEditor - create landscape - template not defined. Please Report");
                }
                else if (string.IsNullOrEmpty(UnityEditor.SceneManagement.EditorSceneManager.GetActiveScene().name))
                {
                    EditorUtility.DisplayDialog("Generate Landscape", "Please save the scene before adding a landscape.", "Got it!");
                }
                else
                {
                    LBLandscape lbLandscape = lbTemplate.CreateLandscapeFromTemplate(lbTemplate.landscapeName);
                    UnityEditor.SceneManagement.EditorSceneManager.MarkSceneDirty(UnityEditor.SceneManagement.EditorSceneManager.GetActiveScene());
                    if (lbLandscape != null)
                    {
                        lbTemplate.ApplyTemplateToLandscape(lbLandscape, false, true, null, true);
                        if (isPopulateLandscapeProp.boolValue)
                        {
                            lbLandscape.ApplyTopography(false, true);
                            lbLandscape.ApplyTextures(false, true);
                            lbLandscape.ApplyTrees(false, true);
                            lbLandscape.ApplyGrass(false, true);
                            lbLandscape.ApplyGroups(false, true);
                            lbLandscape.ApplyMeshes(false, true);
                        }

                        if (lbTemplate.isLBLightingIncluded)
                        {
                            LBLighting lbLighting = GameObject.FindObjectOfType <LBLighting>();
                            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, Camera.main, true);
                            }
                        }

                        LandscapeBuilderWindow.SetLandscape(lbLandscape, true);
                        // Prevent errors in editor for U2017
                        //EditorGUILayout.EndVertical();
                        //return;
                    }
                }
            }

            EditorGUILayout.BeginHorizontal();
            labelText = "<color=" + txtColourName + "><b>Debug Mode</b></color>";
            EditorGUILayout.LabelField(labelText, labelFieldRichText, GUILayout.Width(EditorGUIUtility.labelWidth));
            EditorGUILayout.PropertyField(debugModeProp, new GUIContent(""), GUILayout.Width(30));
            labelText = "<color=" + txtColourName + "><b>INTERNAL USE ONLY</b></color>";
            EditorGUILayout.LabelField(labelText, labelFieldRichText);
            EditorGUILayout.EndHorizontal();

            serializedObject.ApplyModifiedProperties();

            if (debugModeProp.boolValue)
            {
                // Display unhidden public variables in LBTemplate.cs
                DrawDefaultInspector();
            }

            EditorGUILayout.EndVertical();
        }