8
8
using UnityEngine ;
9
9
using UnityEngine . Bindings ;
10
10
using UnityEngine . Scripting ;
11
+ using UnityEditor . Modules ;
11
12
12
13
namespace UnityEditor . Build . Profile
13
14
{
@@ -45,14 +46,26 @@ internal StandaloneBuildSubtarget subtarget
45
46
/// <summary>
46
47
/// Module name used to fetch build profiles.
47
48
/// </summary>
48
- [ SerializeField ] string m_ModuleName ;
49
+ string m_ModuleName ;
49
50
[ VisibleToOtherModules ]
50
51
internal string moduleName
51
52
{
52
53
get => m_ModuleName ;
53
54
set => m_ModuleName = value ;
54
55
}
55
56
57
+ /// <summary>
58
+ /// Platform ID of the build profile.
59
+ /// Correspond to platform GUID in <see cref="BuildTargetDiscovery"/>
60
+ /// </summary>
61
+ [ SerializeField ] string m_PlatformId ;
62
+ [ VisibleToOtherModules ]
63
+ internal string platformId
64
+ {
65
+ get => m_PlatformId ;
66
+ set => m_PlatformId = value ;
67
+ }
68
+
56
69
/// <summary>
57
70
/// Platform module specific build settings; e.g. AndroidBuildSettings.
58
71
/// </summary>
@@ -96,7 +109,7 @@ public EditorBuildSettingsScene[] scenes
96
109
/// define be deserializing the YAML file and assumes defines will be found under "m_ScriptingDefines" node.
97
110
/// </remarks>
98
111
[ SerializeField ] private string [ ] m_ScriptingDefines = Array . Empty < string > ( ) ;
99
- [ VisibleToOtherModules ] internal string [ ] scriptingDefines
112
+ public string [ ] scriptingDefines
100
113
{
101
114
get => m_ScriptingDefines ;
102
115
set => m_ScriptingDefines = value ;
@@ -114,6 +127,12 @@ internal PlayerSettings playerSettings
114
127
set { m_PlayerSettings = value ; }
115
128
}
116
129
130
+ // TODO: Return server IBuildTargets for server build profiles. (https://jira.unity3d.com/browse/PLAT-6612)
131
+ /// <summary>
132
+ /// Get the IBuildTarget of the build profile.
133
+ /// </summary>
134
+ internal IBuildTarget GetIBuildTarget ( ) => ModuleManager . GetIBuildTarget ( buildTarget ) ;
135
+
117
136
/// <summary>
118
137
/// Returns true if the given <see cref="BuildProfile"/> is the active profile or a classic
119
138
/// profile for the EditorUserBuildSettings active build target.
@@ -128,30 +147,43 @@ internal bool IsActiveBuildProfileOrPlatform()
128
147
|| ! BuildProfileContext . IsClassicPlatformProfile ( this ) )
129
148
return false ;
130
149
131
- if ( ! BuildProfileModuleUtil . IsStandalonePlatform ( buildTarget ) )
132
- return buildTarget == EditorUserBuildSettings . activeBuildTarget ;
133
-
134
- var profileModuleName = BuildProfileModuleUtil . GetModuleName ( buildTarget ) ;
135
- var activeModuleName = BuildProfileModuleUtil . GetModuleName ( EditorUserBuildSettings . activeBuildTarget ) ;
136
- return profileModuleName == activeModuleName && subtarget == EditorUserBuildSettings . standaloneBuildSubtarget ;
150
+ var activePlatformId = BuildProfileModuleUtil . GetPlatformId (
151
+ EditorUserBuildSettings . activeBuildTarget , EditorUserBuildSettings . standaloneBuildSubtarget ) ;
152
+ return platformId == activePlatformId ;
137
153
}
138
154
139
155
[ VisibleToOtherModules ]
140
156
internal bool CanBuildLocally ( )
141
157
{
142
158
// Note: A platform build profile may have a non-null value even if its module is not installed.
143
159
// This scenario is true for server platform profiles, which are the same type as the standalone one.
144
- return platformBuildProfile != null && BuildProfileModuleUtil . IsModuleInstalled ( moduleName , subtarget ) ;
160
+ return platformBuildProfile != null && BuildProfileModuleUtil . IsModuleInstalled ( platformId ) ;
161
+ }
162
+
163
+ internal string GetLastRunnableBuildPathKey ( )
164
+ {
165
+ if ( platformBuildProfile == null )
166
+ return string . Empty ;
167
+
168
+ var key = platformBuildProfile . GetLastRunnableBuildPathKey ( ) ;
169
+ if ( string . IsNullOrEmpty ( key ) || BuildProfileContext . IsClassicPlatformProfile ( this ) )
170
+ return key ;
171
+
172
+ string assetPath = AssetDatabase . GetAssetPath ( this ) ;
173
+ return BuildProfileModuleUtil . GetLastRunnableBuildKeyFromAssetPath ( assetPath , key ) ;
145
174
}
146
175
147
176
void OnEnable ( )
148
177
{
178
+ ValidateDataConsistency ( ) ;
179
+
180
+ moduleName = BuildProfileModuleUtil . GetModuleName ( platformId ) ;
181
+
149
182
// Check if the platform support module has been installed,
150
183
// and try to set an uninitialized platform settings.
151
184
if ( platformBuildProfile == null )
152
185
TryCreatePlatformSettings ( ) ;
153
186
154
- CheckSceneListConsistency ( ) ;
155
187
onBuildProfileEnable ? . Invoke ( this ) ;
156
188
LoadPlayerSettings ( ) ;
157
189
@@ -182,6 +214,30 @@ void OnDisable()
182
214
AssetDatabase . SaveAssetIfDirty ( this ) ;
183
215
}
184
216
217
+ void ValidateDataConsistency ( )
218
+ {
219
+ // TODO: Remove migration code (https://jira.unity3d.com/browse/PLAT-8909)
220
+ // Set platform ID for build profiles created before it is introduced.
221
+ if ( string . IsNullOrEmpty ( platformId ) )
222
+ {
223
+ platformId = BuildProfileContext . IsSharedProfile ( buildTarget ) ?
224
+ new GUID ( string . Empty ) . ToString ( ) : BuildProfileModuleUtil . GetPlatformId ( buildTarget , subtarget ) ;
225
+ EditorUtility . SetDirty ( this ) ;
226
+ }
227
+ else
228
+ {
229
+ var ( curBuildTarget , curSubtarget ) = BuildProfileModuleUtil . GetBuildTargetAndSubtarget ( platformId ) ;
230
+ if ( buildTarget != curBuildTarget || subtarget != curSubtarget )
231
+ {
232
+ buildTarget = curBuildTarget ;
233
+ subtarget = curSubtarget ;
234
+ EditorUtility . SetDirty ( this ) ;
235
+ }
236
+ }
237
+
238
+ CheckSceneListConsistency ( ) ;
239
+ }
240
+
185
241
/// <summary>
186
242
/// EditorBuildSettingsScene stores both path and GUID. Path can become
187
243
/// invalid when scenes are moved or renamed and must be recalculated.
0 commit comments