-
Notifications
You must be signed in to change notification settings - Fork 817
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[content automatically redacted] touching PlatformDependent folder
- Loading branch information
1 parent
3973104
commit def6175
Showing
24 changed files
with
480 additions
and
345 deletions.
There are no files selected for viewing
90 changes: 90 additions & 0 deletions
90
...der-pipelines.core/Editor/RenderPipeline/RenderPipelineGlobalSettingsEndNameEditAction.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
using System; | ||
using UnityEngine; | ||
using UnityEngine.Rendering; | ||
|
||
namespace UnityEditor.Rendering | ||
{ | ||
/// <summary> | ||
/// <see cref="ProjectWindowCallback.EndNameEditAction"/> for <see cref="RenderPipelineGlobalSettings"/> | ||
/// </summary> | ||
public class RenderPipelineGlobalSettingsEndNameEditAction : ProjectWindowCallback.EndNameEditAction | ||
{ | ||
private Type renderPipelineType { get; set; } | ||
private Type renderPipelineGlobalSettingsType { get; set; } | ||
private RenderPipelineGlobalSettings source { get; set; } | ||
|
||
/// <inheritdoc/> | ||
public override void Action(int instanceId, string pathName, string resourceFile) | ||
{ | ||
RenderPipelineGlobalSettings assetCreated = RenderPipelineGlobalSettingsUtils.Create(renderPipelineGlobalSettingsType, pathName, source) as RenderPipelineGlobalSettings; | ||
|
||
if (renderPipelineType != null) | ||
{ | ||
if (assetCreated != null) | ||
GraphicsSettings.RegisterRenderPipelineSettings(renderPipelineType, assetCreated); | ||
else | ||
GraphicsSettings.UnregisterRenderPipelineSettings(renderPipelineType); | ||
} | ||
|
||
ProjectWindowUtil.ShowCreatedAsset(assetCreated); | ||
} | ||
|
||
private static string s_DefaultAssetName = "{0}.asset"; | ||
|
||
internal static RenderPipelineGlobalSettingsEndNameEditAction CreateEndNameEditAction( | ||
Type renderPipelineType, Type renderPipelineGlobalSettingsType, bool updateAssetOnGraphicsSettings, RenderPipelineGlobalSettings source = null) | ||
{ | ||
var action = ScriptableObject.CreateInstance<RenderPipelineGlobalSettingsEndNameEditAction>(); | ||
action.renderPipelineGlobalSettingsType = renderPipelineGlobalSettingsType; | ||
|
||
if (updateAssetOnGraphicsSettings) | ||
action.renderPipelineType = renderPipelineType; | ||
|
||
if (source != null) | ||
action.source = source; | ||
|
||
return action; | ||
} | ||
|
||
internal static void StartEndNameEditAction(RenderPipelineGlobalSettingsEndNameEditAction action, string pathName) | ||
{ | ||
ProjectWindowUtil.StartNameEditingIfProjectWindowExists( | ||
action.GetInstanceID(), | ||
action, | ||
pathName, | ||
CoreEditorStyles.globalSettingsIcon, | ||
null); | ||
} | ||
|
||
/// <summary> | ||
/// Creates a new <see cref="RenderPipelineGlobalSettings"/> of the given type for the given pipeline | ||
/// </summary> | ||
/// <typeparam name="TRenderPipeline"></typeparam> | ||
/// <typeparam name="TGlobalSettings"></typeparam> | ||
/// <param name="usePathFromCurrentSettings"></param> | ||
/// <param name="updateAssetOnGraphicsSettings"></param> | ||
public static void CreateNew<TRenderPipeline, TGlobalSettings>(bool usePathFromCurrentSettings = false, bool updateAssetOnGraphicsSettings = false) | ||
where TRenderPipeline : RenderPipeline | ||
where TGlobalSettings : RenderPipelineGlobalSettings | ||
{ | ||
string pathName = string.Format(s_DefaultAssetName, typeof(TGlobalSettings).Name); | ||
|
||
if (usePathFromCurrentSettings) | ||
{ | ||
var currentSettings = GraphicsSettings.GetSettingsForRenderPipeline(typeof(TRenderPipeline)); | ||
if (currentSettings != null) | ||
pathName = AssetDatabase.GenerateUniqueAssetPath(AssetDatabase.GetAssetPath(currentSettings)); | ||
} | ||
|
||
StartEndNameEditAction(CreateEndNameEditAction(typeof(TRenderPipeline), typeof(TGlobalSettings), updateAssetOnGraphicsSettings), pathName); | ||
} | ||
|
||
internal static void CloneFrom<TRenderPipeline, TGlobalSettings>(RenderPipelineGlobalSettings source, bool updateAssetOnGraphicsSettings = false) | ||
where TRenderPipeline : RenderPipeline | ||
where TGlobalSettings : RenderPipelineGlobalSettings | ||
{ | ||
var pathName = AssetDatabase.GenerateUniqueAssetPath(AssetDatabase.GetAssetPath(source)); | ||
StartEndNameEditAction(CreateEndNameEditAction(typeof(TRenderPipeline), typeof(TGlobalSettings), updateAssetOnGraphicsSettings, source), pathName); | ||
} | ||
} | ||
} |
3 changes: 3 additions & 0 deletions
3
...ipelines.core/Editor/RenderPipeline/RenderPipelineGlobalSettingsEndNameEditAction.cs.meta
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
26 changes: 26 additions & 0 deletions
26
...es/com.unity.render-pipelines.core/Runtime/RenderPipeline/RenderPipelineGlobalSettings.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
using System; | ||
|
||
namespace UnityEngine.Rendering | ||
{ | ||
/// <summary> | ||
/// A <see cref="ScriptableObject"/> to associate with a <see cref="RenderPipeline"/> and store project-wide settings for that pipeline. | ||
/// You can register a single <see cref="RenderPipelineGlobalSettings"/> instance to the <see cref="GraphicsSettings"/> by using <see cref="Rendering.GraphicsSettings.RegisterRenderPipelineSettings"/>. You can use this to save `RenderPipeline` settings that appear in `GraphicsSettings`. | ||
/// </summary> | ||
/// <typeparam name="TGlobalRenderPipelineSettings"><see cref="RenderPipelineGlobalSettings"/></typeparam> | ||
/// <typeparam name="TRenderPipeline"><see cref="RenderPipeline"/></typeparam> | ||
public abstract class RenderPipelineGlobalSettings<TGlobalRenderPipelineSettings, TRenderPipeline> : RenderPipelineGlobalSettings | ||
where TRenderPipeline : RenderPipeline | ||
where TGlobalRenderPipelineSettings : RenderPipelineGlobalSettings | ||
{ | ||
/// <summary> | ||
/// Active Global Settings asset. If the value is `null` then no `TGlobalRenderPipelineSettings` is registered to the Graphics Settings with the `TRenderPipeline`. | ||
/// </summary> | ||
#if UNITY_EDITOR | ||
public static TGlobalRenderPipelineSettings instance => | ||
GraphicsSettings.GetSettingsForRenderPipeline<TRenderPipeline>() as TGlobalRenderPipelineSettings; | ||
#else | ||
public static TGlobalRenderPipelineSettings instance => s_Instance.Value; | ||
private static Lazy<TGlobalRenderPipelineSettings> s_Instance = new (() => GraphicsSettings.GetSettingsForRenderPipeline<TRenderPipeline>() as TGlobalRenderPipelineSettings); | ||
#endif | ||
} | ||
} |
3 changes: 3 additions & 0 deletions
3
...m.unity.render-pipelines.core/Runtime/RenderPipeline/RenderPipelineGlobalSettings.cs.meta
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
142 changes: 142 additions & 0 deletions
142
...m.unity.render-pipelines.core/Runtime/RenderPipeline/RenderPipelineGlobalSettingsUtils.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,142 @@ | ||
#if UNITY_EDITOR | ||
using System; | ||
using System.Linq; | ||
using System.Reflection; | ||
using UnityEditor; | ||
|
||
namespace UnityEngine.Rendering | ||
{ | ||
/// <summary> | ||
/// Set of utilities for <see cref="RenderPipelineGlobalSettings"/> | ||
/// </summary> | ||
public class RenderPipelineGlobalSettingsUtils | ||
{ | ||
/// <summary> | ||
/// Creates a <see cref="RenderPipelineGlobalSettings"/> asset | ||
/// </summary> | ||
/// <param name="path">The path where Unity generates the asset.</param> | ||
/// <param name="dataSource">Another `RenderPipelineGlobalSettings` that Unity uses as a data source.</param> | ||
/// <typeparam name="TGlobalSetting"><see cref="RenderPipelineGlobalSettings"/> </typeparam> | ||
/// <returns>Returns the asset created.</returns> | ||
public static TGlobalSetting Create<TGlobalSetting>(string path, TGlobalSetting dataSource = null) | ||
where TGlobalSetting : RenderPipelineGlobalSettings | ||
{ | ||
return Create(typeof(TGlobalSetting), path, dataSource) as TGlobalSetting; | ||
} | ||
|
||
/// <summary> | ||
/// Creates a <see cref="RenderPipelineGlobalSettings"/> asset | ||
/// </summary> | ||
/// <param name="renderPipelineGlobalSettingsType"></param> | ||
/// <param name="path">The path where Unity generates the asset.</param> | ||
/// <param name="dataSource">Another `RenderPipelineGlobalSettings` that Unity uses as a data source.</param> | ||
/// <returns>Returns the asset created.</returns> | ||
public static RenderPipelineGlobalSettings Create(Type renderPipelineGlobalSettingsType, string path, RenderPipelineGlobalSettings dataSource = null) | ||
{ | ||
if (!typeof(RenderPipelineGlobalSettings).IsAssignableFrom(renderPipelineGlobalSettingsType)) | ||
throw new ArgumentException( | ||
$"{nameof(renderPipelineGlobalSettingsType)} must be a valid {typeof(RenderPipelineGlobalSettings)}"); | ||
|
||
// Sanitize the path | ||
if (string.IsNullOrEmpty(path)) | ||
path = $"Assets/{renderPipelineGlobalSettingsType.Name}.asset"; | ||
|
||
if (!path.StartsWith("assets/", StringComparison.CurrentCultureIgnoreCase)) | ||
path = $"Assets/{path}"; | ||
|
||
CoreUtils.EnsureFolderTreeInAssetFilePath(path); | ||
path = AssetDatabase.GenerateUniqueAssetPath(path); | ||
|
||
var assetCreated = ScriptableObject.CreateInstance(renderPipelineGlobalSettingsType) as RenderPipelineGlobalSettings; | ||
if (assetCreated) | ||
{ | ||
AssetDatabase.CreateAsset(assetCreated, path); | ||
|
||
// copy data from provided source | ||
if (dataSource != null) | ||
EditorUtility.CopySerializedManagedFieldsOnly(dataSource, assetCreated); | ||
|
||
assetCreated.Initialize(dataSource); | ||
|
||
AssetDatabase.SaveAssets(); | ||
AssetDatabase.Refresh(); | ||
} | ||
|
||
return assetCreated; | ||
} | ||
|
||
/// <summary> | ||
/// Checks that a <see cref="RenderPipelineGlobalSettings"/> asset exists. | ||
/// If the asset isn't valid, Unity tries the following in order: | ||
/// 1. Loads the asset at the default path. | ||
/// 2. Finds any asset in the project with the same type. | ||
/// 3. If `canCreateNewAsset` is true, creates a new asset in the default path. | ||
/// If Unity finds or creates a valid asset, Unity updates the <see cref="GraphicsSettings"/> with it. Otherwise Unity will unregister the settings for the given pipeline. | ||
/// </summary> | ||
/// <param name="instance">The current instance of the asset.</param> | ||
/// <param name="defaultPath">The default path.</param> | ||
/// <param name="canCreateNewAsset">If set to `true`, Unity creates a new asset if it can't find an existing asset in the project.</param> | ||
/// <typeparam name="TGlobalSetting">The type of global settings asset to check.</typeparam> | ||
/// <typeparam name="TRenderPipeline">The type of `RenderPipeline` that this asset belongs to.</typeparam> | ||
/// <returns>The asset that Unity found or created, or `null` if Unity can't find or create a valid asset.</returns> | ||
public static bool TryEnsure<TGlobalSetting, TRenderPipeline>(ref TGlobalSetting instance, string defaultPath = "", bool canCreateNewAsset = true) | ||
where TGlobalSetting : RenderPipelineGlobalSettings<TGlobalSetting, TRenderPipeline> | ||
where TRenderPipeline : RenderPipeline | ||
{ | ||
if (!TryEnsure<TGlobalSetting, TRenderPipeline>(ref instance, defaultPath, canCreateNewAsset, out var error)) | ||
{ | ||
Debug.LogError(error.Message); | ||
return false; | ||
} | ||
|
||
return true; | ||
} | ||
|
||
// This method is exposed to Unit Tests | ||
internal static bool TryEnsure<TGlobalSetting, TRenderPipeline>(ref TGlobalSetting instance, string defaultPath, bool canCreateNewAsset, out Exception error) | ||
where TGlobalSetting : RenderPipelineGlobalSettings<TGlobalSetting, TRenderPipeline> | ||
where TRenderPipeline : RenderPipeline | ||
{ | ||
var globalSettingsName = typeof(TGlobalSetting).GetCustomAttribute<DisplayInfoAttribute>()?.name ?? typeof(TGlobalSetting).Name; | ||
|
||
if (instance == null || instance.Equals(null)) | ||
{ | ||
if (!string.IsNullOrEmpty(defaultPath)) | ||
{ | ||
// Look at default path, if the asset exist, is the one that we need | ||
instance = AssetDatabase.LoadAssetAtPath<TGlobalSetting>(defaultPath); | ||
} | ||
|
||
if (instance == null) | ||
{ | ||
// There was not saved into the default path, fetch the asset database to see if there is one defined in the project | ||
instance = CoreUtils.LoadAllAssets<TGlobalSetting>().FirstOrDefault(); | ||
if (instance == null) | ||
{ | ||
// Try to create one if possible | ||
if (canCreateNewAsset) | ||
{ | ||
instance = Create<TGlobalSetting>(defaultPath); | ||
if (instance != null) | ||
{ | ||
Debug.LogWarning($"{globalSettingsName} has been created for you. If you want to modify it, go to Project Settings > Graphics > {globalSettingsName}"); | ||
} | ||
} | ||
} | ||
} | ||
} | ||
|
||
if (instance == null || instance.Equals(null)) | ||
{ | ||
error = new Exception($"Unable to find or create a {globalSettingsName}. The configured Render Pipeline may not work correctly. Go to Project Settings > Graphics > {globalSettingsName} for additional help."); | ||
GraphicsSettings.UnregisterRenderPipelineSettings<TRenderPipeline>(); | ||
return false; | ||
} | ||
|
||
error = null; | ||
GraphicsSettings.RegisterRenderPipelineSettings<TRenderPipeline>(instance); | ||
return true; | ||
} | ||
} | ||
} | ||
#endif |
2 changes: 1 addition & 1 deletion
2
...nderPipelineGlobalSettingsCreator.cs.meta → ...RenderPipelineGlobalSettingsUtils.cs.meta
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
3 changes: 3 additions & 0 deletions
3
Packages/com.unity.render-pipelines.core/Tests/Editor/RenderPipeline.meta
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Oops, something went wrong.