55using UnityEditor ;
66using UnityEngine ;
77using System . Collections . Generic ;
8+ using DiscoveredTargetInfo = UnityEditor . BuildTargetDiscovery . DiscoveredTargetInfo ;
9+ using TargetAttributes = UnityEditor . BuildTargetDiscovery . TargetAttributes ;
810
911namespace UnityEditor . Build
1012{
@@ -18,55 +20,22 @@ internal class BuildPlatform
1820 public BuildTargetGroup targetGroup ;
1921 public bool forceShowTarget ;
2022 public string tooltip ;
23+ public BuildTarget defaultTarget ;
2124
22- public BuildPlatform ( string locTitle , string iconId , BuildTargetGroup targetGroup , bool forceShowTarget )
23- : this ( locTitle , "" , iconId , targetGroup , forceShowTarget )
25+ public BuildPlatform ( string locTitle , string iconId , BuildTargetGroup targetGroup , BuildTarget defaultTarget , bool forceShowTarget )
26+ : this ( locTitle , "" , iconId , targetGroup , defaultTarget , forceShowTarget )
2427 {
2528 }
2629
27- public BuildPlatform ( string locTitle , string tooltip , string iconId , BuildTargetGroup targetGroup , bool forceShowTarget )
30+ public BuildPlatform ( string locTitle , string tooltip , string iconId , BuildTargetGroup targetGroup , BuildTarget defaultTarget , bool forceShowTarget )
2831 {
2932 this . targetGroup = targetGroup ;
3033 name = targetGroup != BuildTargetGroup . Unknown ? BuildPipeline . GetBuildTargetGroupName ( defaultTarget ) : "" ;
3134 title = EditorGUIUtility . TextContentWithIcon ( locTitle , iconId ) ;
3235 smallIcon = EditorGUIUtility . IconContent ( iconId + ".Small" ) . image as Texture2D ;
3336 this . tooltip = tooltip ;
3437 this . forceShowTarget = forceShowTarget ;
35- }
36-
37- // ADD_NEW_PLATFORM_HERE
38- public BuildTarget defaultTarget
39- {
40- get
41- {
42- switch ( targetGroup )
43- {
44- case BuildTargetGroup . Standalone :
45- return BuildTarget . StandaloneWindows ;
46- case BuildTargetGroup . iOS :
47- return BuildTarget . iOS ;
48- case BuildTargetGroup . tvOS :
49- return BuildTarget . tvOS ;
50- case BuildTargetGroup . PS4 :
51- return BuildTarget . PS4 ;
52- case BuildTargetGroup . XboxOne :
53- return BuildTarget . XboxOne ;
54- case BuildTargetGroup . Android :
55- return BuildTarget . Android ;
56- case BuildTargetGroup . Switch :
57- return BuildTarget . Switch ;
58- case BuildTargetGroup . WebGL :
59- return BuildTarget . WebGL ;
60- case BuildTargetGroup . WSA :
61- return BuildTarget . WSAPlayer ;
62- case BuildTargetGroup . Facebook :
63- return BuildTarget . StandaloneWindows64 ;
64- case BuildTargetGroup . Lumin :
65- return BuildTarget . Lumin ;
66- default :
67- return ( BuildTarget ) ( - 1 ) ;
68- }
69- }
38+ this . defaultTarget = defaultTarget ;
7039 }
7140 } ;
7241
@@ -84,27 +53,32 @@ public static BuildPlatforms instance
8453
8554 internal BuildPlatforms ( )
8655 {
87- // This is pretty brittle, notLicensedMessages and buildTargetNotInstalled below must match the order here
88- // and since NaCl isn't listed in the build settings like the other platforms you must not add anything after it, if it
89- // must also be added in the license/notinstalled arrays.
90- // ADD_NEW_PLATFORM_HERE
9156 List < BuildPlatform > buildPlatformsList = new List < BuildPlatform > ( ) ;
92- buildPlatformsList . Add ( new BuildPlatform ( "PC, Mac & Linux Standalone" , "BuildSettings.Standalone" , BuildTargetGroup . Standalone , true ) ) ;
93- buildPlatformsList . Add ( new BuildPlatform ( "iOS" , "BuildSettings.iPhone" , BuildTargetGroup . iOS , true ) ) ;
94- // TVOS TODO change the icon when it's ready
95- buildPlatformsList . Add ( new BuildPlatform ( "tvOS" , "BuildSettings.tvOS" , BuildTargetGroup . tvOS , true ) ) ;
96- buildPlatformsList . Add ( new BuildPlatform ( "Android" , "BuildSettings.Android" , BuildTargetGroup . Android , true ) ) ;
97- buildPlatformsList . Add ( new BuildPlatform ( "Xbox One" , "BuildSettings.XboxOne" , BuildTargetGroup . XboxOne , true ) ) ;
98- buildPlatformsList . Add ( new BuildPlatform ( "PS4" , "BuildSettings.PS4" , BuildTargetGroup . PS4 , true ) ) ;
99- buildPlatformsList . Add ( new BuildPlatform ( "Universal Windows Platform" , "BuildSettings.Metro" , BuildTargetGroup . WSA , true ) ) ;
100- buildPlatformsList . Add ( new BuildPlatform ( "WebGL" , "BuildSettings.WebGL" , BuildTargetGroup . WebGL , true ) ) ;
101- buildPlatformsList . Add ( new BuildPlatform ( "Facebook" , "BuildSettings.Facebook" , BuildTargetGroup . Facebook , true ) ) ;
102- buildPlatformsList . Add ( new BuildPlatform ( "Nintendo Switch" , "BuildSettings.Switch" , BuildTargetGroup . Switch , false ) ) ;
103- buildPlatformsList . Add ( new BuildPlatform ( "Lumin" , "BuildSettings.Lumin" , BuildTargetGroup . Lumin , false ) ) ;
57+ DiscoveredTargetInfo [ ] buildTargets = BuildTargetDiscovery . GetBuildTargetInfoList ( ) ;
58+
59+ // Standalone needs to be first
60+ buildPlatformsList . Add ( new BuildPlatform ( BuildPipeline . GetBuildTargetGroupDisplayName ( BuildTargetGroup . Standalone ) , "BuildSettings.Standalone" , BuildTargetGroup . Standalone , BuildTarget . StandaloneWindows , true ) ) ;
61+
62+ foreach ( var target in buildTargets )
63+ {
64+ if ( ! target . HasFlag ( TargetAttributes . IsStandalonePlatform ) )
65+ {
66+ BuildTargetGroup btg = BuildPipeline . GetBuildTargetGroup ( target . buildTgtPlatformVal ) ;
67+ buildPlatformsList . Add ( new BuildPlatform (
68+ BuildPipeline . GetBuildTargetGroupDisplayName ( btg ) ,
69+ target . iconName ,
70+ btg ,
71+ target . buildTgtPlatformVal ,
72+ ! target . HasFlag ( TargetAttributes . HideInUI ) ) ) ;
73+ }
74+ }
75+
76+ // Facebook is a special case and needs to be added separately
77+ buildPlatformsList . Add ( new BuildPlatform ( BuildPipeline . GetBuildTargetGroupDisplayName ( BuildTargetGroup . Facebook ) , "BuildSettings.Facebook" , BuildTargetGroup . Facebook , BuildTarget . StandaloneWindows64 , true ) ) ;
10478
10579 foreach ( var buildPlatform in buildPlatformsList )
10680 {
107- buildPlatform . tooltip = BuildPipeline . GetBuildTargetGroupDisplayName ( buildPlatform . targetGroup ) + " settings" ;
81+ buildPlatform . tooltip = buildPlatform . title . text + " settings" ;
10882 }
10983
11084 buildPlatforms = buildPlatformsList . ToArray ( ) ;
@@ -152,14 +126,22 @@ public string GetModuleDisplayName(BuildTargetGroup buildTargetGroup, BuildTarge
152126 }
153127 }
154128
155- public int BuildPlatformIndexFromTargetGroup ( BuildTargetGroup group )
129+ private int BuildPlatformIndexFromTargetGroup ( BuildTargetGroup group )
156130 {
157131 for ( int i = 0 ; i < buildPlatforms . Length ; i ++ )
158132 if ( group == buildPlatforms [ i ] . targetGroup )
159133 return i ;
160134 return - 1 ;
161135 }
162136
137+ public bool ContainsBuildTarget ( BuildTargetGroup group )
138+ {
139+ if ( BuildPlatformIndexFromTargetGroup ( group ) < 0 )
140+ return false ;
141+
142+ return true ;
143+ }
144+
163145 public BuildPlatform BuildPlatformFromTargetGroup ( BuildTargetGroup group )
164146 {
165147 int index = BuildPlatformIndexFromTargetGroup ( group ) ;
0 commit comments