浏览代码
Added a CommonSettings component to handle the choice of the SkyRenderer and later other global scene settings.
/main
Added a CommonSettings component to handle the choice of the SkyRenderer and later other global scene settings.
/main
Julien Ignace
8 年前
当前提交
799fb598
共有 17 个文件被更改,包括 306 次插入 和 34 次删除
-
9Assets/ScriptableRenderLoop/HDRenderLoop/HDRenderLoop.cs
-
1Assets/ScriptableRenderLoop/HDRenderLoop/Sky/HDRISky/HDRISkyParameters.cs
-
1Assets/ScriptableRenderLoop/HDRenderLoop/Sky/ProceduralSky/ProceduralSkyParameters.cs
-
40Assets/ScriptableRenderLoop/HDRenderLoop/Sky/SkyManager.cs
-
26Assets/ScriptableRenderLoop/HDRenderLoop/Sky/SkyParameters.cs
-
2Assets/ScriptableRenderLoop/HDRenderLoop/Sky/SkyParameters.cs.meta
-
12Assets/ScriptableRenderLoop/HDRenderLoop/Utilities.cs
-
27Assets/ScriptableRenderLoop/HDRenderLoop/Editor/HDRenderLoopMenuItems.cs
-
12Assets/ScriptableRenderLoop/HDRenderLoop/Editor/HDRenderLoopMenuItems.cs.meta
-
9Assets/ScriptableRenderLoop/HDRenderLoop/SceneSettings.meta
-
81Assets/ScriptableRenderLoop/HDRenderLoop/SceneSettings/CommonSettings.cs
-
12Assets/ScriptableRenderLoop/HDRenderLoop/SceneSettings/CommonSettings.cs.meta
-
9Assets/ScriptableRenderLoop/HDRenderLoop/SceneSettings/Editor.meta
-
87Assets/ScriptableRenderLoop/HDRenderLoop/SceneSettings/Editor/CommonSettingsEditor.cs
-
12Assets/ScriptableRenderLoop/HDRenderLoop/SceneSettings/Editor/CommonSettingsEditor.cs.meta
|
|||
using System.Collections; |
|||
using System.Collections.Generic; |
|||
using UnityEngine; |
|||
|
|||
|
|||
namespace UnityEngine.Experimental.ScriptableRenderLoop |
|||
{ |
|||
public class HDRenderLoopMenuItems |
|||
{ |
|||
[UnityEditor.MenuItem("HDRenderLoop/Create Scene Settings")] |
|||
static void CreateSceneSettings() |
|||
{ |
|||
CommonSettings[] settings = Object.FindObjectsOfType(typeof(CommonSettings)) as CommonSettings[]; |
|||
|
|||
if(settings.Length == 0) |
|||
{ |
|||
GameObject go = new GameObject(); |
|||
go.name = "SceneSettings"; |
|||
go.AddComponent(typeof(CommonSettings)); |
|||
} |
|||
else |
|||
{ |
|||
Debug.LogWarning("SceneSettings has already been created."); |
|||
} |
|||
} |
|||
} |
|||
} |
|
|||
fileFormatVersion: 2 |
|||
guid: 19042aef0dcb65e4496d778558fefad9 |
|||
timeCreated: 1481793704 |
|||
licenseType: Pro |
|||
MonoImporter: |
|||
serializedVersion: 2 |
|||
defaultReferences: [] |
|||
executionOrder: 0 |
|||
icon: {instanceID: 0} |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
fileFormatVersion: 2 |
|||
guid: 1b5e87e98ef1994498478f60a6dcdd65 |
|||
folderAsset: yes |
|||
timeCreated: 1481725797 |
|||
licenseType: Pro |
|||
DefaultImporter: |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
using System.Collections; |
|||
using System.Collections.Generic; |
|||
using UnityEngine; |
|||
using System; |
|||
using System.Linq; |
|||
using System.Reflection; |
|||
|
|||
namespace UnityEngine.Experimental.ScriptableRenderLoop |
|||
{ |
|||
[ExecuteInEditMode] |
|||
[DisallowMultipleComponent] |
|||
public class CommonSettings |
|||
: MonoBehaviour |
|||
{ |
|||
[SerializeField] |
|||
private string m_SkyRendererTypeName = ""; |
|||
public Type skyRendererType |
|||
{ |
|||
set { m_SkyRendererTypeName = value != null ? value.FullName : ""; OnSkyRendererChanged(); } |
|||
get { return m_SkyRendererTypeName == "" ? null : Assembly.GetAssembly(typeof(CommonSettings)).GetType(m_SkyRendererTypeName); } |
|||
} |
|||
|
|||
|
|||
void OnEnable() |
|||
{ |
|||
HDRenderLoop renderLoop = Utilities.GetHDRenderLoop(); |
|||
if (renderLoop == null) |
|||
{ |
|||
return; |
|||
} |
|||
|
|||
OnSkyRendererChanged(); |
|||
} |
|||
|
|||
void OnDisable() |
|||
{ |
|||
} |
|||
|
|||
void OnSkyRendererChanged() |
|||
{ |
|||
HDRenderLoop renderLoop = Utilities.GetHDRenderLoop(); |
|||
if (renderLoop == null) |
|||
{ |
|||
return; |
|||
} |
|||
|
|||
renderLoop.InstantiateSkyRenderer(skyRendererType); |
|||
|
|||
List<SkyParameters> result = new List<SkyParameters>(); |
|||
gameObject.GetComponents<SkyParameters>(result); |
|||
|
|||
Type skyParamType = renderLoop.skyManager.GetSkyParameterType(); |
|||
|
|||
// Disable all incompatible sky parameters and enable the compatible one
|
|||
bool found = false; |
|||
foreach (SkyParameters param in result) |
|||
{ |
|||
if (param.GetType() == skyParamType) |
|||
{ |
|||
// This is a workaround the fact that we can't control the order in which components are initialized.
|
|||
// So it can happen that a given SkyParameter is OnEnabled before the CommonSettings and so fail the setup because the SkyRenderer is not yet initialized.
|
|||
// So we disable it to for OnEnable to be called again.
|
|||
param.enabled = false; |
|||
|
|||
param.enabled = true; |
|||
found = true; |
|||
} |
|||
else |
|||
{ |
|||
param.enabled = false; |
|||
} |
|||
} |
|||
|
|||
// If it does not exist, create the parameters
|
|||
if (!found && skyParamType != null) |
|||
{ |
|||
gameObject.AddComponent(skyParamType); |
|||
} |
|||
} |
|||
} |
|||
} |
|
|||
fileFormatVersion: 2 |
|||
guid: bc357c46587fc9d4cb8f311794d7d2f3 |
|||
timeCreated: 1481734434 |
|||
licenseType: Pro |
|||
MonoImporter: |
|||
serializedVersion: 2 |
|||
defaultReferences: [] |
|||
executionOrder: 0 |
|||
icon: {instanceID: 0} |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
fileFormatVersion: 2 |
|||
guid: a1fd2e77167b0904e9c33020c13d1011 |
|||
folderAsset: yes |
|||
timeCreated: 1481726125 |
|||
licenseType: Pro |
|||
DefaultImporter: |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
using System.Collections; |
|||
using System.Collections.Generic; |
|||
using UnityEngine; |
|||
using UnityEditor; |
|||
using System; |
|||
using System.Linq; |
|||
using System.Reflection; |
|||
|
|||
namespace UnityEngine.Experimental.ScriptableRenderLoop |
|||
{ |
|||
[CustomEditor(typeof(CommonSettings))] |
|||
public class CommonSettingsEditor |
|||
: Editor |
|||
{ |
|||
private class Styles |
|||
{ |
|||
public readonly GUIContent none = new GUIContent("None"); |
|||
public readonly GUIContent skyRenderer = new GUIContent("Sky Renderer"); |
|||
} |
|||
|
|||
private static Styles s_Styles = null; |
|||
private static Styles styles |
|||
{ |
|||
get |
|||
{ |
|||
if (s_Styles == null) |
|||
s_Styles = new Styles(); |
|||
return s_Styles; |
|||
} |
|||
} |
|||
|
|||
private List<Type> m_SkyRendererTypes; |
|||
private List<GUIContent> m_SkyRendererTypeNames = new List<GUIContent>(); |
|||
private List<int> m_SkyRendererTypeValues = new List<int>(); |
|||
|
|||
void OnEnable() |
|||
{ |
|||
m_SkyRendererTypes = Assembly.GetAssembly(typeof(SkyRenderer)) |
|||
.GetTypes() |
|||
.Where(t => t.IsSubclassOf(typeof(SkyRenderer)) && !t.IsGenericType) |
|||
.ToList(); |
|||
|
|||
// Prepare the list of available SkyRenderers for the IntPopup
|
|||
m_SkyRendererTypeNames.Clear(); |
|||
m_SkyRendererTypeValues.Clear(); |
|||
for(int i = 0 ; i < m_SkyRendererTypes.Count ; ++i) |
|||
{ |
|||
string longName = m_SkyRendererTypes[i].ToString(); |
|||
char[] separators = {'.'}; |
|||
string[] tokens = longName.Split(separators); |
|||
m_SkyRendererTypeNames.Add(new GUIContent(tokens[tokens.Length - 1])); |
|||
m_SkyRendererTypeValues.Add(i); |
|||
} |
|||
|
|||
// Add default null value.
|
|||
m_SkyRendererTypeNames.Add(styles.none); |
|||
m_SkyRendererTypeValues.Add(m_SkyRendererTypeValues.Count); |
|||
m_SkyRendererTypes.Add(null); |
|||
} |
|||
|
|||
public override void OnInspectorGUI() |
|||
{ |
|||
serializedObject.Update(); |
|||
|
|||
CommonSettings settings = target as CommonSettings; |
|||
// Retrieve the index of the current SkyRenderer
|
|||
int index = -1; |
|||
for(int i = 0 ; i < m_SkyRendererTypeValues.Count ; ++i ) |
|||
{ |
|||
if(m_SkyRendererTypes[i] == settings.skyRendererType) |
|||
{ |
|||
index = i; |
|||
break; |
|||
} |
|||
} |
|||
|
|||
EditorGUI.BeginChangeCheck(); |
|||
int newValue = EditorGUILayout.IntPopup(styles.skyRenderer, index, m_SkyRendererTypeNames.ToArray(), m_SkyRendererTypeValues.ToArray()); |
|||
if(EditorGUI.EndChangeCheck()) |
|||
{ |
|||
settings.skyRendererType = m_SkyRendererTypes[newValue]; |
|||
} |
|||
|
|||
serializedObject.ApplyModifiedProperties(); |
|||
} |
|||
} |
|||
} |
|
|||
fileFormatVersion: 2 |
|||
guid: b020b2b47372e064bb3e3282b87df5d2 |
|||
timeCreated: 1481726141 |
|||
licenseType: Pro |
|||
MonoImporter: |
|||
serializedVersion: 2 |
|||
defaultReferences: [] |
|||
executionOrder: 0 |
|||
icon: {instanceID: 0} |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
撰写
预览
正在加载...
取消
保存
Reference in new issue