@@ -22,41 +22,23 @@ internal class BuildProfileModuleUtil
22
22
{
23
23
const string k_BuyProUrl = "https://store.unity.com/products/unity-pro" ;
24
24
const string k_ConsoleModuleUrl = "https://unity3d.com/platform-installation" ;
25
- const string k_BuildSettingsPlatformIconFormat = "BuildSettings.{0}" ;
26
25
const string k_LastRunnableBuildPathSeparator = "_" ;
27
26
static readonly string k_NoModuleLoaded = L10n . Tr ( "No {0} module loaded." ) ;
28
27
static readonly string k_EditorWillNeedToBeReloaded = L10n . Tr ( "Note: Editor will need to be restarted to load any newly installed modules" ) ;
29
28
static readonly string k_BuildProfileRecompileReason = L10n . Tr ( "Active build profile scripting defines changes." ) ;
30
29
static readonly GUIContent k_OpenDownloadPage = EditorGUIUtility . TrTextContent ( "Open Download Page" ) ;
31
30
static readonly GUIContent k_InstallModuleWithHub = EditorGUIUtility . TrTextContent ( "Install with Unity Hub" ) ;
32
- static Dictionary < string , BuildTargetDiscovery . DiscoveredTargetInfo > s_DiscoveredTargetInfos = InitializeDiscoveredTargetDict ( ) ;
33
31
static HashSet < string > s_BuildProfileIconModules = new ( )
34
32
{
35
33
"Switch" ,
36
34
"QNX" ,
37
35
} ;
38
36
39
37
/// <summary>
40
- /// Classic platform display name for a given build profile. Matching
41
- /// value in the old BuildSettings window.
38
+ /// Classic platform display name for a given build profile.
42
39
/// </summary>
43
- /// <see cref="BuildPlayerWindow"/>
44
- public static string GetClassicPlatformDisplayName ( string platformId )
45
- {
46
- var ( buildTarget , subtarget ) = GetBuildTargetAndSubtarget ( platformId ) ;
47
- var moduleName = GetModuleName ( buildTarget ) ;
48
-
49
- return ( moduleName , subtarget ) switch
50
- {
51
- ( "OSXStandalone" , StandaloneBuildSubtarget . Server ) => "Mac Server" ,
52
- ( "WindowsStandalone" , StandaloneBuildSubtarget . Server ) => "Windows Server" ,
53
- ( "LinuxStandalone" , StandaloneBuildSubtarget . Server ) => "Linux Server" ,
54
- ( "OSXStandalone" , _ ) => "Mac" ,
55
- ( "WindowsStandalone" , _ ) => "Windows" ,
56
- ( "LinuxStandalone" , _ ) => "Linux" ,
57
- _ => GetModuleDisplayName ( moduleName ) ,
58
- } ;
59
- }
40
+ public static string GetClassicPlatformDisplayName ( string platformId ) =>
41
+ GetModuleDisplayName ( platformId ) ;
60
42
61
43
/// <summary>
62
44
/// Fetch default editor platform icon texture.
@@ -102,25 +84,10 @@ public static Texture2D GetWarningIcon()
102
84
/// </summary>
103
85
public static bool IsModuleInstalled ( string platformId )
104
86
{
105
- var ( buildTarget , subtarget ) = GetBuildTargetAndSubtarget ( platformId ) ;
87
+ var ( buildTarget , _ ) = GetBuildTargetAndSubtarget ( platformId ) ;
106
88
var moduleName = GetModuleName ( buildTarget ) ;
107
89
108
- // NamedBuildTarget will be deprecated. This code is extracted from
109
- // NamedBuildTarget.FromActiveSettings. Except instead of taking a dependency
110
- // on Editor User Build Settings, we use the passed subtarget.
111
- NamedBuildTarget namedTarget ;
112
- var buildTargetGroup = BuildPipeline . GetBuildTargetGroup ( buildTarget ) ;
113
- if ( buildTargetGroup == BuildTargetGroup . Standalone
114
- && subtarget == StandaloneBuildSubtarget . Server )
115
- {
116
- namedTarget = NamedBuildTarget . Server ;
117
- }
118
- else
119
- {
120
- namedTarget = NamedBuildTarget . FromBuildTargetGroup ( buildTargetGroup ) ;
121
- }
122
-
123
- bool installed = BuildPlatforms . instance . BuildPlatformFromNamedBuildTarget ( namedTarget ) . installed ;
90
+ bool installed = BuildTargetDiscovery . BuildPlatformIsInstalled ( new GUID ( platformId ) ) ;
124
91
return installed
125
92
&& BuildPipeline . LicenseCheck ( buildTarget )
126
93
&& ! string . IsNullOrEmpty ( moduleName )
@@ -168,9 +135,7 @@ public static VisualElement CreateLicenseNotFoundElement(string platformId)
168
135
if ( BuildPipeline . LicenseCheck ( buildTarget ) )
169
136
return null ;
170
137
171
- var targetGroup = BuildPipeline . GetBuildTargetGroup ( buildTarget ) ;
172
- var namedBuildTarget = NamedBuildTarget . FromBuildTargetGroup ( targetGroup ) ;
173
- string niceName = BuildPipeline . GetBuildTargetGroupDisplayName ( namedBuildTarget . ToBuildTargetGroup ( ) ) ;
138
+ string displayName = GetModuleDisplayName ( platformId ) ;
174
139
string licenseMsg = L10n . Tr ( "Your license does not cover {0} Publishing." ) ;
175
140
string buttonMsg = L10n . Tr ( "Go to Our Online Store" ) ;
176
141
string url = k_BuyProUrl ;
@@ -184,7 +149,7 @@ public static VisualElement CreateLicenseNotFoundElement(string platformId)
184
149
185
150
var root = new VisualElement ( ) ;
186
151
root . style . flexDirection = FlexDirection . Column ;
187
- var label = new Label ( string . Format ( licenseMsg , niceName ) ) ;
152
+ var label = new Label ( string . Format ( licenseMsg , displayName ) ) ;
188
153
label . style . whiteSpace = WhiteSpace . Normal ;
189
154
root . Add ( label ) ;
190
155
if ( ! BuildTargetDiscovery . PlatformHasFlag ( buildTarget , TargetAttributes . IsStandalonePlatform ) )
@@ -341,36 +306,23 @@ public static IBuildProfileExtension GetBuildProfileExtension(string moduleName)
341
306
/// </summary>
342
307
public static List < string > FindAllViewablePlatforms ( )
343
308
{
344
- var result = new List < string > ( )
309
+ var result = new List < string > ( ) ;
310
+
311
+ foreach ( var platformGuid in BuildTargetDiscovery . GetAllPlatforms ( ) )
345
312
{
346
- GetPlatformId ( BuildTarget . StandaloneWindows64 , StandaloneBuildSubtarget . Player ) ,
347
- GetPlatformId ( BuildTarget . StandaloneOSX , StandaloneBuildSubtarget . Player ) ,
348
- GetPlatformId ( BuildTarget . StandaloneLinux64 , StandaloneBuildSubtarget . Player ) ,
349
- GetPlatformId ( BuildTarget . StandaloneWindows64 , StandaloneBuildSubtarget . Server ) ,
350
- GetPlatformId ( BuildTarget . StandaloneOSX , StandaloneBuildSubtarget . Server ) ,
351
- GetPlatformId ( BuildTarget . StandaloneLinux64 , StandaloneBuildSubtarget . Server )
352
- } ;
313
+ var installed = BuildTargetDiscovery . BuildPlatformIsInstalled ( platformGuid ) ;
314
+ if ( ! installed && BuildTargetDiscovery . BuildPlatformIsHiddenInUI ( platformGuid ) )
315
+ continue ;
316
+
317
+ result . Add ( platformGuid . ToString ( ) ) ;
318
+ }
353
319
354
320
// Swap current editor standalone platform to the top.
355
321
if ( Application . platform == RuntimePlatform . OSXEditor )
356
322
result . Reverse ( 0 , 2 ) ;
357
323
if ( Application . platform == RuntimePlatform . LinuxEditor )
358
324
result . Reverse ( 0 , 3 ) ;
359
325
360
- foreach ( var buildTargetInfo in BuildTargetDiscovery . GetBuildTargetInfoList ( ) )
361
- {
362
- if ( buildTargetInfo . HasFlag ( TargetAttributes . IsStandalonePlatform ) )
363
- continue ;
364
-
365
- // installed platform check from BuildPlatforms
366
- bool installed = BuildPipeline . GetPlaybackEngineDirectory ( buildTargetInfo . buildTargetPlatformVal , BuildOptions . None , false ) != string . Empty ;
367
- if ( ! installed && buildTargetInfo . HasFlag ( TargetAttributes . HideInUI ) )
368
- continue ;
369
-
370
- var platformId = GetPlatformId ( buildTargetInfo . buildTargetPlatformVal , StandaloneBuildSubtarget . Default ) ;
371
- result . Add ( platformId ) ;
372
- }
373
-
374
326
return result ;
375
327
}
376
328
@@ -542,17 +494,6 @@ internal static void SetBuildProfileLastRunnableBuildPathKey(string key, string
542
494
EditorPrefs . SetString ( key , value ) ;
543
495
}
544
496
545
- static Dictionary < string , BuildTargetDiscovery . DiscoveredTargetInfo > InitializeDiscoveredTargetDict ( )
546
- {
547
- var result = new Dictionary < string , BuildTargetDiscovery . DiscoveredTargetInfo > ( ) ;
548
- foreach ( var kvp in BuildTargetDiscovery . GetBuildTargetInfoList ( ) )
549
- {
550
- var targetString = GetModuleName ( kvp . buildTargetPlatformVal ) ;
551
- result . TryAdd ( targetString , kvp ) ;
552
- }
553
- return result ;
554
- }
555
-
556
497
static bool LoadBuildProfileIcon ( string platformId , out Texture2D icon )
557
498
{
558
499
var moduleName = GetModuleName ( platformId ) ;
@@ -568,31 +509,17 @@ static bool LoadBuildProfileIcon(string platformId, out Texture2D icon)
568
509
569
510
static string GetPlatformIconId ( string platformId )
570
511
{
571
- var ( buildTarget , subtarget ) = GetBuildTargetAndSubtarget ( platformId ) ;
572
- var moduleName = GetModuleName ( buildTarget ) ;
573
-
574
- if ( subtarget == StandaloneBuildSubtarget . Server )
575
- {
576
- return string . Format ( k_BuildSettingsPlatformIconFormat , "DedicatedServer" ) ;
577
- }
512
+ var iconName = BuildTargetDiscovery . BuildPlatformIconName ( new GUID ( platformId ) ) ;
578
513
579
- if ( s_DiscoveredTargetInfos . TryGetValue ( moduleName , out var targetInfo ) )
580
- {
581
- return targetInfo . iconName ;
582
- }
514
+ if ( string . IsNullOrEmpty ( iconName ) )
515
+ return "BuildSettings.Editor" ;
583
516
584
- return "BuildSettings.Editor" ;
517
+ return iconName ;
585
518
}
586
519
587
- /// <summary>
588
- /// Module display name as defined on native side in "BuildTargetGroupName.h"
589
- /// </summary>
590
- static string GetModuleDisplayName ( string moduleName )
520
+ static string GetModuleDisplayName ( string platformId )
591
521
{
592
- if ( ! s_DiscoveredTargetInfos . TryGetValue ( moduleName , out var gt ) )
593
- return moduleName ;
594
-
595
- return BuildPipeline . GetBuildTargetGroupDisplayName ( BuildPipeline . GetBuildTargetGroup ( gt . buildTargetPlatformVal ) ) ;
522
+ return BuildTargetDiscovery . BuildPlatformDisplayName ( new GUID ( platformId ) ) ;
596
523
}
597
524
598
525
/// <summary>
0 commit comments