77using UnityEngine . Bindings ;
88using UnityEngine . UIElements ;
99using UnityEngine . Rendering ;
10+ using UnityEngine ;
1011
1112namespace UnityEditor . Build . Profile
1213{
@@ -33,6 +34,8 @@ public override VisualElement CreateInspectorGUI()
3334 BindEnumFieldWithFadeGroup ( root , "Lightmap" , CalculateLightmapStrippingFromCurrentScene ) ;
3435 BindEnumFieldWithFadeGroup ( root , "Fog" , CalculateFogStrippingFromCurrentScene ) ;
3536
37+ BindShaderPreload ( root ) ;
38+
3639 // Align fields as in the inspector
3740 var type = typeof ( BaseField < > ) ;
3841 root . Query < BindableElement > ( )
@@ -59,6 +62,57 @@ void BindEnumFieldWithFadeGroup(VisualElement content, string id, Action buttonC
5962 content . MandatoryQ < Button > ( $ "Import{ id } FromCurrentScene") . clicked += buttonCallback ;
6063 }
6164
65+ void BindShaderPreload ( VisualElement root )
66+ {
67+ var shaderPreloadProperty = serializedObject . FindProperty ( "m_PreloadedShaders" ) ;
68+ shaderPreloadProperty . isExpanded = false ;
69+
70+ var delayedShaderTimeLimitProperty = serializedObject . FindProperty ( "m_PreloadShadersBatchTimeLimit" ) ;
71+ var shaderPreloadToggle = root . MandatoryQ < Toggle > ( "ShaderPreloadToggle" ) ;
72+ var delayedShaderTimeLimitGroup = root . MandatoryQ < VisualElement > ( "DelayedShaderTimeLimitGroup" ) ;
73+ var delayedShaderTimeLimit = root . MandatoryQ < IntegerField > ( "DelayedShaderTimeLimit" ) ;
74+ shaderPreloadToggle . RegisterValueChangedCallback ( evt => {
75+ delayedShaderTimeLimitGroup . style . display = evt . newValue ? DisplayStyle . Flex : DisplayStyle . None ;
76+ var newVal = evt . newValue ? delayedShaderTimeLimit . value : - 1 ;
77+ if ( delayedShaderTimeLimitProperty . intValue != newVal )
78+ {
79+ delayedShaderTimeLimitProperty . intValue = newVal ;
80+ delayedShaderTimeLimitProperty . serializedObject . ApplyModifiedProperties ( ) ;
81+ }
82+ } ) ;
83+ delayedShaderTimeLimit . RegisterValueChangedCallback ( evt =>
84+ {
85+ if ( delayedShaderTimeLimitProperty . intValue != evt . newValue )
86+ {
87+ delayedShaderTimeLimitProperty . intValue = evt . newValue ;
88+ delayedShaderTimeLimitProperty . serializedObject . ApplyModifiedProperties ( ) ;
89+ }
90+ } ) ;
91+ shaderPreloadToggle . SetValueWithoutNotify ( delayedShaderTimeLimitProperty . intValue >= 0 ) ;
92+ delayedShaderTimeLimit . SetValueWithoutNotify ( Mathf . Max ( 0 , delayedShaderTimeLimitProperty . intValue ) ) ;
93+ delayedShaderTimeLimitGroup . style . display = delayedShaderTimeLimitProperty . intValue >= 0 ? DisplayStyle . Flex : DisplayStyle . None ;
94+
95+ var shaderTracking = root . MandatoryQ < HelpBox > ( "ShaderTrackingInfoBox" ) ;
96+ shaderTracking . schedule . Execute ( ( ) =>
97+ shaderTracking . text =
98+ $ "Currently tracked: { ShaderUtil . GetCurrentShaderVariantCollectionShaderCount ( ) } shaders { ShaderUtil . GetCurrentShaderVariantCollectionVariantCount ( ) } total variants") . Every ( 500 ) ;
99+
100+ var saveButton = root . MandatoryQ < Button > ( "SaveShaderVariants" ) ;
101+ saveButton . clickable = new Clickable ( ( ) =>
102+ {
103+ var assetPath = EditorUtility . SaveFilePanelInProject (
104+ L10n . Tr ( "Save Shader Variant Collection" ) ,
105+ "NewShaderVariants" ,
106+ "shadervariants" ,
107+ L10n . Tr ( "Save shader variant collection" ) ,
108+ ProjectWindowUtil . GetActiveFolderPath ( ) ) ;
109+ if ( ! string . IsNullOrEmpty ( assetPath ) )
110+ ShaderUtil . SaveCurrentShaderVariantCollection ( assetPath ) ;
111+ } ) ;
112+ var clearButton = root . MandatoryQ < Button > ( "ClearCurrentShaderVariants" ) ;
113+ clearButton . clickable = new Clickable ( ShaderUtil . ClearCurrentShaderVariantCollection ) ;
114+ }
115+
62116 void CalculateLightmapStrippingFromCurrentScene ( )
63117 {
64118 bool lightmapKeepPlain , lightmapKeepDirCombined , lightmapKeepDynamicPlain , lightmapKeepDynamicDirCombined , lightmapKeepShadowMask , lightmapKeepSubtractive ;
0 commit comments