88using UnityEngine ;
99using UnityEngine . Bindings ;
1010using UnityEngine . Scripting ;
11+ using UnityEditor . Modules ;
1112
1213namespace UnityEditor . Build . Profile
1314{
@@ -45,14 +46,26 @@ internal StandaloneBuildSubtarget subtarget
4546 /// <summary>
4647 /// Module name used to fetch build profiles.
4748 /// </summary>
48- [ SerializeField ] string m_ModuleName ;
49+ string m_ModuleName ;
4950 [ VisibleToOtherModules ]
5051 internal string moduleName
5152 {
5253 get => m_ModuleName ;
5354 set => m_ModuleName = value ;
5455 }
5556
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+
5669 /// <summary>
5770 /// Platform module specific build settings; e.g. AndroidBuildSettings.
5871 /// </summary>
@@ -96,7 +109,7 @@ public EditorBuildSettingsScene[] scenes
96109 /// define be deserializing the YAML file and assumes defines will be found under "m_ScriptingDefines" node.
97110 /// </remarks>
98111 [ SerializeField ] private string [ ] m_ScriptingDefines = Array . Empty < string > ( ) ;
99- [ VisibleToOtherModules ] internal string [ ] scriptingDefines
112+ public string [ ] scriptingDefines
100113 {
101114 get => m_ScriptingDefines ;
102115 set => m_ScriptingDefines = value ;
@@ -114,6 +127,12 @@ internal PlayerSettings playerSettings
114127 set { m_PlayerSettings = value ; }
115128 }
116129
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+
117136 /// <summary>
118137 /// Returns true if the given <see cref="BuildProfile"/> is the active profile or a classic
119138 /// profile for the EditorUserBuildSettings active build target.
@@ -128,30 +147,43 @@ internal bool IsActiveBuildProfileOrPlatform()
128147 || ! BuildProfileContext . IsClassicPlatformProfile ( this ) )
129148 return false ;
130149
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 ;
137153 }
138154
139155 [ VisibleToOtherModules ]
140156 internal bool CanBuildLocally ( )
141157 {
142158 // Note: A platform build profile may have a non-null value even if its module is not installed.
143159 // 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 ) ;
145174 }
146175
147176 void OnEnable ( )
148177 {
178+ ValidateDataConsistency ( ) ;
179+
180+ moduleName = BuildProfileModuleUtil . GetModuleName ( platformId ) ;
181+
149182 // Check if the platform support module has been installed,
150183 // and try to set an uninitialized platform settings.
151184 if ( platformBuildProfile == null )
152185 TryCreatePlatformSettings ( ) ;
153186
154- CheckSceneListConsistency ( ) ;
155187 onBuildProfileEnable ? . Invoke ( this ) ;
156188 LoadPlayerSettings ( ) ;
157189
@@ -182,6 +214,30 @@ void OnDisable()
182214 AssetDatabase . SaveAssetIfDirty ( this ) ;
183215 }
184216
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+
185241 /// <summary>
186242 /// EditorBuildSettingsScene stores both path and GUID. Path can become
187243 /// invalid when scenes are moved or renamed and must be recalculated.
0 commit comments