//Making sure there is at least one HDRenderPipelineGlobalSettings instance in the project static internal HDRenderPipelineGlobalSettings Ensure(bool canCreateNewAsset = true) { if (instance == null || instance.Equals(null) || instance.m_Version == Version.First) { // Try to migrate HDRPAsset in Graphics. It can produce a HDRenderPipelineGlobalSettings // with data from former HDRPAsset if it is at a version allowing this. if (GraphicsSettings.defaultRenderPipeline is HDRenderPipelineAsset hdrpAsset && hdrpAsset.IsVersionBelowAddedHDRenderPipelineGlobalSettings()) { // if possible we need to finish migration of hdrpAsset in order to grab value from it (hdrpAsset as IMigratableAsset).Migrate(); } } if (instance == null || instance.Equals(null)) { //try load at default path HDRenderPipelineGlobalSettings loaded = AssetDatabase.LoadAssetAtPath <HDRenderPipelineGlobalSettings>($"Assets/{HDProjectSettingsReadOnlyBase.projectSettingsFolderPath}/HDRenderPipelineGlobalSettings.asset"); if (loaded == null) { //Use any available IEnumerator <HDRenderPipelineGlobalSettings> enumerator = CoreUtils.LoadAllAssets <HDRenderPipelineGlobalSettings>().GetEnumerator(); if (enumerator.MoveNext()) { loaded = enumerator.Current; } } if (loaded != null) { UpdateGraphicsSettings(loaded); } // No migration available and no asset available? Create one if allowed if (canCreateNewAsset && instance == null) { var createdAsset = Create($"Assets/{HDProjectSettingsReadOnlyBase.projectSettingsFolderPath}/HDRenderPipelineGlobalSettings.asset"); UpdateGraphicsSettings(createdAsset); Debug.LogWarning("No HDRP Global Settings Asset is assigned. One has been created for you. If you want to modify it, go to Project Settings > Graphics > HDRP Settings."); } if (instance == null) { Debug.LogError("Cannot find any HDRP Global Settings asset and Cannot create one from former used HDRP Asset."); } Debug.Assert(instance, "Could not create HDRP's Global Settings - HDRP may not work correctly - Open the Graphics Window for additional help."); } // Attempt upgrade (do notiong if up to date) IMigratableAsset migratableAsset = instance; if (!migratableAsset.IsAtLastVersion()) { migratableAsset.Migrate(); } return(instance); }
//Making sure there is at least one HDRenderPipelineGlobalSettings instance in the project static internal HDRenderPipelineGlobalSettings Ensure(bool canCreateNewAsset = true) { bool needsMigration = (assetToBeMigrated != null && !assetToBeMigrated.Equals(null)); if (HDRenderPipelineGlobalSettings.instance && !needsMigration) { return(HDRenderPipelineGlobalSettings.instance); } HDRenderPipelineGlobalSettings assetCreated = null; string path = "Assets/HDRPDefaultResources/HDRenderPipelineGlobalSettings.asset"; if (needsMigration) { if (HDRenderPipelineGlobalSettings.instance) { path = AssetDatabase.GetAssetPath(HDRenderPipelineGlobalSettings.instance); } assetCreated = MigrateFromHDRPAsset(assetToBeMigrated, path, bClearObsoleteFields: false, canCreateNewAsset: canCreateNewAsset); if (assetCreated != null && !assetCreated.Equals(null)) { assetToBeMigrated = null; } } else { assetCreated = AssetDatabase.LoadAssetAtPath <HDRenderPipelineGlobalSettings>(path); if (assetCreated == null) { var guidHDGlobalAssets = AssetDatabase.FindAssets("t:HDRenderPipelineGlobalSettings"); //If we could not find the asset at the default path, find the first one if (guidHDGlobalAssets.Length > 0) { var curGUID = guidHDGlobalAssets[0]; path = AssetDatabase.GUIDToAssetPath(curGUID); assetCreated = AssetDatabase.LoadAssetAtPath <HDRenderPipelineGlobalSettings>(path); } else if (canCreateNewAsset)// or create one altogether { if (!AssetDatabase.IsValidFolder("Assets/HDRPDefaultResources/")) { AssetDatabase.CreateFolder("Assets", "HDRPDefaultResources"); } assetCreated = Create(path); } else { Debug.LogError("Cannot migrate HDRP Asset to a new HDRP Global Settings asset. If you are building a Player, make sure to save an HDRP Global Settings asset by opening the project in the Editor."); return(null); } } } Debug.Assert(assetCreated, "Could not create HDRP's Global Settings - HDRP may not work correctly - Open the Graphics Window for additional help."); UpdateGraphicsSettings(assetCreated); return(HDRenderPipelineGlobalSettings.instance); }