From 18c6dd79a3b25be3fade7e7c8330b699a02d4289 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dino=20Fejzagi=C4=87?= Date: Sat, 23 Jan 2021 14:44:56 +0100 Subject: [PATCH] Implement utility to check for used render pipeline (#766) * Implement utility to check for used render pipeline * Fix docs --- .../Definitions/Utilities/RenderPipeline.cs | 29 ++++++++++++++ .../Utilities/RenderPipeline.cs.meta | 11 ++++++ Runtime/Utilities/RenderPipelineUtilities.cs | 38 +++++++++++++++++++ .../Utilities/RenderPipelineUtilities.cs.meta | 11 ++++++ 4 files changed, 89 insertions(+) create mode 100644 Runtime/Definitions/Utilities/RenderPipeline.cs create mode 100644 Runtime/Definitions/Utilities/RenderPipeline.cs.meta create mode 100644 Runtime/Utilities/RenderPipelineUtilities.cs create mode 100644 Runtime/Utilities/RenderPipelineUtilities.cs.meta diff --git a/Runtime/Definitions/Utilities/RenderPipeline.cs b/Runtime/Definitions/Utilities/RenderPipeline.cs new file mode 100644 index 000000000..8362ce535 --- /dev/null +++ b/Runtime/Definitions/Utilities/RenderPipeline.cs @@ -0,0 +1,29 @@ +// Copyright (c) XRTK. All rights reserved. +// Licensed under the MIT License. See LICENSE in the project root for license information. + +namespace XRTK.Definitions.Utilities +{ + /// + /// Available render pipelines for use in Unity applications. + /// + public enum RenderPipeline + { + /// + /// The legacy "built-in" render pipeline of Unity that was deprecated + /// when scriptable render pipelines were introduced. + /// + Legacy = 0, + /// + /// The universal render pipeline, formerly also known as lightweight render pipeline. + /// + UniversalRenderPipeline, + /// + /// The high definition pipeline. + /// + HighDefinitionRenderPipeline, + /// + /// A customized scriptable render pipeline. + /// + Custom + } +} \ No newline at end of file diff --git a/Runtime/Definitions/Utilities/RenderPipeline.cs.meta b/Runtime/Definitions/Utilities/RenderPipeline.cs.meta new file mode 100644 index 000000000..27df4ea64 --- /dev/null +++ b/Runtime/Definitions/Utilities/RenderPipeline.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 42fc4a1663d5ed446a02d84a1684b2d5 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {fileID: 2800000, guid: 8ac5213854cf4dbabd140decf8df1946, type: 3} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Runtime/Utilities/RenderPipelineUtilities.cs b/Runtime/Utilities/RenderPipelineUtilities.cs new file mode 100644 index 000000000..2750162e0 --- /dev/null +++ b/Runtime/Utilities/RenderPipelineUtilities.cs @@ -0,0 +1,38 @@ +// Copyright (c) XRTK. All rights reserved. +// Licensed under the MIT License. See LICENSE in the project root for license information. + +using UnityEngine.Rendering; +using XRTK.Extensions; +using RenderPipeline = XRTK.Definitions.Utilities.RenderPipeline; + +namespace XRTK.Utilities +{ + public static class RenderPipelineUtilities + { + private const string urpAssetTypeName = "UniversalRenderPipelineAsset"; + private const string hdrpAssetTypeName = "HDRenderPipelineAsset"; + + /// + /// Gets the used by the project. + /// + /// The used by the project. + public static RenderPipeline GetActiveRenderingPipeline() + { + var renderPipelineAsset = GraphicsSettings.renderPipelineAsset; + if (renderPipelineAsset.IsNull()) + { + return RenderPipeline.Legacy; + } + + switch (renderPipelineAsset.GetType().Name) + { + case urpAssetTypeName: + return RenderPipeline.UniversalRenderPipeline; + case hdrpAssetTypeName: + return RenderPipeline.HighDefinitionRenderPipeline; + } + + return RenderPipeline.Custom; + } + } +} \ No newline at end of file diff --git a/Runtime/Utilities/RenderPipelineUtilities.cs.meta b/Runtime/Utilities/RenderPipelineUtilities.cs.meta new file mode 100644 index 000000000..06a981010 --- /dev/null +++ b/Runtime/Utilities/RenderPipelineUtilities.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 3a5e3e4cc8e21894aaf436407c14170f +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {fileID: 2800000, guid: 8ac5213854cf4dbabd140decf8df1946, type: 3} + userData: + assetBundleName: + assetBundleVariant: