5
5
using UnityEditor ;
6
6
using UnityEngine ;
7
7
using System . Collections . Generic ;
8
+ using DiscoveredTargetInfo = UnityEditor . BuildTargetDiscovery . DiscoveredTargetInfo ;
9
+ using TargetAttributes = UnityEditor . BuildTargetDiscovery . TargetAttributes ;
8
10
9
11
namespace UnityEditor . Build
10
12
{
@@ -18,55 +20,22 @@ internal class BuildPlatform
18
20
public BuildTargetGroup targetGroup ;
19
21
public bool forceShowTarget ;
20
22
public string tooltip ;
23
+ public BuildTarget defaultTarget ;
21
24
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 )
24
27
{
25
28
}
26
29
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 )
28
31
{
29
32
this . targetGroup = targetGroup ;
30
33
name = targetGroup != BuildTargetGroup . Unknown ? BuildPipeline . GetBuildTargetGroupName ( defaultTarget ) : "" ;
31
34
title = EditorGUIUtility . TextContentWithIcon ( locTitle , iconId ) ;
32
35
smallIcon = EditorGUIUtility . IconContent ( iconId + ".Small" ) . image as Texture2D ;
33
36
this . tooltip = tooltip ;
34
37
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 ;
70
39
}
71
40
} ;
72
41
@@ -84,27 +53,32 @@ public static BuildPlatforms instance
84
53
85
54
internal BuildPlatforms ( )
86
55
{
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
91
56
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 ) ) ;
104
78
105
79
foreach ( var buildPlatform in buildPlatformsList )
106
80
{
107
- buildPlatform . tooltip = BuildPipeline . GetBuildTargetGroupDisplayName ( buildPlatform . targetGroup ) + " settings" ;
81
+ buildPlatform . tooltip = buildPlatform . title . text + " settings" ;
108
82
}
109
83
110
84
buildPlatforms = buildPlatformsList . ToArray ( ) ;
@@ -152,14 +126,22 @@ public string GetModuleDisplayName(BuildTargetGroup buildTargetGroup, BuildTarge
152
126
}
153
127
}
154
128
155
- public int BuildPlatformIndexFromTargetGroup ( BuildTargetGroup group )
129
+ private int BuildPlatformIndexFromTargetGroup ( BuildTargetGroup group )
156
130
{
157
131
for ( int i = 0 ; i < buildPlatforms . Length ; i ++ )
158
132
if ( group == buildPlatforms [ i ] . targetGroup )
159
133
return i ;
160
134
return - 1 ;
161
135
}
162
136
137
+ public bool ContainsBuildTarget ( BuildTargetGroup group )
138
+ {
139
+ if ( BuildPlatformIndexFromTargetGroup ( group ) < 0 )
140
+ return false ;
141
+
142
+ return true ;
143
+ }
144
+
163
145
public BuildPlatform BuildPlatformFromTargetGroup ( BuildTargetGroup group )
164
146
{
165
147
int index = BuildPlatformIndexFromTargetGroup ( group ) ;
0 commit comments