浏览代码
[HDLoop] Use scene singleton pattern for skysettings and common settings. The idea is that when a scene is activated we look to see if there are any override settings in that scene; if so we apply them. If there are no override settings we just do the default.
/main
[HDLoop] Use scene singleton pattern for skysettings and common settings. The idea is that when a scene is activated we look to see if there are any override settings in that scene; if so we apply them. If there are no override settings we just do the default.
/main
Tim Cooper
8 年前
当前提交
c3449ff8
共有 15 个文件被更改,包括 280 次插入 和 159 次删除
-
17Assets/ScriptableRenderLoop/HDRenderPipeline/Editor/HDRenderPipelineMenuItems.cs
-
39Assets/ScriptableRenderLoop/HDRenderPipeline/HDRenderPipeline.cs
-
106Assets/ScriptableRenderLoop/HDRenderPipeline/SceneSettings/CommonSettings.cs
-
6Assets/ScriptableRenderLoop/HDRenderPipeline/SceneSettings/Editor/CommonSettingsEditor.cs
-
4Assets/ScriptableRenderLoop/HDRenderPipeline/Sky/ProceduralSky/ProceduralSkyParameters.cs
-
107Assets/ScriptableRenderLoop/HDRenderPipeline/Sky/SkyManager.cs
-
8Assets/ScriptableRenderLoop/HDRenderPipeline/Sky/SkyParameters.cs
-
3Assets/ScriptableRenderLoop/HDRenderPipeline/Sky/SkyRenderer.cs
-
2Assets/ScriptableRenderLoop/RenderPasses/ShadowRenderPass.cs
-
41Assets/ScriptableRenderLoop/HDRenderPipeline/SceneSettings/CommonSettingsSingleton.cs
-
12Assets/ScriptableRenderLoop/HDRenderPipeline/SceneSettings/CommonSettingsSingleton.cs.meta
-
30Assets/ScriptableRenderLoop/HDRenderPipeline/Sky/SkyParametersSingleton.cs
-
12Assets/ScriptableRenderLoop/HDRenderPipeline/Sky/SkyParametersSingleton.cs.meta
-
40Assets/ScriptableRenderLoop/core/Singleton.cs
-
12Assets/ScriptableRenderLoop/core/Singleton.cs.meta
|
|||
using System.Linq; |
|||
using UnityEngine.SceneManagement; |
|||
|
|||
namespace UnityEngine.Experimental.Rendering.HDPipeline |
|||
{ |
|||
public class CommonSettingsSingleton : Singleton<CommonSettingsSingleton> |
|||
{ |
|||
private CommonSettings.Settings settings { get; set; } |
|||
|
|||
public static CommonSettings.Settings overrideSettings |
|||
{ |
|||
get { return instance.settings; } |
|||
} |
|||
|
|||
protected override void OnEnable() |
|||
{ |
|||
SceneManager.activeSceneChanged += SceneManagerOnActiveSceneChanged; |
|||
} |
|||
|
|||
protected override void OnDisable() |
|||
{ |
|||
SceneManager.activeSceneChanged -= SceneManagerOnActiveSceneChanged; |
|||
} |
|||
|
|||
protected override void SceneManagerOnActiveSceneChanged(Scene from, Scene to) |
|||
{ |
|||
Refresh(); |
|||
} |
|||
|
|||
public static void Refresh() |
|||
{ |
|||
instance.settings = null; |
|||
|
|||
//TODO: Slow, and linq, make good and fast
|
|||
var overrideSettings = FindObjectsOfType<CommonSettings>().Where(x => x.isActiveAndEnabled && x.gameObject.scene == SceneManager.GetActiveScene()); |
|||
if (overrideSettings.Any()) |
|||
instance.settings = overrideSettings.FirstOrDefault().settings; |
|||
} |
|||
|
|||
} |
|||
} |
|
|||
fileFormatVersion: 2 |
|||
guid: dcb3649c420bf2d4093ab76418541c0f |
|||
timeCreated: 1485087502 |
|||
licenseType: Pro |
|||
MonoImporter: |
|||
serializedVersion: 2 |
|||
defaultReferences: [] |
|||
executionOrder: 0 |
|||
icon: {instanceID: 0} |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
using System.Linq; |
|||
using UnityEngine.SceneManagement; |
|||
|
|||
namespace UnityEngine.Experimental.Rendering.HDPipeline |
|||
{ |
|||
public class SkyParametersSingleton : Singleton<SkyParametersSingleton> |
|||
{ |
|||
private SkyParameters settings { get; set; } |
|||
|
|||
public static SkyParameters overrideSettings |
|||
{ |
|||
get { return instance.settings; } |
|||
} |
|||
|
|||
protected override void SceneManagerOnActiveSceneChanged(Scene from, Scene to) |
|||
{ |
|||
Refresh(); |
|||
} |
|||
|
|||
public static void Refresh() |
|||
{ |
|||
instance.settings = null; |
|||
|
|||
//TODO: Slow, and linq, make good and fast
|
|||
var overrideSettings = FindObjectsOfType<SkyParameters>().Where(x => x.isActiveAndEnabled && x.gameObject.scene == SceneManager.GetActiveScene()); |
|||
if (overrideSettings.Any()) |
|||
instance.settings = overrideSettings.FirstOrDefault(); |
|||
} |
|||
} |
|||
} |
|
|||
fileFormatVersion: 2 |
|||
guid: 6b9acc7ad27501c4bbcd5d6d5a7fb218 |
|||
timeCreated: 1485096567 |
|||
licenseType: Pro |
|||
MonoImporter: |
|||
serializedVersion: 2 |
|||
defaultReferences: [] |
|||
executionOrder: 0 |
|||
icon: {instanceID: 0} |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
using UnityEngine.SceneManagement; |
|||
|
|||
namespace UnityEngine.Experimental.Rendering |
|||
{ |
|||
[ExecuteInEditMode] |
|||
public abstract class Singleton<T> : ScriptableObject where T : ScriptableObject |
|||
{ |
|||
private static T theInstance { get; set; } |
|||
|
|||
protected static T instance |
|||
{ |
|||
get |
|||
{ |
|||
LoadAsset(); |
|||
return theInstance; |
|||
} |
|||
} |
|||
|
|||
protected virtual void OnEnable() |
|||
{ |
|||
SceneManager.activeSceneChanged += SceneManagerOnActiveSceneChanged; |
|||
} |
|||
|
|||
protected virtual void OnDisable() |
|||
{ |
|||
SceneManager.activeSceneChanged -= SceneManagerOnActiveSceneChanged; |
|||
} |
|||
|
|||
protected abstract void SceneManagerOnActiveSceneChanged(Scene arg0, Scene arg1); |
|||
|
|||
static void LoadAsset() |
|||
{ |
|||
if (!theInstance) |
|||
{ |
|||
theInstance = CreateInstance<T>(); |
|||
theInstance.hideFlags = HideFlags.HideAndDontSave; |
|||
} |
|||
} |
|||
} |
|||
} |
|
|||
fileFormatVersion: 2 |
|||
guid: a8e809a4a46fd8046a7e3a4f172585f0 |
|||
timeCreated: 1485087282 |
|||
licenseType: Pro |
|||
MonoImporter: |
|||
serializedVersion: 2 |
|||
defaultReferences: [] |
|||
executionOrder: 0 |
|||
icon: {instanceID: 0} |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
撰写
预览
正在加载...
取消
保存
Reference in new issue