コード例 #1
0
        private RenderTexture OrthoLayerBake(Terrain terrain, LayerMask layerMask, float distance)
        {
            RenderTextureDescriptor rtDesc        = GetDefaultCollisionMaskRTDescriptor(terrain);
            RenderTexture           collisionMask = new RenderTexture(rtDesc);
            RenderTexture           currentRT     = RenderTexture.active;

            RenderTexture.active = collisionMask;
            //we start with a full white texture, the areas that would create a collision are painted in black
            GL.Clear(true, true, Color.white);
            RenderTexture.active = currentRT;
            var originalLODBias = QualitySettings.lodBias;

            try
            {
#if HDPipeline
                //In HD Pipeline we can use a frame override to set the LOD Bias for the capture.
                OrthographicBake.m_HDLODBiasOverride = 100;
#else
                QualitySettings.lodBias = 100;
#endif
                OrthographicBake.LightsOff();
                OrthographicBake.CreateBakeDirectionalLight(9999f, Color.white);
                OrthographicBake.BakeTerrain(terrain, terrain.terrainData.heightmapResolution, terrain.terrainData.heightmapResolution, layerMask, null);
                Material growShrinkMaterial = new Material(Shader.Find("Hidden/Gaia/GrowShrink"));
                growShrinkMaterial.SetTexture("_InputTex", OrthographicBake.m_tmpRenderTexture);
                //translate the grow shrink distance into a scalar terrain value, as the shader works with U/V coordinates
                float scalarDistance = distance / terrain.terrainData.size.x;
                growShrinkMaterial.SetFloat("_Distance", scalarDistance);
                growShrinkMaterial.SetFloat("_TexelSize", OrthographicBake.m_tmpRenderTexture.texelSize.x);
                Graphics.Blit(OrthographicBake.m_tmpRenderTexture, collisionMask, growShrinkMaterial, 1);
                OrthographicBake.CleanUpRenderTexture();
            }
            catch (Exception ex)
            {
                Debug.LogError("Error while trying to bake a layer-based game object collision mask. Error Message: " + ex.Message + " Stack Trace: " + ex.StackTrace);
            }
            finally
            {
#if !HDPipeline
                QualitySettings.lodBias = originalLODBias;
#endif

                OrthographicBake.LightsOn();
                OrthographicBake.RemoveBakeDirectionalLight();
                OrthographicBake.RemoveOrthoCam();
            }
            return(collisionMask);
        }
コード例 #2
0
        private void DrawSummary(bool helpEnabled)
        {
            m_manager.m_session = (GaiaSession)m_editorUtils.ObjectField("SessionData", m_manager.m_session, typeof(GaiaSession), helpEnabled);
            m_editorUtils.InlineHelp("SessionData", helpEnabled);
            if (m_manager.m_session == null)
            {
                if (m_editorUtils.Button("CreateSessionButton"))
                {
                    m_manager.CreateSession();
                }
            }
            if (m_manager.m_session == null)
            {
                return;
            }
            EditorGUI.BeginChangeCheck();
            m_manager.m_session.m_name = m_editorUtils.DelayedTextField("Name", m_manager.m_session.m_name, helpEnabled);
            if (EditorGUI.EndChangeCheck())
            {
                //Get the old path
                string oldSessionDataPath = GaiaDirectories.GetSessionSubFolderPath(m_manager.m_session);
                //Rename the session asset
                AssetDatabase.RenameAsset(AssetDatabase.GetAssetPath(m_manager.m_session), m_manager.m_session.m_name + ".asset");
                //rename the session data path as well
                string newSessionDataPath = GaiaDirectories.GetSessionSubFolderPath(m_manager.m_session, false);
                AssetDatabase.MoveAsset(oldSessionDataPath, newSessionDataPath);
                //if we have terrain scenes stored in the Terrain Loader, we need to update the paths in there as well
                foreach (TerrainScene terrainScene in TerrainLoaderManager.TerrainScenes)
                {
                    terrainScene.m_scenePath         = terrainScene.m_scenePath.Replace(oldSessionDataPath, newSessionDataPath);
                    terrainScene.m_impostorScenePath = terrainScene.m_impostorScenePath.Replace(oldSessionDataPath, newSessionDataPath);
                    terrainScene.m_backupScenePath   = terrainScene.m_backupScenePath.Replace(oldSessionDataPath, newSessionDataPath);
                    terrainScene.m_colliderScenePath = terrainScene.m_colliderScenePath.Replace(oldSessionDataPath, newSessionDataPath);
                }
                TerrainLoaderManager.Instance.SaveStorageData();

                AssetDatabase.DeleteAsset(oldSessionDataPath);
                AssetDatabase.SaveAssets();
            }

            EditorGUILayout.BeginHorizontal();
            EditorGUILayout.LabelField(m_editorUtils.GetContent("Description"), GUILayout.MaxWidth(EditorGUIUtility.labelWidth));
            m_manager.m_session.m_description = EditorGUILayout.TextArea(m_manager.m_session.m_description, GUILayout.MinHeight(100));
            EditorGUILayout.EndHorizontal();
            m_editorUtils.InlineHelp("Description", helpEnabled);
            m_manager.m_session.m_previewImage = (Texture2D)m_editorUtils.ObjectField("PreviewImage", m_manager.m_session.m_previewImage, typeof(Texture2D), helpEnabled);
            GUILayout.BeginHorizontal();
            Rect rect = EditorGUILayout.GetControlRect();

            GUILayout.Space(rect.width - 20);
            if (GUILayout.Button("Generate Image"))
            {
                string textureFileName = GaiaDirectories.GetSessionSubFolderPath(m_manager.m_session) + Path.DirectorySeparatorChar + m_manager.m_session + "_Preview";
                var    originalLODBias = QualitySettings.lodBias;
                QualitySettings.lodBias = 100;
                OrthographicBake.BakeTerrain(Terrain.activeTerrain, 2048, 2048, Camera.main.cullingMask, textureFileName);
                OrthographicBake.RemoveOrthoCam();
                QualitySettings.lodBias = originalLODBias;
                textureFileName        += ".png";
                AssetDatabase.ImportAsset(textureFileName);
                var importer = AssetImporter.GetAtPath(textureFileName) as TextureImporter;
                if (importer != null)
                {
                    importer.sRGBTexture         = false;
                    importer.alphaIsTransparency = false;
                    importer.alphaSource         = TextureImporterAlphaSource.None;
                    importer.mipmapEnabled       = false;
                }
                AssetDatabase.ImportAsset(textureFileName);
                m_manager.m_session.m_previewImage = (Texture2D)AssetDatabase.LoadAssetAtPath(textureFileName, typeof(Texture2D));
            }
            GUILayout.EndHorizontal();
            m_editorUtils.InlineHelp("PreviewImage", helpEnabled);
            m_editorUtils.LabelField("Created", new GUIContent(m_manager.m_session.m_dateCreated), helpEnabled);
            m_manager.m_session.m_isLocked = m_editorUtils.Toggle("Locked", m_manager.m_session.m_isLocked, helpEnabled);
            float maxSeaLevel = 2000f;

            if (Terrain.activeTerrain != null)
            {
                maxSeaLevel = Terrain.activeTerrain.terrainData.size.y + Terrain.activeTerrain.transform.position.y;
            }
            else
            {
                maxSeaLevel = m_manager.GetSeaLevel(false) + 500f;
            }

            float oldSeaLevel = m_manager.GetSeaLevel(false);
            float newSeaLEvel = oldSeaLevel;

            newSeaLEvel = m_editorUtils.Slider("SeaLevel", newSeaLEvel, 0, maxSeaLevel, helpEnabled);
            if (newSeaLEvel != oldSeaLevel)
            {
                //Do we have a water instance? If yes, update it & it will update the sea level in the session as well
                if (PWS_WaterSystem.Instance != null)
                {
                    PWS_WaterSystem.Instance.SeaLevel = newSeaLEvel;
                }
                else
                {
                    //no water instance yet, just update the sea level in the session
                    m_manager.SetSeaLevel(newSeaLEvel, false);
                    SceneView.RepaintAll();
                }
            }

            m_manager.m_session.m_spawnDensity = m_editorUtils.FloatField("SpawnDensity", Mathf.Max(0.01f, m_manager.m_session.m_spawnDensity), helpEnabled);
            GUILayout.BeginHorizontal();
            if (m_editorUtils.Button("DeleteAllOperations"))
            {
                if (EditorUtility.DisplayDialog(m_editorUtils.GetTextValue("PopupDeleteAllTitle"), m_editorUtils.GetTextValue("PopupDeleteAllMessage"), m_editorUtils.GetTextValue("Continue"), m_editorUtils.GetTextValue("Cancel")))
                {
                    foreach (GaiaOperation op in m_manager.m_session.m_operations)
                    {
                        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);
                        }
                    }

                    m_manager.m_session.m_operations.Clear();
                }
            }

            if (m_editorUtils.Button("PlaySession"))
            {
                GaiaLighting.SetDefaultAmbientLight(GaiaUtils.GetGaiaSettings().m_gaiaLightingProfile);
                GaiaSessionManager.PlaySession();
            }
            GUILayout.EndHorizontal();
        }