@@ -216,24 +216,48 @@ event Action IViewDisplayer.OnUpdateRequested
216216 StyleSheet styleSheet = null ;
217217 StyleSheet styleSheetLight = null ;
218218
219- void OnEnable ( )
219+ void ReloadStyleSheets ( )
220220 {
221- //Stylesheet
222- // Try to load stylesheet. Timing can be odd while upgrading packages (case 1219692).
223- // In this case, it will be fixed in OnGUI. Though it can spawn error while reimporting assets.
224- // Waiting for filter on stylesheet (case 1228706) to remove last error.
225- if ( styleSheet == null || styleSheet . Equals ( null ) )
221+ if ( styleSheet == null || styleSheet . Equals ( null ) )
226222 {
227223 styleSheet = AssetDatabase . LoadAssetAtPath < StyleSheet > ( Style . k_uss ) ;
228- if ( styleSheet != null && ! styleSheet . Equals ( null ) )
229- rootVisualElement . styleSheets . Add ( styleSheet ) ;
224+ if ( styleSheet == null || styleSheet . Equals ( null ) )
225+ {
226+ //Debug.LogWarning("[LookDev] Could not load Stylesheet.");
227+ return ;
228+ }
230229 }
231- if ( ! EditorGUIUtility . isProSkin && styleSheetLight != null && ! styleSheetLight . Equals ( null ) )
230+
231+ if ( ! rootVisualElement . styleSheets . Contains ( styleSheet ) )
232+ rootVisualElement . styleSheets . Add ( styleSheet ) ;
233+
234+ //Additively load Light Skin
235+ if ( ! EditorGUIUtility . isProSkin )
232236 {
233- styleSheetLight = AssetDatabase . LoadAssetAtPath < StyleSheet > ( Style . k_uss_personal_overload ) ;
234- if ( styleSheetLight != null && ! styleSheetLight . Equals ( null ) )
237+ if ( styleSheetLight == null || styleSheetLight . Equals ( null ) )
238+ {
239+ styleSheetLight = AssetDatabase . LoadAssetAtPath < StyleSheet > ( Style . k_uss_personal_overload ) ;
240+ if ( styleSheetLight == null || styleSheetLight . Equals ( null ) )
241+ {
242+ //Debug.LogWarning("[LookDev] Could not load Light skin.");
243+ return ;
244+ }
245+ }
246+
247+ if ( ! rootVisualElement . styleSheets . Contains ( styleSheetLight ) )
235248 rootVisualElement . styleSheets . Add ( styleSheetLight ) ;
236249 }
250+ }
251+
252+ void OnEnable ( )
253+ {
254+ //Stylesheet
255+ // Try to load stylesheet. Timing can be odd while upgrading packages (case 1219692).
256+ // In this case, it will be fixed in OnGUI. Though it can spawn error while reimporting assets.
257+ // Waiting for filter on stylesheet (case 1228706) to remove last error.
258+ // On Editor Skin change, OnEnable is called and stylesheets need to be reloaded (case 1278802).
259+ if ( EditorApplication . isUpdating )
260+ ReloadStyleSheets ( ) ;
237261
238262 //Call the open function to configure LookDev
239263 // in case the window where open when last editor session finished.
@@ -694,14 +718,11 @@ void OnGUI()
694718 // rootVisualElement.styleSheets.Add(styleSheetLight);
695719 //}
696720 }
697- else
698- {
699- //deal with missing style when domain reload...
700- if ( ! rootVisualElement . styleSheets . Contains ( styleSheet ) )
701- rootVisualElement . styleSheets . Add ( styleSheet ) ;
702- if ( ! EditorGUIUtility . isProSkin && ! rootVisualElement . styleSheets . Contains ( styleSheetLight ) )
703- rootVisualElement . styleSheets . Add ( styleSheetLight ) ;
704- }
721+ if ( EditorApplication . isUpdating )
722+ return ;
723+
724+ //deal with missing style on domain reload...
725+ ReloadStyleSheets ( ) ;
705726
706727 OnUpdateRequestedInternal ? . Invoke ( ) ;
707728 }
0 commit comments