예제 #1
0
        private static void AddOverCloud()
        {
            GameObject overCloudPrefab = AssetDatabase.LoadAssetAtPath <GameObject>(GaiaUtils.GetAssetPath("OverCloud.prefab"));

            if (overCloudPrefab != null)
            {
                Light sunLight = GaiaUtils.GetMainDirectionalLight();
                if (sunLight != null)
                {
                    GameObject.DestroyImmediate(sunLight.gameObject);
                }

                PrefabUtility.InstantiatePrefab(overCloudPrefab, GetOrCreateParentObject(GaiaConstants.gaiaLightingObject, true).transform);

                Camera mainCamera = GaiaUtils.GetCamera();
                if (mainCamera != null)
                {
                    OverCloudCamera ocCamera = mainCamera.gameObject.GetComponent <OverCloudCamera>();
                    if (ocCamera == null)
                    {
                        ocCamera = mainCamera.gameObject.AddComponent <OverCloudCamera>();
                    }
                }

                GaiaUtils.SetCustomLightSystem(overCloudPrefab);
            }
            else
            {
                Debug.LogError("OverCloud Prefab was not found");
            }
        }
예제 #2
0
        static MewlistMassiveClouds()
        {
            string folderName = "MassiveClouds";

            if (Directory.Exists(GaiaUtils.GetAssetPath(folderName)))
            {
                //Make sure we inject GAIA_2_PRESENT
                bool updateScripting = false;
                var  symbols         = PlayerSettings.GetScriptingDefineSymbolsForGroup(EditorUserBuildSettings.selectedBuildTargetGroup);
                if (!symbols.Contains("MEWLIST_MASSIVE_CLOUDS"))
                {
                    updateScripting = true;
                    if (symbols.Length < 1)
                    {
                        symbols += "MEWLIST_MASSIVE_CLOUDS";
                    }
                    else
                    {
                        symbols += ";MEWLIST_MASSIVE_CLOUDS";
                    }
                }

                if (updateScripting)
                {
                    PlayerSettings.SetScriptingDefineSymbolsForGroup(EditorUserBuildSettings.selectedBuildTargetGroup, symbols);
                }
            }
        }
예제 #3
0
        /// <summary>
        /// Gets the shader
        /// </summary>
        /// <param name="path"></param>
        /// <param name="seachPattern"></param>
        /// <returns></returns>
        public static Shader GetShaderFile(string path, string seachPattern)
        {
            Shader        returningShader = null;
            DirectoryInfo dirInfo         = new DirectoryInfo(path);
            var           files           = dirInfo.GetFiles();

            foreach (FileInfo file in files)
            {
                if (file.Extension.EndsWith("shader") && file.Name.Contains(seachPattern))
                {
                    returningShader = AssetDatabase.LoadAssetAtPath <Shader>(GaiaUtils.GetAssetPath(file.Name));
                    return(returningShader);
                }
            }

            return(null);
        }
예제 #4
0
        public override void OnInspectorGUI()
        {
            //Initialization
            m_editorUtils.Initialize(); // Do not remove this!

            //Set up the box style
            if (m_boxStyle == null)
            {
                m_boxStyle = new GUIStyle(GUI.skin.box)
                {
                    normal    = { textColor = GUI.skin.label.normal.textColor },
                    fontStyle = FontStyle.Bold,
                    alignment = TextAnchor.UpperLeft
                };
            }

            //Monitor for changes
            EditorGUI.BeginChangeCheck();

            EditorGUILayout.LabelField("Profile Version: " + m_version);

            bool enableEditMode = System.IO.Directory.Exists(GaiaUtils.GetAssetPath("Dev Utilities"));

            if (enableEditMode)
            {
                m_profile.m_editorUpdates = EditorGUILayout.ToggleLeft("Use Procedural Worlds Editor Settings", m_profile.m_editorUpdates);
            }
            else
            {
                m_profile.m_editorUpdates = false;
            }

            if (m_profile.m_editorUpdates)
            {
                m_editorUtils.Panel("ProfileSettings", ProfileSettingsEnabled, false);
            }

            //Check for changes, make undo record, make changes and let editor know we are dirty
            if (EditorGUI.EndChangeCheck())
            {
                Undo.RecordObject(m_profile, "Made changes");
                EditorUtility.SetDirty(m_profile);
            }
        }
예제 #5
0
        /// <summary>
        /// Removes Suffix in file formats required
        /// </summary>
        /// <param name="path"></param>
        private static List <Material> GetMaterials(string path)
        {
            List <Material> materials = new List <Material>();

            DirectoryInfo dirInfo = new DirectoryInfo(path);
            var           files   = dirInfo.GetFiles();

            foreach (FileInfo file in files)
            {
                if (file.Extension.EndsWith("mat"))
                {
                    materials.Add(AssetDatabase.LoadAssetAtPath <Material>(GaiaUtils.GetAssetPath(file.Name)));
                }
            }

            m_allMaterials = materials;

            return(materials);
        }
예제 #6
0
        private static void AddClouds()
        {
            Camera mainCamera = GaiaUtils.GetCamera();

            if (mainCamera != null)
            {
                MassiveClouds clouds = mainCamera.GetComponent <MassiveClouds>();
                if (clouds == null)
                {
                    clouds = mainCamera.gameObject.AddComponent <MassiveClouds>();
                }

                List <MassiveCloudsProfile>   profiles   = new List <MassiveCloudsProfile>();
                MassiveCloudsProfile          profile    = AssetDatabase.LoadAssetAtPath <MassiveCloudsProfile>(GaiaUtils.GetAssetPath("Cloudy C.asset"));
                List <MassiveCloudsParameter> parameters = new List <MassiveCloudsParameter>();
                if (profile != null)
                {
                    profiles.Add(profile);
                    parameters.Add(profile.Parameter);
                    clouds.SetProfiles(profiles);
                    clouds.SetParameters(parameters);
                }

                MassiveCloudsCameraEffect cloudsEffect = mainCamera.GetComponent <MassiveCloudsCameraEffect>();
                if (cloudsEffect == null)
                {
                    cloudsEffect = mainCamera.gameObject.AddComponent <MassiveCloudsCameraEffect>();
                }
            }
        }
예제 #7
0
        /// <summary>
        /// Updates the biome post fx to SRP volume profile
        /// </summary>
        private static void UpdateBiomePostFX()
        {
            try
            {
                GaiaPostProcessBiome[] gaiaPostProcessBiomes = GameObject.FindObjectsOfType <GaiaPostProcessBiome>();
                if (gaiaPostProcessBiomes.Length > 0)
                {
                    foreach (GaiaPostProcessBiome biome in gaiaPostProcessBiomes)
                    {
#if UNITY_POST_PROCESSING_STACK_V2
                        PostProcessVolume processVolume = biome.GetComponent <PostProcessVolume>();
                        if (processVolume != null)
                        {
                            GameObject.DestroyImmediate(processVolume);
                        }
#endif

#if UPPipeline
                        Volume volumeComp = biome.GetComponent <Volume>();
                        if (volumeComp == null)
                        {
                            volumeComp = biome.gameObject.AddComponent <Volume>();
                            volumeComp.sharedProfile = AssetDatabase.LoadAssetAtPath <VolumeProfile>(GaiaUtils.GetAssetPath("UP " + biome.PostProcessingFileName + ".asset"));
                        }
#endif
                    }
                }
                UpdateShadowDistance();
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
                throw;
            }
        }
예제 #8
0
        /// <summary>
        /// Crate post processing instance profile
        /// </summary>
        /// <param name="sceneProfile"></param>
        public static void CreatePostFXProfileInstance(SceneProfile sceneProfile, GaiaLightingProfileValues profile)
        {
            try
            {
                if (sceneProfile == null)
                {
                    return;
                }

#if UPPipeline
                VolumeProfile volumeProfile = AssetDatabase.LoadAssetAtPath <VolumeProfile>(GaiaUtils.GetAssetPath("URP Global Post Processing Profile.asset"));
                if (profile.PostProcessProfileURP != null)
                {
                    volumeProfile = profile.PostProcessProfileURP;
                }
                if (volumeProfile == null)
                {
                    return;
                }

                GaiaSessionManager session = GaiaSessionManager.GetSessionManager();
                if (session != null)
                {
                    string path = GaiaDirectories.GetSceneProfilesFolderPath(session.m_session);
                    if (!string.IsNullOrEmpty(path))
                    {
                        if (EditorSceneManager.GetActiveScene() != null)
                        {
                            if (!string.IsNullOrEmpty(EditorSceneManager.GetActiveScene().path))
                            {
                                path = path + "/" + EditorSceneManager.GetActiveScene().name + " " + volumeProfile.name + " Profile.asset";
                            }
                            else
                            {
                                path = path + "/" + volumeProfile.name + " HDRP Post FX Profile.asset";
                            }
                        }
                        else
                        {
                            path = path + "/" + volumeProfile.name + " HDRP Post FX Profile.asset";
                        }

                        if (sceneProfile.m_universalPostFXProfile != null)
                        {
                            if (!sceneProfile.m_isUserProfileSet)
                            {
                                if (!sceneProfile.m_universalPostFXProfile.name.Contains(volumeProfile.name))
                                {
                                    AssetDatabase.DeleteAsset(AssetDatabase.GetAssetPath(sceneProfile.m_universalPostFXProfile));
                                    sceneProfile.m_universalPostFXProfile = null;
                                }
                            }
                        }

                        if (AssetDatabase.LoadAssetAtPath <VolumeProfile>(path) == null)
                        {
                            FileUtil.CopyFileOrDirectory(AssetDatabase.GetAssetPath(volumeProfile), path);
                            AssetDatabase.ImportAsset(path);
                        }

                        sceneProfile.m_universalPostFXProfile = AssetDatabase.LoadAssetAtPath <VolumeProfile>(path);
                    }
                }
#endif
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
                throw;
            }
        }
예제 #9
0
        /// <summary>
        /// Sets the pipeline asset to the procedural worlds asset if the profile is set yo change it
        /// </summary>
        /// <param name="profile"></param>
        public static void SetPipelineAsset(UnityPipelineProfile profile)
        {
            try
            {
                GaiaPackageVersion        unityVersion = GaiaManagerEditor.GetPackageVersion();
                UnityVersionPipelineAsset mapping      = profile.m_universalPipelineProfiles.Find(x => x.m_unityVersion == unityVersion);
                string pipelineAssetName = "";
                if (mapping != null)
                {
                    pipelineAssetName = mapping.m_pipelineAssetName;
                }
                else
                {
                    Debug.LogError("Could not determine the correct render pipeline settings asset for this unity version / rendering pipeline!");
                    return;
                }

                GraphicsSettings.renderPipelineAsset = AssetDatabase.LoadAssetAtPath <RenderPipelineAsset>(GaiaUtils.GetAssetPath(pipelineAssetName + GaiaConstants.gaiaFileFormatAsset));
                profile.m_pipelineSwitchUpdates      = true;
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
                throw;
            }
        }
예제 #10
0
        /// <summary>
        /// Start installation
        /// </summary>
        private static void StartInstallingPackage()
        {
            //bool updatesChanges = false;
            //string shaderRootFolder = GaiaDirectories.GetShaderDirectory();
            //if (m_gaiaPipelineProfile == null)
            //{
            //    m_gaiaPipelineProfile = GetPipelineProfile();
            //}

            ////Add Shader setup here
            //string[] folderPaths = Directory.GetDirectories(shaderRootFolder, ".", SearchOption.AllDirectories);
            //foreach (string folderPath in folderPaths)
            //{
            //    CleanUpFolder(folderPath);
            //}

            //AssetDatabase.Refresh();

            //m_unityVersion = Application.unityVersion;
            //m_unityVersion = m_unityVersion.Remove(m_unityVersion.LastIndexOf(".")).Replace(".", "_0");
            //string keyWordToSearch = "";
            //if (m_installShaders)
            //{
            //    if (m_renderPipeline == GaiaConstants.EnvironmentRenderer.BuiltIn)
            //    {
            //        keyWordToSearch = GaiaConstants.builtInKeyWord;
            //    }
            //    else if (m_renderPipeline == GaiaConstants.EnvironmentRenderer.Lightweight)
            //    {
            //        keyWordToSearch = GaiaConstants.lightweightKeyWord;
            //    }
            //    else if (m_renderPipeline == GaiaConstants.EnvironmentRenderer.Universal)
            //    {
            //        keyWordToSearch = GaiaConstants.universalKeyWord;
            //    }
            //    else
            //    {
            //        keyWordToSearch = GaiaConstants.highDefinitionKeyWord;
            //    }

            //    int numberOfFolders = folderPaths.Length;
            //    int currentFolder = 1;

            //    foreach (string folderpath in folderPaths)
            //    {
            //        //try
            //        //{
            //        //    EditorUtility.DisplayProgressBar("Processing Shader Library", "Processing Library Folder " + currentFolder.ToString() + " of " + numberOfFolders.ToString(), (float)currentFolder / (float)numberOfFolders);

            //        //    string finalFolderName = "";

            //        //    if (Application.platform == RuntimePlatform.OSXEditor || Application.platform == RuntimePlatform.LinuxEditor)
            //        //        finalFolderName = folderpath.Substring(folderpath.LastIndexOf("/"));
            //        //    else
            //        //        finalFolderName = folderpath.Substring(folderpath.LastIndexOf("\\"));

            //        //    if (!folderpath.EndsWith("PWSF Functions") && !folderpath.EndsWith("PWS Procedural") && !folderpath.EndsWith("PWS Water Pro"))
            //        //    {
            //        //        if (finalFolderName.Contains(keyWordToSearch + " " + m_unityVersion))
            //        //        {
            //        //            updatesChanges = RemoveFileSuffix(folderpath);
            //        //            foreach (MaterialLibraryEntry entry in m_materialLibrary)
            //        //            {
            //        //                if (folderpath.Contains(entry.m_folderKeyWord))
            //        //                {
            //        //                    entry.m_shaderToInstall = GetShaderFile(folderpath, entry.m_shaderKeyWord);
            //        //                    break;
            //        //                }
            //        //            }
            //        //        }
            //        //        else
            //        //        {
            //        //            updatesChanges = AddFileSuffix(folderpath);
            //        //        }
            //        //    }
            //        //}
            //        //catch (Exception ex)
            //        //{
            //        //    Debug.LogError("Exception while processing the Shader Library Folders, folder path: '" + folderpath + "'. ##Exception: " + ex.Message + " ##Stack Trace: " + ex.StackTrace);
            //        //}

            //        //currentFolder++;
            //    }

            //    if (updatesChanges)
            //    {
            //        AssetDatabase.Refresh();
            //    }

            //    StartInstallingPackage2();
            //}

            //if (m_installMaterials)
            //{
            EditorApplication.update -= EditorUpdate;

            bool updateChanges = false;
            bool promptRenderPipelineMaterialUpdate = false;

            if (m_materialLibrary == null)
            {
                Debug.LogError("Unable to load the Material Library");
            }
            else
            {
                //Change all materials in the library to the correct shader each

                try
                {
                    int numberOfEntries = m_materialLibrary.Length;
                    int currentEntry    = 1;


                    Shader builtInShader1 = Shader.Find(PWShaderNameUtility.ShaderName[1]);
                    Shader builtInShader2 = Shader.Find(PWShaderNameUtility.ShaderName[2]);

                    if (builtInShader1 == null || builtInShader2 == null)
                    {
                        Debug.LogWarning($"One of the standard built in shaders ({ShaderIDs.PW_General_Forward.ToString()},{ShaderIDs.PW_General_Deferred.ToString()}) for shader mapping could not be found!");
                    }

                    Shader[] specialBuiltInShaders = new Shader[3] {
                        null, builtInShader1, builtInShader2
                    };

                    foreach (ShaderMappingEntry entry in m_materialLibrary)
                    {
                        string targetShaderName  = entry.m_builtInShaderName;
                        string searchShaderName1 = "";
                        string searchShaderName2 = "";
                        switch (m_renderPipeline)
                        {
                        case GaiaConstants.EnvironmentRenderer.BuiltIn:
                            targetShaderName  = entry.m_builtInShaderName;
                            searchShaderName1 = entry.m_URPReplacementShaderName;
                            searchShaderName2 = entry.m_HDRPReplacementShaderName;
                            break;

                        case GaiaConstants.EnvironmentRenderer.Lightweight:
                            //not supported anymore
                            break;

                        case GaiaConstants.EnvironmentRenderer.Universal:
                            targetShaderName  = entry.m_URPReplacementShaderName;
                            searchShaderName1 = entry.m_builtInShaderName;
                            searchShaderName2 = entry.m_HDRPReplacementShaderName;
                            break;

                        case GaiaConstants.EnvironmentRenderer.HighDefinition:
                            targetShaderName  = entry.m_HDRPReplacementShaderName;
                            searchShaderName1 = entry.m_builtInShaderName;
                            searchShaderName2 = entry.m_URPReplacementShaderName;
                            break;
                        }
                        try
                        {
                            EditorUtility.DisplayProgressBar("Processing Shader Mapping", "Shader Mapping Entry " + currentEntry.ToString() + " of " + numberOfEntries.ToString(), (float)currentEntry / (float)numberOfEntries);

                            Shader targetShader = Shader.Find(targetShaderName);

                            if (targetShader == null)
                            {
                                Debug.LogError($"The target shader with the name {targetShaderName} from the shader mapping entry {entry.m_builtInShaderName} could not be found!");
                                continue;
                            }
                            else
                            {
                                UnityEngine.Object shaderObject = null;
                                switch (m_renderPipeline)
                                {
                                case GaiaConstants.EnvironmentRenderer.BuiltIn:
                                    shaderObject = AssetDatabase.LoadAssetAtPath <UnityEngine.Object>(GaiaUtils.GetAssetPath(targetShaderName + ".shader"));
                                    break;

                                case GaiaConstants.EnvironmentRenderer.Universal:
                                    shaderObject = AssetDatabase.LoadAssetAtPath <UnityEngine.Object>(GaiaUtils.GetAssetPath(targetShaderName + ".shadergraph"));
                                    break;

                                case GaiaConstants.EnvironmentRenderer.HighDefinition:
                                    shaderObject = AssetDatabase.LoadAssetAtPath <UnityEngine.Object>(GaiaUtils.GetAssetPath(targetShaderName + ".shadergraph"));
                                    break;
                                }

                                if (shaderObject != null)
                                {
                                    if (shaderObject.name.Contains("PW"))
                                    {
                                        AssetDatabase.ImportAsset(AssetDatabase.GetAssetPath(shaderObject));
                                    }
                                }
                            }

                            //Get all the materials that currently use the shaders we want to migrate from
                            Shader searchShader1 = Shader.Find(searchShaderName1);
                            Shader searchShader2 = Shader.Find(searchShaderName2);

                            List <Material> affectedMaterials = GaiaUtils.FindMaterialsByShader(searchShader1).Concat(GaiaUtils.FindMaterialsByShader(searchShader2)).ToList();

                            foreach (Material material in affectedMaterials)
                            {
                                try
                                {
                                    if (material != null)
                                    {
                                        switch (m_renderPipeline)
                                        {
                                        case GaiaConstants.EnvironmentRenderer.BuiltIn:
                                            bool mappedToSpecialShaders = false;
                                            if (material.HasProperty("_PW_ShaderID"))
                                            {
                                                float shaderID = material.GetFloat("_PW_ShaderID");
                                                if (shaderID >= 1)
                                                {
                                                    material.shader = specialBuiltInShaders[(int)shaderID];
                                                    EditorUtility.SetDirty(material);
                                                    updateChanges          = true;
                                                    mappedToSpecialShaders = true;
                                                }
                                            }
                                            if (!mappedToSpecialShaders)
                                            {
                                                material.shader = targetShader;
                                                EditorUtility.SetDirty(material);
                                                updateChanges = true;
                                            }
                                            break;

                                        case GaiaConstants.EnvironmentRenderer.Lightweight:
                                            //not supported
                                            break;

                                        case GaiaConstants.EnvironmentRenderer.Universal:
                                            material.shader = targetShader;
                                            EditorUtility.SetDirty(material);
                                            updateChanges = true;
                                            break;

                                        case GaiaConstants.EnvironmentRenderer.HighDefinition:
                                            bool isSolid = false;
                                            if (material.HasProperty("_PW_ShaderMode"))
                                            {
                                                if (material.GetFloat("_PW_ShaderMode") == 0)
                                                {
                                                    isSolid = true;
                                                }
                                            }
                                            material.shader = targetShader;
                                            if (isSolid)
                                            {
                                                if (material.HasProperty("_AlphaCutoffEnable"))
                                                {
                                                    material.SetFloat("_AlphaCutoffEnable", 0);
                                                }
                                            }
                                            EditorUtility.SetDirty(material);
                                            updateChanges = true;

                                            break;
                                        }
                                    }
                                }
                                catch (Exception ex)
                                {
                                    if (entry != null)
                                    {
                                        Debug.LogError("Exception while processing the Shader Mapping, Material: '" + material.name + "'. ##Exception: " + ex.Message + " ##Stack Trace: " + ex.StackTrace);
                                    }
                                    else
                                    {
                                        Debug.LogError("Exception while processing the Shader Mapping, material is null! ##Exception: " + ex.Message + " ##Stack Trace: " + ex.StackTrace);
                                    }
                                }
                            }
                        }
                        catch (Exception ex)
                        {
                            if (entry != null)
                            {
                                Debug.LogError("Exception while processing the Material Library, entry: '" + entry.m_builtInShaderName + "'. ##Exception: " + ex.Message + " ##Stack Trace: " + ex.StackTrace);
                            }
                            else
                            {
                                Debug.LogError("Exception while processing the Material Library. Entry is null! ##Exception: " + ex.Message + " ##Stack Trace: " + ex.StackTrace);
                            }
                        }
                        currentEntry++;
                    }
                }
                catch (Exception ex)
                {
                    Debug.LogError("Exception while processing the Material Library. ##Exception: " + ex.Message + " ##Stack Trace: " + ex.StackTrace);
                }
            }

            Terrain[] terrains = Terrain.activeTerrains;
            if (terrains != null)
            {
                foreach (Terrain terrain in terrains)
                {
                    terrain.UpdateGIMaterials();
                    terrain.Flush();
                }
            }

            if (updateChanges)
            {
                AssetDatabase.SaveAssets();
                AssetDatabase.Refresh();
            }

            if (promptRenderPipelineMaterialUpdate)
            {
                GaiaUtils.DisplayDialogNoEditor("Please run the Pipeline Material upgrade process", "This project contains materials using the Unity Standard Shader. Please make sure to also run the Render Pipeline Material upgrade process to update those standard shaders. All shaders that are not updated via this process will not be displayed correctly in HDRP. Please look for the entry 'Upgrade Project Materials to High Definition Materials' under 'Edit > Render Pipelines' in your Window menu.", "OK", null);
            }

            FinishInstallingPackages();
        }