mathe/Library/PackageCache/com.unity.render-pipelines.core@14.0.8/Editor/BuildTargetExtensions.cs
2024-09-20 20:30:10 +02:00

47 lines
2.1 KiB
C#

using JetBrains.Annotations;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using UnityEngine;
using UnityEngine.Rendering;
namespace UnityEditor.Rendering
{
/// <summary>
/// Extensions for <see cref="BuildTarget"/>
/// </summary>
public static class BuildTargetExtensions
{
/// <summary>
/// Obtains a list of the <see cref="RenderPipelineAsset"/> that are references into the settings either on <see cref="QualitySettings"/> or in <see cref="GraphicsSettings"/>
/// </summary>
/// <typeparam name="T">The type of <see cref="RenderPipelineAsset"/></typeparam>
/// <param name="buildTarget">The <see cref="BuildTarget"/> to obtain the assets.</param>
/// <param name="srpAssets">The output list of <see cref="RenderPipelineAsset"/> that are referenced by the platform.</param>
/// <returns>false if there was an error fetching the <see cref="RenderPipelineAsset"/> for this <see cref="BuildTarget"/></returns>
[MustUseReturnValue]
public static bool TryGetRenderPipelineAssets<T>([DisallowNull] this BuildTarget buildTarget, List<T> srpAssets)
where T : RenderPipelineAsset
{
if (srpAssets == null)
return false;
var activeBuildTargetGroup = BuildPipeline.GetBuildTargetGroup(buildTarget);
var activeBuildTargetGroupName = activeBuildTargetGroup.ToString();
QualitySettings.GetRenderPipelineAssetsForPlatform<T>(activeBuildTargetGroupName, out var buildPipelineAssets);
srpAssets.AddRange(buildPipelineAssets);
int count = QualitySettings.GetActiveQualityLevelsForPlatformCount(activeBuildTargetGroupName);
var allQualityLevelsAreOverriden = buildPipelineAssets.Count == count;
if (count == 0 || !allQualityLevelsAreOverriden)
{
// We need to check the fallback cases
if (GraphicsSettings.defaultRenderPipeline is T srpAsset)
srpAssets.Add(srpAsset);
}
return true;
}
}
}