-
Notifications
You must be signed in to change notification settings - Fork 2.6k
Expand file tree
/
Copy pathBuildAutomationModalWindow.cs
More file actions
143 lines (120 loc) · 5.62 KB
/
BuildAutomationModalWindow.cs
File metadata and controls
143 lines (120 loc) · 5.62 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
// Unity C# reference source
// Copyright (c) Unity Technologies. For terms of use, see
// https://unity3d.com/legal/licenses/Unity_Reference_Only_License
using UnityEngine;
using UnityEngine.UIElements;
namespace UnityEditor.Build.Profile
{
/// <summary>
/// Cloud Build button modal prompts the user to install the Build Automation package,
/// create a Build Profile, or add credentials to the selected Build Profile.
/// </summary>
internal class BuildAutomationModalWindow : EditorWindow
{
const string k_PackageId = "com.unity.services.cloud-build";
const string k_Uxml = "BuildProfile/UXML/BuildAutomationModalWindow.uxml";
static readonly string s_Label_Install = L10n.Tr("Cloud Builds require the Build Automation package. Clicking install will add the package to your project. It will also add a Build Automation section to your Build Profile so you can customize the way your Cloud Builds are run.");
static readonly string s_Label_Settings = L10n.Tr("Cloud Builds require Build Automation settings to be added to the selected Build Profile.");
static readonly string s_Button_Install = L10n.Tr("Install");
static readonly string s_Button_Settings = L10n.Tr("Add Settings");
static readonly string s_Modal_Title = L10n.Tr("Build Automation");
static readonly string s_Helpbox = L10n.Tr("Build Automation is a pay-as-you-go service provided by Unity. You can start using it for free without a credit card on file, and we will notify you when you reach the limits of the free tier.");
BuildProfileWindow m_ParentWindow;
BuildProfile m_TargetProfile;
Button m_SubmitButton;
Label m_InfoLabel;
/// <summary>
/// On Cloud Build button callback.
/// Tries to invoke UBA package callback OR displays modal
/// for cloud build integration.
/// </summary>
/// <param name="profile">Target build profile.</param>
public static void OnCloudBuildClicked(BuildProfile profile, BuildProfileWindow parentWindow)
{
if (BuildProfileContext.IsClassicPlatformProfile(profile))
{
// Classic profiles should not be invoked by Cloud Build.
return;
}
bool isInstalled = PackageManager.PackageInfo.IsPackageRegistered(k_PackageId);
bool hasCloudSettings = BuildAutomationSettingsEditor.GetSubAssetFromBuildProfile(profile) != null;
if (isInstalled && hasCloudSettings)
{
BuildAutomation.OnCloudBuildClicked(profile);
return;
}
// Show modal automating cloud build workflow integration,
// handle package installation and initial configuration object.
var window = GetWindow<BuildAutomationModalWindow>(s_Modal_Title);
window.minSize = new Vector2(600, 180);
window.maxSize = new Vector2(600, 180);
window.m_TargetProfile = profile;
window.m_ParentWindow = parentWindow;
if (!isInstalled)
{
window.SetInstallInfo();
}
else if (!hasCloudSettings)
{
window.SetAddCredentialsInfo();
}
window.ShowModal();
}
public void CreateGUI()
{
var windowUxml = EditorGUIUtility.LoadRequired(k_Uxml) as VisualTreeAsset;
var windowUss = EditorGUIUtility.LoadRequired(Util.k_StyleSheet) as StyleSheet;
rootVisualElement.styleSheets.Add(windowUss);
windowUxml.CloneTree(rootVisualElement);
m_InfoLabel = rootVisualElement.Q<Label>("uba-label");
m_SubmitButton = rootVisualElement.Q<Button>("submit-button");
var helpbox = rootVisualElement.Q<HelpBox>("uba-helpbox");
var cancel = rootVisualElement.Q<Button>("cancel-button");
helpbox.text = s_Helpbox;
cancel.text = TrText.cancelButtonText;
cancel.clicked += Close;
rootVisualElement.RegisterCallback<GeometryChangedEvent>(OnGeometryCalculated);
}
void OnGeometryCalculated(GeometryChangedEvent evt)
{
var target = (VisualElement)evt.target;
var dimensions = new Vector2(
target.resolvedStyle.width,
target.resolvedStyle.height
);
minSize = dimensions;
maxSize = dimensions;
}
void SetInstallInfo()
{
m_InfoLabel.text = s_Label_Install;
m_SubmitButton.text = s_Button_Install;
m_SubmitButton.clicked += OnInstall;
}
void SetAddCredentialsInfo()
{
m_InfoLabel.text = s_Label_Settings;
m_SubmitButton.text = s_Button_Settings;
m_SubmitButton.clicked += OnAddCredentialsObject;
}
void OnInstall()
{
var request = PackageManager.Client.Add(k_PackageId);
if (BuildAutomationSettingsEditor.GetSubAssetFromBuildProfile(m_TargetProfile) == null)
{
BuildAutomationSettingsEditor.AddBuildAutomationSettings(m_TargetProfile);
m_ParentWindow.RepaintBuildProfileInspector();
}
Close();
}
void OnAddCredentialsObject()
{
if (BuildAutomationSettingsEditor.GetSubAssetFromBuildProfile(m_TargetProfile) == null)
{
BuildAutomationSettingsEditor.AddBuildAutomationSettings(m_TargetProfile);
m_ParentWindow.RepaintBuildProfileInspector();
}
Close();
}
}
}