99namespace UnityEngine . Experimental . ScriptableRenderLoop
1010{
1111 [ CustomEditor ( typeof ( CommonSettings ) ) ]
12+ [ CanEditMultipleObjects ]
1213 public class CommonSettingsEditor
1314 : Editor
1415 {
1516 private class Styles
1617 {
1718 public readonly GUIContent none = new GUIContent ( "None" ) ;
19+ public readonly GUIContent sky = new GUIContent ( "Sky" ) ;
1820 public readonly GUIContent skyRenderer = new GUIContent ( "Sky Renderer" ) ;
21+
22+ public readonly GUIContent shadows = new GUIContent ( "Shadows" ) ;
23+ public readonly GUIContent maxShadowDistance = new GUIContent ( "Maximum shadow distance" ) ;
24+ public readonly GUIContent shadowsDirectionalLightCascadeCount = new GUIContent ( "Directional cascade count" ) ;
25+ public readonly GUIContent [ ] shadowsCascadeCounts = new GUIContent [ ] { new GUIContent ( "1" ) , new GUIContent ( "2" ) , new GUIContent ( "3" ) , new GUIContent ( "4" ) } ;
26+ public readonly int [ ] shadowsCascadeCountValues = new int [ ] { 1 , 2 , 3 , 4 } ;
27+ public readonly GUIContent shadowsCascades = new GUIContent ( "Cascade values" ) ;
28+ public readonly GUIContent [ ] shadowSplits = new GUIContent [ ] { new GUIContent ( "Split 0" ) , new GUIContent ( "Split 1" ) , new GUIContent ( "Split 2" ) } ;
29+
1930 }
2031
2132 private static Styles s_Styles = null ;
@@ -29,23 +40,42 @@ private static Styles styles
2940 }
3041 }
3142
32- private List < Type > m_SkyRendererTypes ;
43+ // Sky renderer
44+ List < Type > m_SkyRendererTypes = new List < Type > ( ) ;
3345 private List < GUIContent > m_SkyRendererTypeNames = new List < GUIContent > ( ) ;
46+ private List < string > m_SkyRendererFullTypeNames = new List < string > ( ) ;
3447 private List < int > m_SkyRendererTypeValues = new List < int > ( ) ;
3548
49+ private bool multipleEditing { get { return targets . Length > 1 ; } }
50+
51+ private SerializedProperty m_SkyRenderer ;
52+
53+ private SerializedProperty m_ShadowMaxDistance ;
54+ private SerializedProperty m_ShadowCascadeCount ;
55+ private SerializedProperty [ ] m_ShadowCascadeSplits = new SerializedProperty [ 3 ] ;
56+
3657 void OnEnable ( )
3758 {
59+ m_SkyRenderer = serializedObject . FindProperty ( "m_SkyRendererTypeName" ) ;
60+
61+ m_ShadowMaxDistance = serializedObject . FindProperty ( "m_ShadowMaxDistance" ) ;
62+ m_ShadowCascadeCount = serializedObject . FindProperty ( "m_ShadowCascadeCount" ) ;
63+ for ( int i = 0 ; i < 3 ; ++ i )
64+ m_ShadowCascadeSplits [ i ] = serializedObject . FindProperty ( string . Format ( "m_ShadowCascadeSplit{0}" , i ) ) ;
65+
3866 m_SkyRendererTypes = Assembly . GetAssembly ( typeof ( SkyRenderer ) )
39- . GetTypes ( )
40- . Where ( t => t . IsSubclassOf ( typeof ( SkyRenderer ) ) && ! t . IsGenericType )
41- . ToList ( ) ;
67+ . GetTypes ( )
68+ . Where ( t => t . IsSubclassOf ( typeof ( SkyRenderer ) ) && ! t . IsGenericType )
69+ . ToList ( ) ;
4270
4371 // Prepare the list of available SkyRenderers for the IntPopup
4472 m_SkyRendererTypeNames . Clear ( ) ;
73+ m_SkyRendererFullTypeNames . Clear ( ) ;
4574 m_SkyRendererTypeValues . Clear ( ) ;
46- for ( int i = 0 ; i < m_SkyRendererTypes . Count ; ++ i )
75+ for ( int i = 0 ; i < m_SkyRendererTypes . Count ; ++ i )
4776 {
4877 string longName = m_SkyRendererTypes [ i ] . ToString ( ) ;
78+ m_SkyRendererFullTypeNames . Add ( longName ) ;
4979 char [ ] separators = { '.' } ;
5080 string [ ] tokens = longName . Split ( separators ) ;
5181 m_SkyRendererTypeNames . Add ( new GUIContent ( tokens [ tokens . Length - 1 ] ) ) ;
@@ -54,32 +84,76 @@ void OnEnable()
5484
5585 // Add default null value.
5686 m_SkyRendererTypeNames . Add ( styles . none ) ;
87+ m_SkyRendererFullTypeNames . Add ( "" ) ;
5788 m_SkyRendererTypeValues . Add ( m_SkyRendererTypeValues . Count ) ;
5889 m_SkyRendererTypes . Add ( null ) ;
5990 }
6091
61- public override void OnInspectorGUI ( )
92+ void OnSkyInspectorGUI ( )
6293 {
63- serializedObject . Update ( ) ;
94+ EditorGUILayout . LabelField ( styles . sky ) ;
95+ EditorGUI . indentLevel ++ ;
6496
65- CommonSettings settings = target as CommonSettings ;
66- // Retrieve the index of the current SkyRenderer
97+ // Retrieve the index of the current SkyRenderer. Won't be used in case of multiple editing with different values
6798 int index = - 1 ;
68- for ( int i = 0 ; i < m_SkyRendererTypeValues . Count ; ++ i )
99+ for ( int i = 0 ; i < m_SkyRendererTypeNames . Count ; ++ i )
69100 {
70- if ( m_SkyRendererTypes [ i ] == settings . skyRendererType )
101+ if ( m_SkyRendererFullTypeNames [ i ] == m_SkyRenderer . stringValue )
71102 {
72103 index = i ;
73104 break ;
74105 }
75106 }
76107
108+ EditorGUI . showMixedValue = m_SkyRenderer . hasMultipleDifferentValues ;
77109 EditorGUI . BeginChangeCheck ( ) ;
78110 int newValue = EditorGUILayout . IntPopup ( styles . skyRenderer , index , m_SkyRendererTypeNames . ToArray ( ) , m_SkyRendererTypeValues . ToArray ( ) ) ;
111+ if ( EditorGUI . EndChangeCheck ( ) )
112+ {
113+ m_SkyRenderer . stringValue = m_SkyRendererFullTypeNames [ newValue ] ;
114+ }
115+ EditorGUI . showMixedValue = false ;
116+
117+ EditorGUI . indentLevel -- ;
118+ }
119+
120+ void OnShadowInspectorGUI ( )
121+ {
122+ EditorGUILayout . LabelField ( styles . shadows ) ;
123+ EditorGUI . indentLevel ++ ;
124+ EditorGUILayout . PropertyField ( m_ShadowMaxDistance , styles . maxShadowDistance ) ;
125+
126+ EditorGUI . BeginChangeCheck ( ) ;
127+ EditorGUI . showMixedValue = m_ShadowCascadeCount . hasMultipleDifferentValues ;
128+ int newCascadeCount = EditorGUILayout . IntPopup ( styles . shadowsDirectionalLightCascadeCount , m_ShadowCascadeCount . intValue , styles . shadowsCascadeCounts , styles . shadowsCascadeCountValues ) ;
79129 if ( EditorGUI . EndChangeCheck ( ) )
80130 {
81- settings . skyRendererType = m_SkyRendererTypes [ newValue ] ;
131+ m_ShadowCascadeCount . intValue = newCascadeCount ;
132+ }
133+
134+ // Compute max cascade count.
135+ int maxCascadeCount = 0 ;
136+ for ( int i = 0 ; i < targets . Length ; ++ i )
137+ {
138+ CommonSettings settings = targets [ i ] as CommonSettings ;
139+ maxCascadeCount = Math . Max ( maxCascadeCount , settings . shadowCascadeCount ) ;
140+ }
141+
142+ EditorGUI . indentLevel ++ ;
143+ for ( int i = 0 ; i < maxCascadeCount - 1 ; i ++ )
144+ {
145+ EditorGUILayout . PropertyField ( m_ShadowCascadeSplits [ i ] , styles . shadowSplits [ i ] ) ;
82146 }
147+ EditorGUI . indentLevel -- ;
148+ EditorGUI . indentLevel -- ;
149+ }
150+
151+ public override void OnInspectorGUI ( )
152+ {
153+ serializedObject . Update ( ) ;
154+
155+ OnSkyInspectorGUI ( ) ;
156+ OnShadowInspectorGUI ( ) ;
83157
84158 serializedObject . ApplyModifiedProperties ( ) ;
85159 }
0 commit comments