88using System . Reflection ;
99using UnityEngine ;
1010using UnityEngine . Rendering ;
11+ using Object = UnityEngine . Object ;
1112
1213namespace UnityEditor . Rendering
1314{
@@ -31,13 +32,12 @@ public static Type FetchFirstCompatibleTypeUsingScriptableRenderPipelineExtensio
3132 if ( Attribute . GetCustomAttribute ( extensionType , typeof ( ScriptableRenderPipelineExtensionAttribute ) ) is ScriptableRenderPipelineExtensionAttribute { inUse : true } )
3233 return extensionType ;
3334#pragma warning restore CS0618
34-
3535 }
3636
3737 return null ;
3838 }
3939
40- private static Dictionary < Type , Type > s_RenderPipelineAssetToRenderPipelineType = new ( ) ;
40+ private static Dictionary < Type , Type > s_RenderPipelineAssetToRenderPipelineType = new ( ) ;
4141
4242 public static Type GetPipelineTypeFromPipelineAssetType ( Type pipelineAssetType )
4343 {
@@ -63,12 +63,95 @@ public static Type GetPipelineTypeFromPipelineAssetType(Type pipelineAssetType)
6363
6464 var pipelineAsset = ScriptableObject . CreateInstance ( pipelineAssetType ) as RenderPipelineAsset ;
6565 pipelineType = pipelineAsset . pipelineType ;
66- UnityEngine . Object . DestroyImmediate ( pipelineAsset ) ;
66+ Object . DestroyImmediate ( pipelineAsset ) ;
6767 s_RenderPipelineAssetToRenderPipelineType [ pipelineAssetType ] = pipelineType ;
6868 return pipelineType ;
6969 }
7070
7171 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+ }
73156 }
74157}
0 commit comments