Skip to content

Commit 81adcd6

Browse files
committed
Improved GlobalVolumeFeature and added custom GUI
1 parent 554f05f commit 81adcd6

File tree

3 files changed

+82
-4
lines changed

3 files changed

+82
-4
lines changed
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
using System;
2+
using System.Collections;
3+
using System.Collections.Generic;
4+
using UnityEditor;
5+
using UnityEngine;
6+
using UnityEngine.Rendering;
7+
8+
[CustomEditor(typeof(GlobalVolumeFeature))]
9+
public class GlobalVolumeFeatureEditor : Editor
10+
{
11+
private GlobalVolumeFeature feature;
12+
private SerializedProperty profileList;
13+
private SerializedProperty baseProfile;
14+
15+
private static class Styles
16+
{
17+
public static GUIStyle frameBox = new GUIStyle(EditorStyles.helpBox);
18+
public static GUIStyle header = new GUIStyle(EditorStyles.boldLabel);
19+
20+
public static GUIContent baseGUI = new GUIContent("Global Base Profile",
21+
"This Profile is always active and should be treated as a default global settings for Volumes.");
22+
}
23+
24+
private void OnEnable()
25+
{
26+
profileList = serializedObject.FindProperty(nameof(feature._qualityProfiles));
27+
baseProfile = serializedObject.FindProperty(nameof(feature._baseProfile));
28+
}
29+
30+
public override void OnInspectorGUI()
31+
{
32+
feature = (GlobalVolumeFeature)target;
33+
34+
EditorGUILayout.PropertyField(baseProfile, Styles.baseGUI);
35+
36+
EditorGUILayout.LabelField("Quality Level Profiles", Styles.header);
37+
38+
var qualityLevelNames = QualitySettings.names;
39+
40+
EditorGUILayout.BeginVertical(Styles.frameBox);
41+
// Draw Quality level entries
42+
for (var i = 0; i < qualityLevelNames.Length; i++)
43+
{
44+
if (i >= feature._qualityProfiles.Count)
45+
{
46+
feature._qualityProfiles.Add(null);
47+
EditorUtility.SetDirty(feature);
48+
serializedObject.Update();
49+
}
50+
EditorGUI.BeginChangeCheck();
51+
var obj = feature._qualityProfiles[i];
52+
feature._qualityProfiles[i] = (VolumeProfile)EditorGUILayout.ObjectField(qualityLevelNames[i], obj, typeof(VolumeProfile), false);
53+
if (EditorGUI.EndChangeCheck())
54+
{
55+
EditorUtility.SetDirty(feature);
56+
serializedObject.Update();
57+
}
58+
}
59+
EditorGUILayout.EndVertical();
60+
61+
if (qualityLevelNames.Length < feature._qualityProfiles.Count)
62+
{
63+
feature._qualityProfiles.RemoveRange(qualityLevelNames.Length, feature._qualityProfiles.Count - qualityLevelNames.Length);
64+
EditorUtility.SetDirty(feature);
65+
}
66+
}
67+
}

Assets/Scripts/Editor/GlobalVolumeFeatureEditor.cs.meta

Lines changed: 11 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Assets/Scripts/Effects/GlobalVolumeFeature.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
using UnityEngine.Rendering;
44
using UnityEngine.Rendering.Universal;
55

6+
//[DisallowMultipleRendererFeature] // once not internal, this needs to be here
67
public class GlobalVolumeFeature : ScriptableRendererFeature
78
{
89
class GlobalVolumePass : ScriptableRenderPass
@@ -41,10 +42,9 @@ public override void OnCameraSetup(CommandBuffer cmd, ref RenderingData renderin
4142
{
4243
var index = QualitySettings.GetQualityLevel();
4344

44-
if(_qualityProfiles.Count >= index)
45-
qualityVol.sharedProfile = _qualityProfiles?[QualitySettings.GetQualityLevel()];
45+
if(_qualityProfiles.Count >= index && _qualityProfiles[index] != null)
46+
qualityVol.sharedProfile = _qualityProfiles?[index];
4647
}
47-
4848
}
4949

5050
// Here you can implement the rendering logic.
@@ -73,7 +73,7 @@ public override void Create()
7373
m_ScriptablePass = new GlobalVolumePass
7474
{
7575
// Configures where the render pass should be injected.
76-
renderPassEvent = RenderPassEvent.BeforeRendering,
76+
renderPassEvent = RenderPassEvent.AfterRenderingTransparents,
7777
_baseProfile = this._baseProfile,
7878
_layerMask = this._layerMask,
7979
_qualityProfiles = this._qualityProfiles,

0 commit comments

Comments
 (0)