8
8
using System . Reflection ;
9
9
using UnityEngine ;
10
10
using UnityEngine . Rendering ;
11
+ using Object = UnityEngine . Object ;
11
12
12
13
namespace UnityEditor . Rendering
13
14
{
@@ -31,13 +32,12 @@ public static Type FetchFirstCompatibleTypeUsingScriptableRenderPipelineExtensio
31
32
if ( Attribute . GetCustomAttribute ( extensionType , typeof ( ScriptableRenderPipelineExtensionAttribute ) ) is ScriptableRenderPipelineExtensionAttribute { inUse : true } )
32
33
return extensionType ;
33
34
#pragma warning restore CS0618
34
-
35
35
}
36
36
37
37
return null ;
38
38
}
39
39
40
- private static Dictionary < Type , Type > s_RenderPipelineAssetToRenderPipelineType = new ( ) ;
40
+ private static Dictionary < Type , Type > s_RenderPipelineAssetToRenderPipelineType = new ( ) ;
41
41
42
42
public static Type GetPipelineTypeFromPipelineAssetType ( Type pipelineAssetType )
43
43
{
@@ -63,12 +63,95 @@ public static Type GetPipelineTypeFromPipelineAssetType(Type pipelineAssetType)
63
63
64
64
var pipelineAsset = ScriptableObject . CreateInstance ( pipelineAssetType ) as RenderPipelineAsset ;
65
65
pipelineType = pipelineAsset . pipelineType ;
66
- UnityEngine . Object . DestroyImmediate ( pipelineAsset ) ;
66
+ Object . DestroyImmediate ( pipelineAsset ) ;
67
67
s_RenderPipelineAssetToRenderPipelineType [ pipelineAssetType ] = pipelineType ;
68
68
return pipelineType ;
69
69
}
70
70
71
71
public static bool TrySetRenderingLayerName ( int index , string name )
72
- => TagManager . TrySetRenderingLayerName ( index , name ) ;
72
+ => TagManager . Internal_TrySetRenderingLayerName ( index , name ) ;
73
+
74
+ public static bool TryAddRenderingLayerName ( string name )
75
+ => TagManager . Internal_TryAddRenderingLayerName ( name ) ;
76
+
77
+ internal static int GetActiveMaxRenderingLayers ( )
78
+ {
79
+ if ( EditorGraphicsSettings . TryGetRenderPipelineSettingsFromInterface < RenderingLayersLimitSettings > ( out var settings )
80
+ && settings . Length != 0 )
81
+ return settings [ 0 ] . maxSupportedRenderingLayers ;
82
+ return 32 ;
83
+ }
84
+
85
+ internal static List < ( int , string ) > GetMaxRenderingLayersFromSettings ( )
86
+ {
87
+ var result = new List < ( int , string ) > ( ) ;
88
+ var renderPipelineAssets = GraphicsSettings . allConfiguredRenderPipelines ;
89
+ foreach ( var renderPipelineAsset in renderPipelineAssets )
90
+ {
91
+ var pipelineType = GetPipelineTypeFromPipelineAssetType ( renderPipelineAsset . GetType ( ) ) ;
92
+ if ( pipelineType == null )
93
+ continue ;
94
+
95
+ if ( ! EditorGraphicsSettings . TryGetRenderPipelineSettingsFromInterfaceForPipeline < RenderingLayersLimitSettings > ( pipelineType , out var settings ) )
96
+ continue ;
97
+
98
+ if ( settings . Length == 0 )
99
+ continue ;
100
+
101
+ result . Add ( ( settings [ 0 ] . maxSupportedRenderingLayers , renderPipelineAsset . pipelineType . Name ) ) ;
102
+ }
103
+
104
+ return result ;
105
+ }
106
+
107
+ internal static ( string [ ] , int [ ] ) GetRenderingLayerNamesAndValuesForMask ( uint currentMask )
108
+ {
109
+ var names = RenderingLayerMask . GetDefinedRenderingLayerNames ( ) ;
110
+ var values = RenderingLayerMask . GetDefinedRenderingLayerValues ( ) ;
111
+
112
+ if ( currentMask != uint . MaxValue )
113
+ {
114
+ //calculate remaining mask value
115
+ uint remainingMask = currentMask ;
116
+ for ( int i = 0 ; i < values . Length ; i ++ )
117
+ {
118
+ uint valueUint = unchecked ( ( uint ) values [ i ] ) ;
119
+ if ( ( currentMask & valueUint ) != 0 )
120
+ remainingMask &= ~ valueUint ;
121
+ }
122
+
123
+ //add remaining mask value to the end of the list
124
+ if ( remainingMask != 0 )
125
+ {
126
+ var listOfUnnamedBits = new List < ( int , uint ) > ( ) ;
127
+ for ( int i = 0 ; i < 32 ; i ++ )
128
+ {
129
+ if ( ( remainingMask & ( 1u << i ) ) != 0 )
130
+ listOfUnnamedBits . Add ( ( i , 1u << i ) ) ;
131
+ }
132
+
133
+ var allNames = new List < string > ( names . Length + listOfUnnamedBits . Count ) ;
134
+ var allValues = new List < int > ( names . Length + listOfUnnamedBits . Count ) ;
135
+ allNames . AddRange ( names ) ;
136
+ allValues . AddRange ( values ) ;
137
+
138
+ for ( int i = 0 ; i < listOfUnnamedBits . Count ; i ++ )
139
+ {
140
+ var bit = listOfUnnamedBits [ i ] ;
141
+ var indexOfTheNextValue = allValues . FindIndex ( ( currentValue ) => unchecked ( ( uint ) currentValue ) > bit . Item2 ) ;
142
+ if ( indexOfTheNextValue == - 1 )
143
+ indexOfTheNextValue = allValues . Count ;
144
+
145
+ //find an index of specific bit value
146
+ allNames . Insert ( indexOfTheNextValue , $ "Undefined Layer { bit . Item1 } ") ;
147
+ allValues . Insert ( indexOfTheNextValue , unchecked ( ( int ) bit . Item2 ) ) ;
148
+ }
149
+ names = allNames . ToArray ( ) ;
150
+ values = allValues . ToArray ( ) ;
151
+ }
152
+ }
153
+
154
+ return ( names , values ) ;
155
+ }
73
156
}
74
157
}
0 commit comments