@@ -172,51 +172,16 @@ internal static BuildProfile GetActiveOrClassicBuildProfile(
172
172
return IsSharedProfile ( target ) ? instance . sharedProfile : instance . GetForClassicPlatform ( target , subTarget ) ;
173
173
}
174
174
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
-
202
175
internal static bool TryGetActiveOrClassicPlatformSettingsBase < T > (
203
176
BuildTarget target , StandaloneBuildSubtarget subTarget , out T result ) where T : BuildProfilePlatformSettingsBase
204
177
{
205
- BuildProfile buildProfile = GetActiveOrClassicBuildProfile ( target , subTarget ) ;
206
- if ( buildProfile != null && buildProfile . platformBuildProfile is T platformProfile )
178
+ if ( ! EditorUserBuildSettings . IsBuildProfileScriptingAvailable ( ) )
207
179
{
208
- result = platformProfile ;
209
- return true ;
180
+ result = null ;
181
+ return false ;
210
182
}
211
183
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 ) ;
220
185
if ( buildProfile != null && buildProfile . platformBuildProfile is T platformProfile )
221
186
{
222
187
result = platformProfile ;
@@ -301,17 +266,11 @@ void OnEnable()
301
266
if ( ! Directory . Exists ( k_BuildProfilePath ) )
302
267
return ;
303
268
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 ++ )
311
271
{
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 ) ;
315
274
316
275
if ( ! File . Exists ( path ) )
317
276
continue ;
@@ -346,31 +305,26 @@ void OnEnable()
346
305
/// </summary>
347
306
void CheckInstalledBuildPlatforms ( )
348
307
{
349
- foreach ( var platform in BuildPlatforms . instance . GetValidPlatforms ( ) )
308
+ var viewablePlatformKeys = BuildProfileModuleUtil . FindAllViewablePlatforms ( ) ;
309
+ for ( var index = 0 ; index < viewablePlatformKeys . Count ; index ++ )
350
310
{
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 ) )
354
316
continue ;
355
- }
356
317
357
- if ( ModuleManager . GetBuildProfileExtension ( targetString ) == null )
318
+ if ( ModuleManager . GetBuildProfileExtension ( moduleName ) == null )
358
319
{
359
320
// Require platform support and implemented build profile
360
321
// 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 ) ;
362
323
continue ;
363
324
}
364
325
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 ) ;
374
328
}
375
329
376
330
GetOrCreateSharedBuildProfile ( ) ;
@@ -462,7 +416,7 @@ static void SaveBuildProfileInProject(BuildProfile profile)
462
416
static void CreateOrLoad ( )
463
417
{
464
418
var buildProfileContext = InternalEditorUtility . LoadSerializedFileAndForget ( k_BuildProfileProviderAssetPath ) ;
465
- if ( buildProfileContext != null && buildProfileContext . Length > 0 )
419
+ if ( buildProfileContext != null && buildProfileContext . Length > 0 && buildProfileContext [ 0 ] != null )
466
420
{
467
421
s_Instance = buildProfileContext [ 0 ] as BuildProfileContext ;
468
422
if ( s_Instance == null )
@@ -476,39 +430,22 @@ static void CreateOrLoad()
476
430
}
477
431
478
432
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 ( ) ;
488
434
}
489
435
490
436
[ 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 )
492
438
{
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.
495
441
if ( IsSharedProfile ( target ) )
496
442
{
497
- var profile = GetClassicProfileAndResetActive ( target , subtarget , settingName ) ;
443
+ var profile = GetActiveOrClassicBuildProfile ( target , subtarget , settingName ) ;
498
444
profile ? . platformBuildProfile . SetRawPlatformSetting ( settingName , settingValue ) ;
499
445
return ;
500
446
}
501
447
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 ) )
512
449
{
513
450
platformProfile . SetRawPlatformSetting ( settingName , settingValue ) ;
514
451
}
@@ -533,7 +470,7 @@ static string GetActiveOrClassicProfileRawPlatformSetting(string settingName, Bu
533
470
534
471
if ( TryGetActiveOrClassicPlatformSettingsBase ( target , subtarget , out BuildProfilePlatformSettingsBase platformProfile ) )
535
472
{
536
- string value = platformProfile . GetRawPlatformSetting ( settingName ) ;
473
+ string value = platformProfile ? . GetRawPlatformSetting ( settingName ) ;
537
474
return value != null ? value : string . Empty ;
538
475
}
539
476
0 commit comments