|
| 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 | +} |
0 commit comments