@@ -172,51 +172,16 @@ internal static BuildProfile GetActiveOrClassicBuildProfile(
172172 return IsSharedProfile ( target ) ? instance . sharedProfile : instance . GetForClassicPlatform ( target , subTarget ) ;
173173 }
174174
175- [ RequiredByNativeCode ]
176- internal static BuildProfile GetClassicProfileAndResetActive (
177- BuildTarget target , StandaloneBuildSubtarget subTarget = StandaloneBuildSubtarget . Default , string sharedSetting = null )
178- {
179- if ( ShouldReturnActiveProfile ( target , subTarget , sharedSetting ) )
180- {
181- // When invoking a legacy setter, we unset the active profile to prevent
182- // inconsistencies with legacy APIs. That is, all legacy APIs need to write to
183- // the classic platform build profile directly. When doing this, the next getter
184- // MUST return the classic platform build profile containing the newly set value.
185- // The active build profile should be updated directly.
186- ResetActiveProfile ( ) ;
187- }
188-
189- return IsSharedProfile ( target ) ? instance . sharedProfile : instance . GetForClassicPlatform ( target , subTarget ) ;
190- }
191-
192- [ RequiredByNativeCode , UsedImplicitly ]
193- internal static void ResetActiveProfile ( )
194- {
195- if ( instance . activeProfile is null )
196- return ;
197-
198- Debug . LogWarning ( $ "[BuildProfile] Active build profile ({ AssetDatabase . GetAssetPath ( instance . activeProfile ) } ) is set when calling a global platform API.") ;
199- instance . activeProfile = null ;
200- }
201-
202175 internal static bool TryGetActiveOrClassicPlatformSettingsBase < T > (
203176 BuildTarget target , StandaloneBuildSubtarget subTarget , out T result ) where T : BuildProfilePlatformSettingsBase
204177 {
205- BuildProfile buildProfile = GetActiveOrClassicBuildProfile ( target , subTarget ) ;
206- if ( buildProfile != null && buildProfile . platformBuildProfile is T platformProfile )
178+ if ( ! EditorUserBuildSettings . IsBuildProfileScriptingAvailable ( ) )
207179 {
208- result = platformProfile ;
209- return true ;
180+ result = null ;
181+ return false ;
210182 }
211183
212- result = null ;
213- return false ;
214- }
215-
216- internal static bool TryGetClassicPlatformSettingsBaseAndResetActive < T > (
217- BuildTarget target , StandaloneBuildSubtarget subTarget , out T result ) where T : BuildProfilePlatformSettingsBase
218- {
219- BuildProfile buildProfile = GetClassicProfileAndResetActive ( target , subTarget ) ;
184+ BuildProfile buildProfile = GetActiveOrClassicBuildProfile ( target , subTarget ) ;
220185 if ( buildProfile != null && buildProfile . platformBuildProfile is T platformProfile )
221186 {
222187 result = platformProfile ;
@@ -301,17 +266,11 @@ void OnEnable()
301266 if ( ! Directory . Exists ( k_BuildProfilePath ) )
302267 return ;
303268
304- // No need to load classic profiles if build profile is disabled.
305- if ( ! EditorUserBuildSettings . IsBuildProfileWorkflowEnabled ( ) )
306- {
307- return ;
308- }
309-
310- foreach ( var platform in BuildPlatforms . instance . GetValidPlatforms ( ) )
269+ var viewablePlatformKeys = BuildProfileModuleUtil . FindAllViewablePlatforms ( ) ;
270+ for ( var index = 0 ; index < viewablePlatformKeys . Count ; index ++ )
311271 {
312- string path = ( platform is BuildPlatformWithSubtarget platformWithSubtarget ) ?
313- GetFilePathForBuildProfile ( GetKey ( platform . defaultTarget , ( StandaloneBuildSubtarget ) platformWithSubtarget . subtarget ) ) :
314- GetFilePathForBuildProfile ( GetKey ( platform . defaultTarget , StandaloneBuildSubtarget . Default ) ) ;
272+ var key = viewablePlatformKeys [ index ] ;
273+ string path = GetFilePathForBuildProfile ( key ) ;
315274
316275 if ( ! File . Exists ( path ) )
317276 continue ;
@@ -346,31 +305,26 @@ void OnEnable()
346305 /// </summary>
347306 void CheckInstalledBuildPlatforms ( )
348307 {
349- foreach ( var platform in BuildPlatforms . instance . GetValidPlatforms ( ) )
308+ var viewablePlatformKeys = BuildProfileModuleUtil . FindAllViewablePlatforms ( ) ;
309+ for ( var index = 0 ; index < viewablePlatformKeys . Count ; index ++ )
350310 {
351- string targetString = ModuleManager . GetTargetStringFromBuildTarget ( platform . defaultTarget ) ;
352- if ( ! ModuleManager . IsPlatformSupportLoaded ( targetString ) )
353- {
311+ var key = viewablePlatformKeys [ index ] ;
312+ var moduleName = key . Item1 ;
313+ var subtarget = key . Item2 ;
314+
315+ if ( ! BuildProfileModuleUtil . IsModuleInstalled ( moduleName , subtarget ) )
354316 continue ;
355- }
356317
357- if ( ModuleManager . GetBuildProfileExtension ( targetString ) == null )
318+ if ( ModuleManager . GetBuildProfileExtension ( moduleName ) == null )
358319 {
359320 // Require platform support and implemented build profile
360321 // extension for the target platform.
361- Debug . LogWarning ( "Platform does not support build profiles targetString=" + targetString ) ;
322+ Debug . LogWarning ( "Platform does not support build profiles targetString=" + moduleName ) ;
362323 continue ;
363324 }
364325
365- if ( platform is BuildPlatformWithSubtarget platformWithSubtarget )
366- {
367- GetOrCreateClassicPlatformBuildProfile ( platform . defaultTarget ,
368- ( StandaloneBuildSubtarget ) platformWithSubtarget . subtarget ) ;
369- }
370- else
371- {
372- GetOrCreateClassicPlatformBuildProfile ( platform . defaultTarget , StandaloneBuildSubtarget . Default ) ;
373- }
326+ var buildTarget = BuildProfileModuleUtil . GetBuildTarget ( moduleName ) ;
327+ GetOrCreateClassicPlatformBuildProfile ( buildTarget , subtarget ) ;
374328 }
375329
376330 GetOrCreateSharedBuildProfile ( ) ;
@@ -462,7 +416,7 @@ static void SaveBuildProfileInProject(BuildProfile profile)
462416 static void CreateOrLoad ( )
463417 {
464418 var buildProfileContext = InternalEditorUtility . LoadSerializedFileAndForget ( k_BuildProfileProviderAssetPath ) ;
465- if ( buildProfileContext != null && buildProfileContext . Length > 0 )
419+ if ( buildProfileContext != null && buildProfileContext . Length > 0 && buildProfileContext [ 0 ] != null )
466420 {
467421 s_Instance = buildProfileContext [ 0 ] as BuildProfileContext ;
468422 if ( s_Instance == null )
@@ -476,39 +430,22 @@ static void CreateOrLoad()
476430 }
477431
478432 System . Diagnostics . Debug . Assert ( s_Instance != null ) ;
479-
480- // Only check installed build platforms to create classic profiles
481- // when the build profile flag is enabled. We need to check here
482- // because this method can be called from the static constructor.
483- // So we should only set the instance but not create profiles
484- if ( EditorUserBuildSettings . IsBuildProfileWorkflowEnabled ( ) )
485- {
486- s_Instance . CheckInstalledBuildPlatforms ( ) ;
487- }
433+ s_Instance . CheckInstalledBuildPlatforms ( ) ;
488434 }
489435
490436 [ RequiredByNativeCode , UsedImplicitly ]
491- static void SetClassicProfileRawPlatformSetting ( string settingName , string settingValue , BuildTarget target , StandaloneBuildSubtarget subtarget )
437+ static void SetActiveOrClassicProfileRawPlatformSetting ( string settingName , string settingValue , BuildTarget target , StandaloneBuildSubtarget subtarget )
492438 {
493- // If it is a shared setting, we will reset active to its classic counterpart if the specified shared
494- // setting is enabled in the active profile, and set the value in the shared profile.
439+ // If it is a shared setting, we will set the value in the active profile if the specified shared setting
440+ // is enabled in the active profile; Otherwise, we will set the value in the shared profile.
495441 if ( IsSharedProfile ( target ) )
496442 {
497- var profile = GetClassicProfileAndResetActive ( target , subtarget , settingName ) ;
443+ var profile = GetActiveOrClassicBuildProfile ( target , subtarget , settingName ) ;
498444 profile ? . platformBuildProfile . SetRawPlatformSetting ( settingName , settingValue ) ;
499445 return ;
500446 }
501447
502- // If the setting doesn't exist in classic platform, return
503- BuildProfile classicProfile = instance . GetForClassicPlatform ( target , subtarget ) ;
504- if ( classicProfile == null || classicProfile . platformBuildProfile == null )
505- return ;
506-
507- if ( classicProfile . platformBuildProfile . GetRawPlatformSetting ( settingName ) == null )
508- return ;
509-
510- // Setting exists, so we should set new value and reset active if needed
511- if ( TryGetClassicPlatformSettingsBaseAndResetActive ( target , subtarget , out BuildProfilePlatformSettingsBase platformProfile ) )
448+ if ( TryGetActiveOrClassicPlatformSettingsBase ( target , subtarget , out BuildProfilePlatformSettingsBase platformProfile ) )
512449 {
513450 platformProfile . SetRawPlatformSetting ( settingName , settingValue ) ;
514451 }
@@ -533,7 +470,7 @@ static string GetActiveOrClassicProfileRawPlatformSetting(string settingName, Bu
533470
534471 if ( TryGetActiveOrClassicPlatformSettingsBase ( target , subtarget , out BuildProfilePlatformSettingsBase platformProfile ) )
535472 {
536- string value = platformProfile . GetRawPlatformSetting ( settingName ) ;
473+ string value = platformProfile ? . GetRawPlatformSetting ( settingName ) ;
537474 return value != null ? value : string . Empty ;
538475 }
539476
0 commit comments