-
Notifications
You must be signed in to change notification settings - Fork 2.6k
Expand file tree
/
Copy pathBuildProfileWindow.cs
More file actions
684 lines (585 loc) · 29.5 KB
/
BuildProfileWindow.cs
File metadata and controls
684 lines (585 loc) · 29.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
// Unity C# reference source
// Copyright (c) Unity Technologies. For terms of use, see
// https://unity3d.com/legal/licenses/Unity_Reference_Only_License
using System;
using System.Collections.Generic;
using JetBrains.Annotations;
using UnityEditor.Build.Profile.Elements;
using UnityEditor.Build.Profile.Handlers;
using UnityEditor.UIElements;
using UnityEngine;
using UnityEngine.Scripting;
using UnityEngine.UIElements;
using static UnityEditor.Build.Profile.Handlers.BuildProfileWindowSelection;
namespace UnityEditor.Build.Profile
{
/// <summary>
/// Build Settings window in 'File > Build Settings'.
/// Handles creating and editing of <see cref="BuildProfile"/> assets.
/// </summary>
internal class BuildProfileWindow : EditorWindow
{
const string k_DevOpsUrl = "https://unity.com/products/unity-devops?utm_medium=desktop-app&utm_source=unity-editor-window-menu&utm_content=buildsettings";
const string k_Uxml = "BuildProfile/UXML/BuildProfileWindow.uxml";
const string k_PlayerSettingsWindow = "Project/Player";
internal const string buildProfileInspectorVisualElement = "build-profile-editor-inspector";
internal const string buildProfileInspectorHeaderVisualElement = "build-profile-editor-inspector-header";
internal BuildProfileEditor buildProfileEditor;
BuildProfileWorkflowState m_WindowState;
bool m_ShouldAskForBuildLocation = true;
BuildProfileDataSource m_BuildProfileDataSource;
BuildProfileContextMenu m_BuildProfileContextMenu;
BuildProfileWindowSelection m_BuildProfileSelection;
/// <summary>
/// Left column classic profile list view.
/// </summary>
PlatformListView m_ProfileListViews;
VisualElement m_WelcomeMessageElement;
VisualElement m_SelectionHeader;
VisualElement m_SelectionFooter;
/// <summary>
/// Build Profile inspector for the selected classic platform or profile,
/// repainted on <see cref="m_BuildProfileClassicPlatformListView"/> selection change.
/// </summary>
/// <see cref="OnClassicPlatformSelected"/>
ScrollView m_BuildProfileInspectorElement;
VisualElement m_BuildProfileInspectorHeaderElement;
VisualElement m_AdditionalActionsDropdown;
DropdownButton m_BuildButton;
ToolbarButton m_AssetImportButton;
Button m_BuildAndRunButton;
Button m_ActivateButton;
Button m_BuildInCloudPackageButton;
AssetImportOverridesWindow m_AssetImportWindow;
Background m_WarningIcon;
[UsedImplicitly, RequiredByNativeCode]
public static void ShowBuildProfileWindow()
{
var window = GetWindow<BuildProfileWindow>(TrText.buildProfilesName);
window.minSize = new Vector2(725, 400);
}
public void CreateGUI()
{
m_WindowState = new BuildProfileWorkflowState(OnWorkflowStateChanged);
var windowUxml = EditorGUIUtility.LoadRequired(k_Uxml) as VisualTreeAsset;
var windowUss = EditorGUIUtility.LoadRequired(Util.k_StyleSheet) as StyleSheet;
rootVisualElement.styleSheets.Add(windowUss);
windowUxml.CloneTree(rootVisualElement);
var listViewAddProfileButton = rootVisualElement.Q<Button>("fallback-add-profile-button");
var addBuildProfileButton = rootVisualElement.Q<ToolbarButton>("add-build-profile-button");
var playerSettingsButton = rootVisualElement.Q<ToolbarButton>("player-settings-button");
m_AssetImportButton = rootVisualElement.Q<ToolbarButton>("asset-import-overrides-button");
// Capture static visual element reference.
m_AdditionalActionsDropdown = rootVisualElement.Q<VisualElement>("additional-actions-dropdown-button");
m_BuildButton = CreateBuildDropdownButton();
rootVisualElement.Q<VisualElement>("build-dropdown-button").Add(m_BuildButton);
m_BuildProfileInspectorElement = rootVisualElement.Q<ScrollView>(buildProfileInspectorVisualElement);
m_BuildProfileInspectorHeaderElement = rootVisualElement.Q<VisualElement>(buildProfileInspectorHeaderVisualElement);
m_BuildAndRunButton = rootVisualElement.Q<Button>("build-and-run-button");
m_ActivateButton = rootVisualElement.Q<Button>("activate-button");
m_BuildInCloudPackageButton = rootVisualElement.Q<Button>("build-cloud-build-pkg");
m_WelcomeMessageElement = rootVisualElement.Q<VisualElement>("fallback-no-custom-build-profiles");
m_SelectionHeader = rootVisualElement.Q<VisualElement>("build-profile-editor-header");
m_SelectionFooter = rootVisualElement.Q<VisualElement>("build-profile-editor-footer");
// Apply localized text to static elements.
rootVisualElement.Q<Label>("platforms-label").text = TrText.platforms;
rootVisualElement.Q<Label>("build-profiles-label").text = TrText.buildProfilesName;
rootVisualElement.Q<Label>("fallback-welcome-label").text = TrText.buildProfileWelcome;
addBuildProfileButton.text = TrText.addBuildProfile;
playerSettingsButton.text = TrText.playerSettings;
listViewAddProfileButton.text = TrText.addBuildProfile;
m_ActivateButton.text = TrText.activate;
m_BuildAndRunButton.text = TrText.buildAndRun;
m_BuildInCloudPackageButton.text = TrText.cloudBuild;
UpdateToolbarButtonState();
// Build dynamic visual elements.
if (m_BuildProfileDataSource != null)
m_BuildProfileDataSource.Dispose();
m_BuildProfileDataSource = new BuildProfileDataSource(this);
m_ProfileListViews = new PlatformListView(this, m_BuildProfileDataSource);
m_BuildProfileSelection = new BuildProfileWindowSelection(rootVisualElement, m_ProfileListViews);
m_BuildProfileContextMenu = new BuildProfileContextMenu(this, m_BuildProfileSelection, m_BuildProfileDataSource);
m_ProfileListViews.Create();
if (m_BuildProfileDataSource.customBuildProfiles.Count > 0)
{
m_ProfileListViews.ShowCustomBuildProfiles();
m_WelcomeMessageElement.Hide();
}
// When creating the profile lists, the bind callbacks (which set the active profile index)
// will be called after this, so we need to find the active profile to select it in here
m_ProfileListViews.SelectActiveProfile();
// Set up event handlers.
m_BuildAndRunButton.clicked += () =>
{
OnBuildButtonClicked(BuildOptions.AutoRunPlayer | BuildOptions.StrictMode);
};
m_ActivateButton.clicked += OnActivateButtonClicked;
m_BuildInCloudPackageButton.clicked += OnCloudBuildClicked;
addBuildProfileButton.clicked += PlatformDiscoveryWindow.ShowWindow;
listViewAddProfileButton.clicked += PlatformDiscoveryWindow.ShowWindow;
playerSettingsButton.clicked += () =>
{
SettingsService.OpenProjectSettings(k_PlayerSettingsWindow);
};
m_AssetImportButton.clicked += () =>
{
if (m_AssetImportWindow == null)
m_AssetImportWindow = ScriptableObject.CreateInstance<AssetImportOverridesWindow>();
m_AssetImportWindow.ShowUtilityWindow(UpdateToolbarButtonState);
};
BuildProfileContext.activeProfileChanged -= OnActiveProfileChanged;
BuildProfileContext.activeProfileChanged += OnActiveProfileChanged;
ActiveBuildTargetListener.activeBuildTargetChanged += OnActiveBuildTargetChanged;
}
public void OnDisable()
{
DestroyImmediate(buildProfileEditor);
BuildProfileContext.activeProfileChanged -= OnActiveProfileChanged;
ActiveBuildTargetListener.activeBuildTargetChanged -= OnActiveBuildTargetChanged;
if (m_BuildProfileDataSource != null)
{
SendWorkflowReport();
m_BuildProfileDataSource.Dispose();
}
if (m_AssetImportWindow != null)
m_AssetImportWindow.Close();
m_ProfileListViews?.Unbind();
}
/// <summary>
/// Handle selection of custom build profile item, creates embedded inspector and clears
/// adjacent list views.
/// </summary>
internal void OnCustomProfileSelected(IEnumerable<object> selectedItems)
{
using var item = selectedItems.GetEnumerator();
if (!item.MoveNext())
return;
bool shouldRebuild = m_BuildProfileDataSource.DeleteNullProfiles();
var profile = item.Current as BuildProfile;
if (profile == null)
{
RepaintAndClearSelection();
Debug.LogWarning("BuildProfileWindow: selected item has been deleted?");
return;
}
m_ActivateButton.text = TrText.activate;
m_ProfileListViews.CleanupSelection(ListViewSelectionType.Custom);
m_SelectionHeader.Show();
m_SelectionFooter.Show();
m_BuildProfileSelection.SelectItems(selectedItems);
m_BuildProfileSelection.UpdateSelectionGUI(profile);
if (!m_BuildProfileSelection.IsMultipleSelection())
{
RebuildBuildProfileEditor(profile);
}
else
{
m_BuildProfileInspectorElement.Clear();
m_BuildProfileInspectorHeaderElement.Clear();
UpdateFormButtonState(null);
}
if (shouldRebuild)
RebuildProfileListViews();
BuildProfileModuleUtil.RepaintProjectSettingsWindow();
}
/// <summary>
/// Handle selection of classic platform profile.
/// </summary>
internal void OnClassicPlatformSelected(BuildProfile profile)
{
if (profile == null)
{
Debug.LogWarning("BuildProfileWindow: selected platform has been deleted?");
return;
}
m_ActivateButton.text = TrText.activatePlatform;
m_ProfileListViews.CleanupSelection(ListViewSelectionType.Classic);
m_SelectionHeader.Show();
m_SelectionFooter.Show();
m_BuildProfileSelection.SelectItem(profile);
m_BuildProfileSelection.UpdateSelectionGUI(profile);
RebuildBuildProfileEditor(profile);
if (m_BuildProfileDataSource.DeleteNullProfiles())
RebuildProfileListViews();
BuildProfileModuleUtil.RepaintProjectSettingsWindow();
}
/// <summary>
/// Handles selection of unavailable and supported platform.
/// </summary>
internal void OnMissingClassicPlatformSelected(GUID platformId)
{
m_SelectionHeader.Show();
m_SelectionFooter.Show();
m_ProfileListViews.CleanupSelection(ListViewSelectionType.MissingClassic);
UpdateFormButtonState(null);
// Render platform requirement helpbox instead of default inspector.
m_BuildProfileInspectorElement.Clear();
m_BuildProfileInspectorHeaderElement.Clear();
var warningHelpBox = new HelpBox()
{
messageType = HelpBoxMessageType.Warning
};
warningHelpBox.AddToClassList("mx-medium");
Util.UpdatePlatformRequirementsWarningHelpBox(warningHelpBox, platformId);
m_BuildProfileInspectorElement.Add(warningHelpBox);
// Update details headers.
m_BuildProfileSelection.MissingPlatformSelected(platformId);
BuildProfileModuleUtil.RepaintProjectSettingsWindow();
}
/// <summary>
/// Show classic platform UI for globally shared settings.
/// </summary>
internal void OnClassicSceneListSelected()
{
m_BuildProfileSelection.ClearSelectedProfiles();
m_ProfileListViews.SelectSharedSceneList();
DestroyImmediate(buildProfileEditor);
buildProfileEditor = ScriptableObject.CreateInstance<BuildProfileEditor>();
m_BuildProfileInspectorElement.Clear();
m_BuildProfileInspectorHeaderElement.Clear();
m_BuildProfileInspectorElement.Add(buildProfileEditor.CreateLegacyGUI());
m_SelectionHeader.Hide();
m_SelectionFooter.Hide();
}
/// <summary>
/// Selects the build profile in the custom profile list view.
/// </summary>
internal void OnBuildProfileCreated(BuildProfile profile)
{
// Clearing the selection is necessary to force repaint of the profile editor
// in a case when the newly created profiles' index matches the index of the old selected profile.
m_BuildProfileSelection.ClearListViewSelection(ListViewSelectionType.Custom);
var index = m_BuildProfileDataSource.customBuildProfiles.IndexOf(profile);
if (index < 0)
return;
m_BuildProfileSelection.visualElement.SelectBuildProfile(index);
}
/// <summary>
/// Duplicates and selects the current classic platform profile.
/// </summary>
internal void DuplicateSelectedClassicProfile()
{
m_BuildProfileContextMenu.HandleDuplicateSelectedProfiles(true);
}
/// <summary>
/// Repaints the list views and clears the selection.
/// </summary>
internal void RepaintAndClearSelection()
{
RebuildProfileListViews();
// Clearing the selection forces the ListView.selectionChanged event to trigger.
// This is necessary because if the selection index remains the same after deletion,
// the selectionChanged event will not be called. This ensures that the build profile
// inspector is updated accordingly.
m_BuildProfileSelection.ClearListViewSelection(ListViewSelectionType.Custom);
m_ProfileListViews.SelectActiveProfile();
}
/// <summary>
/// Creates a <see cref="BuildProfileListEditableLabel"/> with the current
/// <see cref="m_BuildProfileContextMenu"/>.
/// </summary>
internal BuildProfileListEditableLabel CreateEditableLabelItem() => new BuildProfileListEditableLabel(
(object buildProfileObject, string buildProfileLabelName) =>
{
bool isUpdated = m_BuildProfileContextMenu.UpdateBuildProfileLabelName(buildProfileObject, buildProfileLabelName);
if (isUpdated)
{
// The same path is used to force a repaint of the profile editor
OnBuildProfileCreated(buildProfileObject as BuildProfile);
}
return isUpdated;
},
m_BuildProfileContextMenu.AddBuildProfileContextMenu());
/// <summary>
/// Rebuild the custom profile list view, or show the welcome message if no custom
/// profiles exist.
/// </summary>
internal void RebuildProfileListViews()
{
if (m_BuildProfileDataSource.customBuildProfiles.Count == 0)
{
m_ProfileListViews.HideCustomBuildProfiles();
m_WelcomeMessageElement.Show();
}
else
{
m_ProfileListViews.ShowCustomBuildProfiles();
m_WelcomeMessageElement.Hide();
}
m_ProfileListViews.Rebuild();
}
/// <summary>
/// Sticky editor visual elements above inspector window.
/// </summary>
internal void AppendInspectorHeaderElement(VisualElement element)
{
m_BuildProfileInspectorHeaderElement.Add(element);
}
internal void RepaintBuildProfileInspector()
{
if (!m_BuildProfileSelection.IsSingleSelection())
return;
RebuildBuildProfileEditor(m_BuildProfileSelection.Get(0));
}
void Update()
{
// We need to detect when a build profile asset that is selected in inspector
// gets deleted. Since we want to avoid using asset post processors for performance
// reason, we check it in update
if (buildProfileEditor != null &&
buildProfileEditor.buildProfile == null &&
m_BuildProfileSelection?.IsSingleSelection() == true)
{
DestroyImmediate(buildProfileEditor);
m_BuildProfileDataSource?.DeleteNullProfiles();
RepaintAndClearSelection();
}
}
/// <summary>
/// Build Profile Workflow state change callback. Invoked when <see cref="m_WindowState"/> is refreshed
/// by this class or changes are attempted by an embedded <see cref="BuildProfileEditor"/>.
/// </summary>
/// <param name="next"></param>
void OnWorkflowStateChanged(BuildProfileWorkflowState next)
{
if (next == m_WindowState && buildProfileEditor is not null)
{
// When refreshing the window state, if there's a build profile selected
// then the corresponding editor state should be considered.
next = buildProfileEditor.editorState;
}
ReduceWindowState(m_WindowState, next);
}
void ReduceWindowState(BuildProfileWorkflowState parent, BuildProfileWorkflowState child)
{
// For conflict resolution between the parent window and a child state being applied:
// - false booleans take precedence
// - ActionState values take priority in decreasing order: Hidden > Disabled > Enabled
m_ShouldAskForBuildLocation = parent.askForBuildLocation && child.askForBuildLocation;
m_ActivateButton.ApplyActionState(BuildProfileWorkflowState.CalculateActionState(
parent.activateAction, child.activateAction));
m_BuildButton.ApplyActionState(BuildProfileWorkflowState.CalculateActionState(
parent.buildAction, child.buildAction));
m_BuildAndRunButton.ApplyActionState(BuildProfileWorkflowState.CalculateActionState(
parent.buildAndRunAction, child.buildAndRunAction));
m_BuildInCloudPackageButton.ApplyActionState(BuildProfileWorkflowState.CalculateActionState(
parent.buildInCloudPackageAction, child.buildInCloudPackageAction));
m_BuildAndRunButton.text = child.buildAndRunButtonDisplayName;
m_BuildButton.SetText(child.buildButtonDisplayName);
// Additional actions are always directly applied to the parent window state.
if (parent.additionalActions == child.additionalActions)
return;
parent.additionalActions = child.additionalActions;
RepaintAdditionActionsDropdown();
}
void RepaintAdditionActionsDropdown()
{
if (m_WindowState.buildAction == ActionState.Hidden || m_WindowState.additionalActions.Count == 0)
{
m_AdditionalActionsDropdown.Hide();
return;
}
// Dropdown button default text matches the first enabled action in the list,
// otherwise defaults to the first action.
var actions = m_WindowState.additionalActions;
GenericMenu menu = null;
int firstEnabledIndex = -1;
if (actions.Count > 1)
{
menu = new GenericMenu();
for (int i = 0; i < actions.Count; i++)
{
var action = actions[i];
if (action.state != ActionState.Enabled)
continue;
if (firstEnabledIndex < 0)
firstEnabledIndex = i;
else
menu.AddItem(new GUIContent(action.displayName), action.isOn, () => action.callback());
}
}
firstEnabledIndex = Math.Max(firstEnabledIndex, 0);
var dropdown = new DropdownButton(
actions[firstEnabledIndex].displayName, actions[firstEnabledIndex].callback, menu);
if (actions[firstEnabledIndex].state != ActionState.Enabled)
dropdown.SetEnabled(false);
m_AdditionalActionsDropdown.Clear();
m_AdditionalActionsDropdown.Add(dropdown);
m_AdditionalActionsDropdown.Show();
}
void OnActivateButtonClicked()
{
if (!m_BuildProfileSelection.HasSelection())
return;
BuildProfile activateProfile = m_BuildProfileSelection.Get(0);
if (activateProfile.IsActiveBuildProfileOrPlatform())
return;
// before we update the BuildProfileContext's activeProfile,
// we want to capture the current active profile to check if an editor restart is required
// because certain player settings changed that will require it
var currentBuildProfile = BuildProfileContext.activeProfile;
// success here is handling the player settings, failure is the user cancels handling the restart.
var isSuccess = BuildProfileModuleUtil.HandlePlayerSettingsChanged(currentBuildProfile, activateProfile);
if (!isSuccess)
return;
// Classic profiles should not be set as active, they are identified
// by the state of EditorUserBuildSettings active build target.
BuildProfileContext.activeProfile = !BuildProfileContext.IsClassicPlatformProfile(activateProfile)
? activateProfile : null;
BuildProfileModuleUtil.InstallRequiredPackagesForClassicProfileIfRequired(activateProfile,
(string platformName, string packages) =>
{
return EditorUtility.DisplayDialog(
string.Format(TrText.packageInstallationQueryTitle, platformName),
string.Format(TrText.packageInstallationQueryMessage, platformName, packages),
TrText.packageInstallationQueryYes, TrText.packageInstallationQueryNo);
});
buildProfileEditor.OnActivateClicked();
BuildProfileModuleUtil.SwitchLegacyActiveFromBuildProfile(activateProfile);
UpdateFormButtonState(activateProfile);
RebuildProfileListViews();
UpdateToolbarButtonState();
}
void OnBuildButtonClicked(BuildOptions optionFlags)
{
if (!m_BuildProfileSelection.HasSelection())
return;
var profile = m_BuildProfileSelection.Get(0);
if (!profile.IsActiveBuildProfileOrPlatform())
{
Debug.LogWarning("[BuildProfile] Attempted to build with a non-active build profile.");
return;
}
BuildProfileModuleUtil.SwitchLegacySelectedBuildTargets(profile);
EditorApplication.delayCall += () => BuildProfileModuleUtil.CallInternalBuildMethods(m_ShouldAskForBuildLocation, optionFlags);
}
void UpdateFormButtonState(BuildProfile profile)
{
if (profile is null)
{
m_WindowState.activateAction = ActionState.Hidden;
m_WindowState.buildAction = ActionState.Hidden;
m_WindowState.buildAndRunAction = ActionState.Hidden;
m_WindowState.buildInCloudPackageAction = ActionState.Hidden;
m_WindowState.Refresh();
}
else if (profile.IsActiveBuildProfileOrPlatform())
{
m_WindowState.activateAction = ActionState.Hidden;
m_WindowState.buildAction = ActionState.Enabled;
m_WindowState.buildAndRunAction = ActionState.Enabled;
m_WindowState.buildInCloudPackageAction = BuildProfileContext.IsClassicPlatformProfile(profile) ? ActionState.Hidden : ActionState.Enabled;
m_WindowState.Refresh();
}
else
{
bool canBuild = profile.CanBuildLocally();
m_WindowState.activateAction = canBuild ? ActionState.Enabled : ActionState.Hidden;
m_WindowState.buildAction = canBuild ? ActionState.Disabled : ActionState.Hidden;
m_WindowState.buildAndRunAction = ActionState.Hidden;
m_WindowState.buildInCloudPackageAction = BuildProfileContext.IsClassicPlatformProfile(profile) ? ActionState.Hidden : ActionState.Enabled;
m_WindowState.Refresh();
}
}
/// <summary>
/// Callback invoked when <see cref="BuildProfileContext.activeProfile"/> changes.
/// </summary>
void OnActiveProfileChanged(BuildProfile prev, BuildProfile cur)
{
// Delete null build profile before rebuilding ProfileListView.
m_BuildProfileDataSource?.DeleteNullProfiles();
RebuildProfileListViews();
UpdateFormButtonState(m_BuildProfileSelection.Get(0));
}
/// <summary>
/// Cloud Build callback defers to Cloud Build package workflow.
/// </summary>
void OnCloudBuildClicked()
{
var profile = m_BuildProfileSelection.Get(0);
if (profile == null)
return;
BuildAutomationModalWindow.OnCloudBuildClicked(profile, this);
}
/// <summary>
/// Callback invoked when the active build target changes.
/// </summary>
void OnActiveBuildTargetChanged(BuildTarget prev, BuildTarget cur)
{
m_ProfileListViews.Rebuild();
UpdateFormButtonState(m_BuildProfileSelection.Get(0));
}
void RebuildBuildProfileEditor(BuildProfile profile)
{
// Rebuild the BuildProfile inspector, targeting the newly selected BuildProfile.
DestroyImmediate(buildProfileEditor);
buildProfileEditor = (BuildProfileEditor)Editor.CreateEditor(profile, typeof(BuildProfileEditor));
buildProfileEditor.parentState = m_WindowState;
buildProfileEditor.parent = this;
m_BuildProfileInspectorElement.Clear();
m_BuildProfileInspectorHeaderElement.Clear();
m_BuildProfileInspectorElement.Add(buildProfileEditor.CreateInspectorGUI());
// Builds can only be made for an active BuildProfile,
// otherwise allow activating the selected profile.
UpdateFormButtonState(profile);
// Editor User Build Settings track 'selected' build target group.
// This was used by different UX to update default build target group tabs
// based on legacy Build Setting window state.
BuildProfileModuleUtil.SwitchLegacySelectedBuildTargets(profile);
}
void SendWorkflowReport()
{
if (m_BuildProfileDataSource == null)
return;
if (m_BuildProfileDataSource.customBuildProfiles.Count == 0)
{
EditorAnalytics.SendAnalytic(new BuildProfileWorkflowReport());
return;
}
Dictionary<GUID, BuildProfileWorkflowReport> modules = new();
foreach (var profile in m_BuildProfileDataSource.customBuildProfiles)
{
if (modules.TryGetValue(profile.platformGuid, out var report))
{
report.Increment();
continue;
}
modules.Add(profile.platformGuid,
new BuildProfileWorkflowReport(new BuildProfileWorkflowReport.Payload()
{
platformId = profile.platformGuid.ToString(),
platformDisplayName = BuildProfileModuleUtil.GetClassicPlatformDisplayName(profile.platformGuid),
count = 1
}));
}
foreach (var report in modules.Values)
{
EditorAnalytics.SendAnalytic(report);
}
}
DropdownButton CreateBuildDropdownButton()
{
GenericMenu menu = new GenericMenu();
menu.AddItem(new GUIContent(TrText.cleanBuild), false,
() => OnBuildButtonClicked(BuildOptions.ShowBuiltPlayer | BuildOptions.CleanBuildCache));
menu.AddItem(new GUIContent(TrText.forceSkipDataBuild), false,
() => OnBuildButtonClicked(BuildOptions.ShowBuiltPlayer | BuildOptions.BuildScriptsOnly));
return new DropdownButton(TrText.build,
() => OnBuildButtonClicked(BuildOptions.ShowBuiltPlayer), menu);
}
void UpdateToolbarButtonState()
{
if (m_AssetImportButton == null)
return;
TryLoadWarningIcon();
m_AssetImportButton.tooltip = AssetImportOverridesWindow.IsAssetImportOverrideEnabled ? TrText.assetImportOverrideTooltip : string.Empty;
m_AssetImportButton.iconImage = AssetImportOverridesWindow.IsAssetImportOverrideEnabled ? m_WarningIcon : null;
m_AssetImportButton.text = AssetImportOverridesWindow.IsAssetImportOverrideEnabled ? $" {TrText.assetImportOverrides}" : TrText.assetImportOverrides;
}
void TryLoadWarningIcon()
{
if (m_WarningIcon == null)
m_WarningIcon = Background.FromTexture2D(BuildProfileModuleUtil.GetWarningIcon());
}
}
}