浏览代码

[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 次删除
  1. 17
      Assets/ScriptableRenderLoop/HDRenderPipeline/Editor/HDRenderPipelineMenuItems.cs
  2. 39
      Assets/ScriptableRenderLoop/HDRenderPipeline/HDRenderPipeline.cs
  3. 106
      Assets/ScriptableRenderLoop/HDRenderPipeline/SceneSettings/CommonSettings.cs
  4. 6
      Assets/ScriptableRenderLoop/HDRenderPipeline/SceneSettings/Editor/CommonSettingsEditor.cs
  5. 4
      Assets/ScriptableRenderLoop/HDRenderPipeline/Sky/ProceduralSky/ProceduralSkyParameters.cs
  6. 107
      Assets/ScriptableRenderLoop/HDRenderPipeline/Sky/SkyManager.cs
  7. 8
      Assets/ScriptableRenderLoop/HDRenderPipeline/Sky/SkyParameters.cs
  8. 3
      Assets/ScriptableRenderLoop/HDRenderPipeline/Sky/SkyRenderer.cs
  9. 2
      Assets/ScriptableRenderLoop/RenderPasses/ShadowRenderPass.cs
  10. 41
      Assets/ScriptableRenderLoop/HDRenderPipeline/SceneSettings/CommonSettingsSingleton.cs
  11. 12
      Assets/ScriptableRenderLoop/HDRenderPipeline/SceneSettings/CommonSettingsSingleton.cs.meta
  12. 30
      Assets/ScriptableRenderLoop/HDRenderPipeline/Sky/SkyParametersSingleton.cs
  13. 12
      Assets/ScriptableRenderLoop/HDRenderPipeline/Sky/SkyParametersSingleton.cs.meta
  14. 40
      Assets/ScriptableRenderLoop/core/Singleton.cs
  15. 12
      Assets/ScriptableRenderLoop/core/Singleton.cs.meta

17
Assets/ScriptableRenderLoop/HDRenderPipeline/Editor/HDRenderPipelineMenuItems.cs


{
public class HDRenderPipelineMenuItems
{
[MenuItem("HDRenderPipeline/Create Scene Settings")]
static void CreateSceneSettings()
{
CommonSettings[] settings = Object.FindObjectsOfType<CommonSettings>();
if (settings.Length == 0)
{
GameObject go = new GameObject { name = "SceneSettings" };
go.AddComponent<CommonSettings>();
go.AddComponent<PostProcessing>();
}
else
{
Debug.LogWarning("SceneSettings has already been created.");
}
}
[MenuItem("HDRenderPipeline/Synchronize all Layered materials")]
static void SynchronizeAllLayeredMaterial()
{

39
Assets/ScriptableRenderLoop/HDRenderPipeline/HDRenderPipeline.cs


get { return m_TileSettings; }
}
CommonSettings m_CommonSettings;
public CommonSettings commonSettings
public void UpdateCommonSettings()
set { m_CommonSettings = value; }
get { return m_CommonSettings; }
}
var commonSettings = CommonSettingsSingleton.overrideSettings;
public void UpdateCommonSettings()
{
if (commonSettings == null)
{
m_ShadowSettings.maxShadowDistance = ShadowSettings.Default.maxShadowDistance;

// This must be allocate outside of Build() else the option in the class can't be set in the inspector (as it will in this case recreate the class with default value)
//readonly BaseLightLoop m_lightLoop;
SkyManager m_SkyManager;
public SkyManager skyManager
{

{
m_SkyManager = new SkyManager();
m_SkyManager.skyParameters = Object.FindObjectOfType<SkyParameters>();
m_SkyManager.skyParameters = SkyParametersSingleton.overrideSettings;
}
return m_SkyManager;
}

get { return m_Owner.debugParameters; }
}
private CommonSettings commonSettings
{
get { return m_Owner.commonSettings; }
}
m_SkyManager.InstantiateSkyRenderer(skyRendererType);
skyManager.InstantiateSkyRenderer(skyRendererType);
}
public HDRenderPipelineInstance(HDRenderPipeline owner)

m_LitRenderLoop.Cleanup();
Utilities.Destroy(m_DebugViewMaterialGBuffer);
m_SkyManager.Cleanup();
skyManager.Cleanup();
#if UNITY_EDITOR
SupportedRenderingFeatures.active = SupportedRenderingFeatures.Default;

// TODO: This is the wrong way to handle resize/allocation. We can have several different camera here, mean that the loop on camera will allocate and deallocate
// the below buffer which is bad. Best is to have a set of buffer for each camera that is persistent and reallocate resource if need
// For now consider we have only one camera that go to this code, the main one.
m_SkyManager.Resize(); // TODO: Also a bad naming, here we just want to realloc texture if skyparameters change (usefull for lookdev)
skyManager.Resize(); // TODO: Also a bad naming, here we just want to realloc texture if skyparameters change (usefull for lookdev)
if (camera.pixelWidth != m_CurrentWidth || camera.pixelHeight != m_CurrentHeight || m_lightLoop.NeedResize())
{

public void PushGlobalParams(HDCamera hdCamera, ScriptableRenderContext renderContext)
{
if (m_SkyManager.IsSkyValid())
if (skyManager.IsSkyValid())
m_SkyManager.SetGlobalSkyTexture();
skyManager.SetGlobalSkyTexture();
Shader.SetGlobalInt("_EnvLightSkyEnabled", 1);
}
else

// for artists to do lighting work until the fully-featured framework is ready
var localPostProcess = camera.GetComponent<PostProcessing>();
var globalPostProcess = commonSettings == null
/*var globalPostProcess = commonSettings == null
: commonSettings.GetComponent<PostProcessing>();
: commonSettings.GetComponent<PostProcessing>();*/
bool globalActive = globalPostProcess != null && globalPostProcess.enabled;
// bool globalActive = globalPostProcess != null && globalPostProcess.enabled;
if (!localActive && !globalActive)
// if (!localActive && !globalActive)
{
var cmd = new CommandBuffer { name = "" };
cmd.Blit(m_CameraColorBufferRT, BuiltinRenderTextureType.CameraTarget);

}
var target = localActive ? localPostProcess : globalPostProcess;
target.Render(camera, renderContext, m_CameraColorBufferRT, BuiltinRenderTextureType.CameraTarget);
/*var target = localActive ? localPostProcess : globalPostProcess;
target.Render(camera, renderContext, m_CameraColorBufferRT, BuiltinRenderTextureType.CameraTarget);*/
}
}

106
Assets/ScriptableRenderLoop/HDRenderPipeline/SceneSettings/CommonSettings.cs


using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using System.Linq;
using System.Reflection;
public class CommonSettings
: MonoBehaviour
public class CommonSettings : MonoBehaviour
[SerializeField] private string m_SkyRendererTypeName = ""; // Serialize a string because serialize a Type.
[Serializable]
public class Settings
{
[SerializeField]
string m_SkyRendererTypeName = ""; // Serialize a string because serialize a Type.
[SerializeField]
float m_ShadowMaxDistance = ShadowSettings.Default.maxShadowDistance;
[SerializeField]
int m_ShadowCascadeCount = ShadowSettings.Default.directionalLightCascadeCount;
[SerializeField] float m_ShadowMaxDistance = ShadowSettings.Default.maxShadowDistance;
[SerializeField] int m_ShadowCascadeCount = ShadowSettings.Default.directionalLightCascadeCount;
[SerializeField] float m_ShadowCascadeSplit0 = ShadowSettings.Default.directionalLightCascades.x;
[SerializeField] float m_ShadowCascadeSplit1 = ShadowSettings.Default.directionalLightCascades.y;
[SerializeField] float m_ShadowCascadeSplit2 = ShadowSettings.Default.directionalLightCascades.z;
[SerializeField]
float m_ShadowCascadeSplit0 = ShadowSettings.Default.directionalLightCascades.x;
public Type skyRendererType
{
set { m_SkyRendererTypeName = value != null ? value.FullName : ""; OnSkyRendererChanged(); }
get { return m_SkyRendererTypeName == "" ? null : Assembly.GetAssembly(typeof(CommonSettings)).GetType(m_SkyRendererTypeName); }
}
[SerializeField]
float m_ShadowCascadeSplit1 = ShadowSettings.Default.directionalLightCascades.y;
public float shadowMaxDistance { set { m_ShadowMaxDistance = value; OnValidate(); } get { return m_ShadowMaxDistance; } }
public int shadowCascadeCount { set { m_ShadowCascadeCount = value; OnValidate(); } get { return m_ShadowCascadeCount; } }
public float shadowCascadeSplit0 { set { m_ShadowCascadeSplit0 = value; OnValidate(); } get { return m_ShadowCascadeSplit0; } }
public float shadowCascadeSplit1 { set { m_ShadowCascadeSplit1 = value; OnValidate(); } get { return m_ShadowCascadeSplit1; } }
public float shadowCascadeSplit2 { set { m_ShadowCascadeSplit2 = value; OnValidate(); } get { return m_ShadowCascadeSplit2; } }
[SerializeField]
float m_ShadowCascadeSplit2 = ShadowSettings.Default.directionalLightCascades.z;
public float shadowMaxDistance { set { m_ShadowMaxDistance = value; OnValidate(); } get { return m_ShadowMaxDistance; } }
public int shadowCascadeCount { set { m_ShadowCascadeCount = value; OnValidate(); } get { return m_ShadowCascadeCount; } }
public float shadowCascadeSplit0 { set { m_ShadowCascadeSplit0 = value; OnValidate(); } get { return m_ShadowCascadeSplit0; } }
public float shadowCascadeSplit1 { set { m_ShadowCascadeSplit1 = value; OnValidate(); } get { return m_ShadowCascadeSplit1; } }
public float shadowCascadeSplit2 { set { m_ShadowCascadeSplit2 = value; OnValidate(); } get { return m_ShadowCascadeSplit2; } }
void OnEnable()
{
HDRenderPipeline renderPipeline = Utilities.GetHDRenderPipeline();
if (renderPipeline == null)
public void OnValidate()
return;
m_ShadowMaxDistance = Mathf.Max(0.0f, m_ShadowMaxDistance);
m_ShadowCascadeCount = Math.Min(4, Math.Max(1, m_ShadowCascadeCount));
m_ShadowCascadeSplit0 = Mathf.Min(1.0f, Mathf.Max(0.0f, m_ShadowCascadeSplit0));
m_ShadowCascadeSplit1 = Mathf.Min(1.0f, Mathf.Max(0.0f, m_ShadowCascadeSplit1));
m_ShadowCascadeSplit2 = Mathf.Min(1.0f, Mathf.Max(0.0f, m_ShadowCascadeSplit2));
}
if (renderPipeline.commonSettings == null)
renderPipeline.commonSettings = this;
else if (renderPipeline.commonSettings != this)
Debug.LogWarning("Only one CommonSettings can be setup at a time.");
[SerializeField]
private Settings m_Settings = new Settings();
OnSkyRendererChanged();
public Settings settings
{
get { return m_Settings; }
void OnDisable()
public void OnEnable()
HDRenderPipeline renderPipeline = Utilities.GetHDRenderPipeline();
if (renderPipeline == null)
{
return;
}
CommonSettingsSingleton.Refresh();
}
if (renderPipeline.commonSettings == this)
renderPipeline.commonSettings = null;
public void OnDisable()
{
CommonSettingsSingleton.Refresh();
m_ShadowMaxDistance = Mathf.Max(0.0f, m_ShadowMaxDistance);
m_ShadowCascadeCount = Math.Min(4, Math.Max(1, m_ShadowCascadeCount));
m_ShadowCascadeSplit0 = Mathf.Min(1.0f, Mathf.Max(0.0f, m_ShadowCascadeSplit0));
m_ShadowCascadeSplit1 = Mathf.Min(1.0f, Mathf.Max(0.0f, m_ShadowCascadeSplit1));
m_ShadowCascadeSplit2 = Mathf.Min(1.0f, Mathf.Max(0.0f, m_ShadowCascadeSplit2));
OnSkyRendererChanged();
if (settings != null)
settings.OnValidate();
void OnSkyRendererChanged()
/* public Type skyRendererType
{
set { settings.m_SkyRendererTypeName = value != null ? value.FullName : ""; OnSkyRendererChanged(); }
get { return settings.m_SkyRendererTypeName == "" ? null : Assembly.GetAssembly(typeof(CommonSettings)).GetType(settings.m_SkyRendererTypeName); }
}*/
}
/* void OnSkyRendererChanged()
{
HDRenderPipeline renderPipeline = Utilities.GetHDRenderPipeline();
if (renderPipeline == null)

gameObject.AddComponent(skyParamType);
}
}
}
}*/
}

6
Assets/ScriptableRenderLoop/HDRenderPipeline/SceneSettings/Editor/CommonSettingsEditor.cs


for (int i = 0; i < targets.Length; ++i)
{
CommonSettings settings = targets[i] as CommonSettings;
maxCascadeCount = Math.Max(maxCascadeCount, settings.shadowCascadeCount);
maxCascadeCount = Math.Max(maxCascadeCount, settings.settings.shadowCascadeCount);
}
EditorGUI.indentLevel++;

EditorGUI.indentLevel--;
}
public override void OnInspectorGUI()
/* public override void OnInspectorGUI()
{
serializedObject.Update();

serializedObject.ApplyModifiedProperties();
}
}*/
}
}

4
Assets/ScriptableRenderLoop/HDRenderPipeline/Sky/ProceduralSky/ProceduralSkyParameters.cs


using System.Collections;
using System.Collections.Generic;
using UnityEngine;
namespace UnityEngine.Experimental.Rendering.HDPipeline
{
[ExecuteInEditMode]

107
Assets/ScriptableRenderLoop/HDRenderPipeline/Sky/SkyManager.cs


using UnityEngine.Rendering;
using UnityEngine.Experimental.Rendering.HDPipeline;
using System;
namespace UnityEngine.Experimental.Rendering.HDPipeline

public void UpdateEnvironment(HDCamera camera, Light sunLight, ScriptableRenderContext renderContext)
{
using (new Utilities.ProfilingSample("Sky Environment Pass", renderContext))
using (new Utilities.ProfilingSample("Sky Environment Pass", renderContext))
if (IsSkyValid())
if (IsSkyValid())
{
m_CurrentUpdateTime += Time.deltaTime;
m_CurrentUpdateTime += Time.deltaTime;
m_BuiltinParameters.renderContext = renderContext;
m_BuiltinParameters.sunLight = sunLight;
m_BuiltinParameters.renderContext = renderContext;
m_BuiltinParameters.sunLight = sunLight;
// We need one frame delay for this update to work since DynamicGI.UpdateEnvironment is executed direclty but the renderloop is not (so we need to wait for the sky texture to be rendered first)
if (m_NeedLowLevelUpdateEnvironment)
{
// TODO: Properly send the cubemap to Enlighten. Currently workaround is to set the cubemap in a Skybox/cubemap material
m_StandardSkyboxMaterial.SetTexture("_Tex", m_SkyboxCubemapRT);
RenderSettings.skybox = m_StandardSkyboxMaterial; // Setup this material as the default to be use in RenderSettings
RenderSettings.ambientIntensity = 1.0f; // fix this to 1, this parameter should not exist!
RenderSettings.ambientMode = UnityEngine.Rendering.AmbientMode.Skybox; // Force skybox for our HDRI
RenderSettings.reflectionIntensity = 1.0f;
RenderSettings.customReflection = null;
DynamicGI.UpdateEnvironment();
// We need one frame delay for this update to work since DynamicGI.UpdateEnvironment is executed direclty but the renderloop is not (so we need to wait for the sky texture to be rendered first)
if (m_NeedLowLevelUpdateEnvironment)
{
// TODO: Properly send the cubemap to Enlighten. Currently workaround is to set the cubemap in a Skybox/cubemap material
m_StandardSkyboxMaterial.SetTexture("_Tex", m_SkyboxCubemapRT);
RenderSettings.skybox = m_StandardSkyboxMaterial; // Setup this material as the default to be use in RenderSettings
RenderSettings.ambientIntensity = 1.0f; // fix this to 1, this parameter should not exist!
RenderSettings.ambientMode = UnityEngine.Rendering.AmbientMode.Skybox; // Force skybox for our HDRI
RenderSettings.reflectionIntensity = 1.0f;
RenderSettings.customReflection = null;
DynamicGI.UpdateEnvironment();
m_NeedLowLevelUpdateEnvironment = false;
}
m_NeedLowLevelUpdateEnvironment = false;
}
if (
(skyParameters.updateMode == EnvironementUpdateMode.OnDemand && m_UpdateRequired) ||
(skyParameters.updateMode == EnvironementUpdateMode.OnChanged && skyParameters.GetHash() != m_SkyParametersHash) ||
(skyParameters.updateMode == EnvironementUpdateMode.Realtime && m_CurrentUpdateTime > skyParameters.updatePeriod)
)
{
// Render sky into a cubemap - doesn't happen every frame, can be controlled
RenderSkyToCubemap(m_BuiltinParameters, skyParameters, m_SkyboxCubemapRT);
// Note that m_SkyboxCubemapRT is created with auto-generate mipmap, it mean that here we have also our mipmap correctly box filtered for importance sampling.
if (
(skyParameters.updateMode == EnvironementUpdateMode.OnDemand && m_UpdateRequired) ||
(skyParameters.updateMode == EnvironementUpdateMode.OnChanged && skyParameters.GetHash() != m_SkyParametersHash) ||
(skyParameters.updateMode == EnvironementUpdateMode.Realtime && m_CurrentUpdateTime > skyParameters.updatePeriod)
)
{
// Render sky into a cubemap - doesn't happen every frame, can be controlled
RenderSkyToCubemap(m_BuiltinParameters, skyParameters, m_SkyboxCubemapRT);
// Note that m_SkyboxCubemapRT is created with auto-generate mipmap, it mean that here we have also our mipmap correctly box filtered for importance sampling.
// Convolve downsampled cubemap
RenderCubemapGGXConvolution(renderContext, m_BuiltinParameters, skyParameters, m_SkyboxCubemapRT, m_SkyboxGGXCubemapRT);
// Convolve downsampled cubemap
RenderCubemapGGXConvolution(renderContext, m_BuiltinParameters, skyParameters, m_SkyboxCubemapRT, m_SkyboxGGXCubemapRT);
m_NeedLowLevelUpdateEnvironment = true;
m_UpdateRequired = false;
m_SkyParametersHash = skyParameters.GetHash();
m_CurrentUpdateTime = 0.0f;
}
m_NeedLowLevelUpdateEnvironment = true;
m_UpdateRequired = false;
m_SkyParametersHash = skyParameters.GetHash();
m_CurrentUpdateTime = 0.0f;
else
{
// Disabled for now.
// We need to remove RenderSkyToCubemap from the RenderCubemapGGXConvolution first as it needs the skyparameter to be valid.
//if(m_SkyParametersHash != 0)
//{
// // Clear sky light probe
// RenderSettings.skybox = null;
// RenderSettings.ambientIntensity = 1.0f; // fix this to 1, this parameter should not exist!
// RenderSettings.ambientMode = UnityEngine.Rendering.AmbientMode.Skybox; // Force skybox for our HDRI
// RenderSettings.reflectionIntensity = 1.0f;
// RenderSettings.customReflection = null;
// DynamicGI.UpdateEnvironment();
}
else
{
// Disabled for now.
// We need to remove RenderSkyToCubemap from the RenderCubemapGGXConvolution first as it needs the skyparameter to be valid.
//if(m_SkyParametersHash != 0)
//{
// // Clear sky light probe
// RenderSettings.skybox = null;
// RenderSettings.ambientIntensity = 1.0f; // fix this to 1, this parameter should not exist!
// RenderSettings.ambientMode = UnityEngine.Rendering.AmbientMode.Skybox; // Force skybox for our HDRI
// RenderSettings.reflectionIntensity = 1.0f;
// RenderSettings.customReflection = null;
// DynamicGI.UpdateEnvironment();
// // Clear temp cubemap and redo GGX from black
// Utilities.SetRenderTarget(renderContext, m_SkyboxCubemapRT, ClearFlag.ClearColor);
// RenderCubemapGGXConvolution(renderContext, m_BuiltinParameters, skyParameters, m_SkyboxCubemapRT, m_SkyboxGGXCubemapRT);
// // Clear temp cubemap and redo GGX from black
// Utilities.SetRenderTarget(renderContext, m_SkyboxCubemapRT, ClearFlag.ClearColor);
// RenderCubemapGGXConvolution(renderContext, m_BuiltinParameters, skyParameters, m_SkyboxCubemapRT, m_SkyboxGGXCubemapRT);
// m_SkyParametersHash = 0;
//}
}
// m_SkyParametersHash = 0;
//}
}
}
}

8
Assets/ScriptableRenderLoop/HDRenderPipeline/Sky/SkyParameters.cs


m_Properties = GetType()
.GetFields(BindingFlags.Public | BindingFlags.Instance)
.ToArray();
SkyParametersSingleton.Refresh();
public void OnDisable()
{
SkyParametersSingleton.Refresh();
}
public int GetHash()
{
unchecked

3
Assets/ScriptableRenderLoop/HDRenderPipeline/Sky/SkyRenderer.cs


using UnityEngine.Rendering;
using UnityEngine.Experimental.Rendering.HDPipeline;
using System.Collections.Generic;
using System;

2
Assets/ScriptableRenderLoop/RenderPasses/ShadowRenderPass.cs


namespace UnityEngine.Experimental.Rendering
{
[System.Serializable]
[Serializable]
public class ShadowSettings
{
public bool enabled;

41
Assets/ScriptableRenderLoop/HDRenderPipeline/SceneSettings/CommonSettingsSingleton.cs


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;
}
}
}

12
Assets/ScriptableRenderLoop/HDRenderPipeline/SceneSettings/CommonSettingsSingleton.cs.meta


fileFormatVersion: 2
guid: dcb3649c420bf2d4093ab76418541c0f
timeCreated: 1485087502
licenseType: Pro
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

30
Assets/ScriptableRenderLoop/HDRenderPipeline/Sky/SkyParametersSingleton.cs


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();
}
}
}

12
Assets/ScriptableRenderLoop/HDRenderPipeline/Sky/SkyParametersSingleton.cs.meta


fileFormatVersion: 2
guid: 6b9acc7ad27501c4bbcd5d6d5a7fb218
timeCreated: 1485096567
licenseType: Pro
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

40
Assets/ScriptableRenderLoop/core/Singleton.cs


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;
}
}
}
}

12
Assets/ScriptableRenderLoop/core/Singleton.cs.meta


fileFormatVersion: 2
guid: a8e809a4a46fd8046a7e3a4f172585f0
timeCreated: 1485087282
licenseType: Pro
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
正在加载...
取消
保存