浏览代码

Improved GlobalVolumeFeature and added custom GUI

/main
Andrem 3 年前
当前提交
c81d59ae
共有 3 个文件被更改,包括 82 次插入4 次删除
  1. 8
      Assets/Scripts/Effects/GlobalVolumeFeature.cs
  2. 67
      Assets/Scripts/Editor/GlobalVolumeFeatureEditor.cs
  3. 11
      Assets/Scripts/Editor/GlobalVolumeFeatureEditor.cs.meta

8
Assets/Scripts/Effects/GlobalVolumeFeature.cs


using UnityEngine.Rendering;
using UnityEngine.Rendering.Universal;
//[DisallowMultipleRendererFeature] // once not internal, this needs to be here
public class GlobalVolumeFeature : ScriptableRendererFeature
{
class GlobalVolumePass : ScriptableRenderPass

{
var index = QualitySettings.GetQualityLevel();
if(_qualityProfiles.Count >= index)
qualityVol.sharedProfile = _qualityProfiles?[QualitySettings.GetQualityLevel()];
if(_qualityProfiles.Count >= index && _qualityProfiles[index] != null)
qualityVol.sharedProfile = _qualityProfiles?[index];
}
// Here you can implement the rendering logic.

m_ScriptablePass = new GlobalVolumePass
{
// Configures where the render pass should be injected.
renderPassEvent = RenderPassEvent.BeforeRendering,
renderPassEvent = RenderPassEvent.AfterRenderingTransparents,
_baseProfile = this._baseProfile,
_layerMask = this._layerMask,
_qualityProfiles = this._qualityProfiles,

67
Assets/Scripts/Editor/GlobalVolumeFeatureEditor.cs


using System;
using System.Collections;
using System.Collections.Generic;
using UnityEditor;
using UnityEngine;
using UnityEngine.Rendering;
[CustomEditor(typeof(GlobalVolumeFeature))]
public class GlobalVolumeFeatureEditor : Editor
{
private GlobalVolumeFeature feature;
private SerializedProperty profileList;
private SerializedProperty baseProfile;
private static class Styles
{
public static GUIStyle frameBox = new GUIStyle(EditorStyles.helpBox);
public static GUIStyle header = new GUIStyle(EditorStyles.boldLabel);
public static GUIContent baseGUI = new GUIContent("Global Base Profile",
"This Profile is always active and should be treated as a default global settings for Volumes.");
}
private void OnEnable()
{
profileList = serializedObject.FindProperty(nameof(feature._qualityProfiles));
baseProfile = serializedObject.FindProperty(nameof(feature._baseProfile));
}
public override void OnInspectorGUI()
{
feature = (GlobalVolumeFeature)target;
EditorGUILayout.PropertyField(baseProfile, Styles.baseGUI);
EditorGUILayout.LabelField("Quality Level Profiles", Styles.header);
var qualityLevelNames = QualitySettings.names;
EditorGUILayout.BeginVertical(Styles.frameBox);
// Draw Quality level entries
for (var i = 0; i < qualityLevelNames.Length; i++)
{
if (i >= feature._qualityProfiles.Count)
{
feature._qualityProfiles.Add(null);
EditorUtility.SetDirty(feature);
serializedObject.Update();
}
EditorGUI.BeginChangeCheck();
var obj = feature._qualityProfiles[i];
feature._qualityProfiles[i] = (VolumeProfile)EditorGUILayout.ObjectField(qualityLevelNames[i], obj, typeof(VolumeProfile), false);
if (EditorGUI.EndChangeCheck())
{
EditorUtility.SetDirty(feature);
serializedObject.Update();
}
}
EditorGUILayout.EndVertical();
if (qualityLevelNames.Length < feature._qualityProfiles.Count)
{
feature._qualityProfiles.RemoveRange(qualityLevelNames.Length, feature._qualityProfiles.Count - qualityLevelNames.Length);
EditorUtility.SetDirty(feature);
}
}
}

11
Assets/Scripts/Editor/GlobalVolumeFeatureEditor.cs.meta


fileFormatVersion: 2
guid: 234cf3565ca2a49dc860867404243203
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
正在加载...
取消
保存