-
Notifications
You must be signed in to change notification settings - Fork 341
Expand file tree
/
Copy pathBootstrapEditorUI.cs
More file actions
451 lines (381 loc) · 18.7 KB
/
BootstrapEditorUI.cs
File metadata and controls
451 lines (381 loc) · 18.7 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
// BootstrapEditorUI.cs
//
// Author:
// JasonXuDeveloper <jason@xgamedev.net>
//
// Copyright (c) 2025 JEngine
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
using System;
using System.Collections.Generic;
using JEngine.Core;
using JEngine.Core.Editor;
using JEngine.Core.Encrypt;
using JEngine.Core.Update;
using JEngine.UI.Editor.Components.Button;
using JEngine.UI.Editor.Components.Form;
using JEngine.UI.Editor.Components.Layout;
using JEngine.UI.Editor.Theming;
using JEngine.UI.Editor.Utilities;
using TMPro;
using UnityEditor;
using UnityEngine;
using UnityEngine.UIElements;
using Button = UnityEngine.UI.Button;
using Slider = UnityEngine.UI.Slider;
namespace JEngine.UI.Editor.Internal
{
/// <summary>
/// Enhanced Bootstrap inspector UI using JEngine UI components.
/// </summary>
internal static class BootstrapEditorUI
{
private static SerializedObject _serializedObject;
private static Bootstrap _bootstrap;
private static VisualElement _fallbackContainer;
private static VisualElement _currentRoot;
/// <summary>
/// Creates the enhanced Bootstrap inspector.
/// </summary>
public static VisualElement CreateInspector(SerializedObject serializedObject, Bootstrap bootstrap)
{
_serializedObject = serializedObject;
_bootstrap = bootstrap;
// Unregister previous undo callback if exists
Undo.undoRedoPerformed -= OnUndoRedo;
var root = new VisualElement();
_currentRoot = root;
// Apply stylesheets
StyleSheetManager.ApplyAllStyleSheets(root);
// Apply padding only (no background for inspector)
root.style.paddingTop = Tokens.Spacing.MD;
root.style.paddingLeft = Tokens.Spacing.MD;
root.style.paddingRight = Tokens.Spacing.MD;
root.style.paddingBottom = Tokens.Spacing.MD;
// Centered container for compact inspector layout
var container = new JContainer(ContainerSize.Xs);
var content = new JStack(GapSize.Sm);
// Header
content.Add(CreateHeader());
#if UNITY_EDITOR
// Development Settings
content.Add(CreateDevelopmentSettingsSection());
#endif
// Server Settings
content.Add(CreateServerSettingsSection());
// Asset Settings
content.Add(CreateAssetSettingsSection());
// Security Settings
content.Add(CreateSecuritySettingsSection());
// UI Settings
content.Add(CreateUISettingsSection());
container.Add(content);
root.Add(container);
// Register undo/redo callback
Undo.undoRedoPerformed += OnUndoRedo;
// Cleanup callback when element is detached (no closure)
root.RegisterCallback<DetachFromPanelEvent, Undo.UndoRedoCallback>(OnDetachFromPanel, OnUndoRedo);
return root;
}
/// <summary>
/// Called when element is detached from panel. Cleanup callback.
/// </summary>
private static void OnDetachFromPanel(DetachFromPanelEvent evt, Undo.UndoRedoCallback undoCallback)
{
Undo.undoRedoPerformed -= undoCallback;
}
/// <summary>
/// Called when undo/redo is performed. Rebuilds the inspector UI.
/// </summary>
private static void OnUndoRedo()
{
if (_currentRoot == null || _serializedObject == null || _bootstrap == null)
return;
// Update serialized object to reflect undo/redo changes
_serializedObject.Update();
// Rebuild the entire UI
_currentRoot.Clear();
// Centered container for compact inspector layout
var container = new JContainer(ContainerSize.Xs);
// Recreate content
var content = new JStack(GapSize.Sm);
content.Add(CreateHeader());
#if UNITY_EDITOR
content.Add(CreateDevelopmentSettingsSection());
#endif
content.Add(CreateServerSettingsSection());
content.Add(CreateAssetSettingsSection());
content.Add(CreateSecuritySettingsSection());
content.Add(CreateUISettingsSection());
container.Add(content);
_currentRoot.Add(container);
}
private static VisualElement CreateHeader()
{
var header = new VisualElement();
header.style.marginBottom = Tokens.Spacing.Xl;
header.style.paddingBottom = Tokens.Spacing.MD;
header.style.borderBottomWidth = 1;
header.style.borderBottomColor = Tokens.Colors.BorderSubtle;
var title = new Label("Bootstrap Configuration");
title.style.fontSize = Tokens.FontSize.Title;
title.style.color = Tokens.Colors.TextHeader;
title.style.unityFontStyleAndWeight = FontStyle.Bold;
title.style.marginBottom = Tokens.Spacing.Xs;
var subtitle = new Label("Configure JEngine hot update bootstrap settings");
subtitle.style.fontSize = Tokens.FontSize.Base;
subtitle.style.color = Tokens.Colors.TextMuted;
header.Add(title);
header.Add(subtitle);
return header;
}
#if UNITY_EDITOR
private static VisualElement CreateDevelopmentSettingsSection()
{
var section = new JSection("Development Settings");
var playModeButton = new JToggleButton(
"Editor Dev Mode",
"Host Play Mode",
_bootstrap.useEditorDevMode,
ButtonVariant.Primary, // Active state uses Primary
ButtonVariant.Secondary, // Inactive state uses Secondary
value =>
{
_bootstrap.useEditorDevMode = value;
_serializedObject.FindProperty(nameof(_bootstrap.useEditorDevMode)).boolValue = value;
EditorUtility.SetDirty(_bootstrap);
_serializedObject.ApplyModifiedProperties();
}
).FullWidth();
section.Add(new JFormField("Editor Mode", playModeButton));
return section;
}
#endif
private static VisualElement CreateServerSettingsSection()
{
var section = new JSection("Server Settings");
// Default Host Server
var defaultHostField = new JTextField();
defaultHostField.BindProperty(_serializedObject.FindProperty(nameof(_bootstrap.defaultHostServer)));
section.Add(new JFormField("Host Server", defaultHostField));
// Fallback Mode Toggle
var fallbackToggle = new JToggleButton(
"Using Default Server as Fallback",
"Using Custom Server as Fallback",
_bootstrap.useDefaultAsFallback,
ButtonVariant.Primary, // Active state uses Primary
ButtonVariant.Secondary, // Inactive state uses Secondary
value =>
{
_bootstrap.useDefaultAsFallback = value;
_serializedObject.FindProperty(nameof(_bootstrap.useDefaultAsFallback)).boolValue = value;
EditorUtility.SetDirty(_bootstrap);
_serializedObject.ApplyModifiedProperties();
UpdateFallbackVisibility();
}
);
section.Add(new JFormField("Fallback Mode", fallbackToggle));
// Custom Fallback Server (conditionally visible)
_fallbackContainer = new VisualElement();
var fallbackField = new JTextField();
fallbackField.BindProperty(_serializedObject.FindProperty(nameof(_bootstrap.fallbackHostServer)));
_fallbackContainer.Add(new JFormField("Fallback Server", fallbackField));
section.Add(_fallbackContainer);
// Append Time Ticks Toggle
var appendTimeTicksToggle = new JToggle(_bootstrap.appendTimeTicks);
appendTimeTicksToggle.tooltip = "Append time ticks to resource URLs to prevent caching";
appendTimeTicksToggle.OnValueChanged(value =>
{
_bootstrap.appendTimeTicks = value;
_serializedObject.FindProperty(nameof(_bootstrap.appendTimeTicks)).boolValue = value;
EditorUtility.SetDirty(_bootstrap);
_serializedObject.ApplyModifiedProperties();
});
section.Add(new JFormField("Append Time Ticks", appendTimeTicksToggle));
UpdateFallbackVisibility();
return section;
}
private static VisualElement CreateAssetSettingsSection()
{
var section = new JSection("Asset Settings");
// Target Platform
var targetPlatformField = JDropdown<TargetPlatform>.ForEnum(_bootstrap.targetPlatform);
targetPlatformField.OnValueChanged(value =>
{
var enumProperty = _serializedObject.FindProperty(nameof(_bootstrap.targetPlatform));
enumProperty.enumValueIndex = Array.IndexOf(Enum.GetValues(typeof(TargetPlatform)), value);
_serializedObject.ApplyModifiedProperties();
});
section.Add(new JFormField("Platform", targetPlatformField));
// Package Name
var packageChoices = EditorUtils.GetAvailableYooAssetPackages();
var packageNameField = new JDropdown(
packageChoices.Count > 0 ? packageChoices : new List<string> { _bootstrap.packageName },
_bootstrap.packageName
);
packageNameField.OnValueChanged(value =>
{
_serializedObject.FindProperty(nameof(_bootstrap.packageName)).stringValue = value;
_serializedObject.ApplyModifiedProperties();
});
section.Add(new JFormField("Package", packageNameField));
// Hot Code Assembly
var hotCodeChoices = EditorUtils.GetAvailableAsmdefFiles();
var hotCodeField = new JDropdown(
hotCodeChoices.Count > 0 ? hotCodeChoices : new List<string> { _bootstrap.hotCodeName },
_bootstrap.hotCodeName
);
hotCodeField.OnValueChanged(value =>
{
_serializedObject.FindProperty(nameof(_bootstrap.hotCodeName)).stringValue = value;
_serializedObject.ApplyModifiedProperties();
});
section.Add(new JFormField("Code Assembly", hotCodeField));
// Hot Scene
var hotSceneChoices = EditorUtils.GetAvailableHotScenes();
var hotSceneField = new JDropdown(
hotSceneChoices.Count > 0 ? hotSceneChoices : new List<string> { _bootstrap.selectedHotScene },
_bootstrap.selectedHotScene
);
hotSceneField.OnValueChanged(value =>
{
_serializedObject.FindProperty(nameof(_bootstrap.selectedHotScene)).stringValue = value;
_serializedObject.ApplyModifiedProperties();
});
section.Add(new JFormField("Scene", hotSceneField));
// Hot Update Entry Class
var hotClassChoices = EditorUtils.GetAvailableHotClasses(_bootstrap.hotCodeName);
var hotClassField = new JDropdown(
hotClassChoices.Count > 0 ? hotClassChoices : new List<string> { _bootstrap.hotUpdateClassName },
_bootstrap.hotUpdateClassName
);
hotClassField.OnValueChanged(value =>
{
_serializedObject.FindProperty(nameof(_bootstrap.hotUpdateClassName)).stringValue = value;
_serializedObject.ApplyModifiedProperties();
});
section.Add(new JFormField("Entry Class", hotClassField));
// Hot Update Entry Method
var hotMethodChoices = EditorUtils.GetAvailableHotMethods(_bootstrap.hotCodeName, _bootstrap.hotUpdateClassName);
var hotMethodField = new JDropdown(
hotMethodChoices.Count > 0 ? hotMethodChoices : new List<string> { _bootstrap.hotUpdateMethodName },
_bootstrap.hotUpdateMethodName
);
hotMethodField.OnValueChanged(value =>
{
_serializedObject.FindProperty(nameof(_bootstrap.hotUpdateMethodName)).stringValue = value;
_serializedObject.ApplyModifiedProperties();
});
section.Add(new JFormField("Entry Method", hotMethodField));
// AOT DLL List File
var aotChoices = EditorUtils.GetAvailableAOTDataFiles();
var aotField = new JDropdown(
aotChoices.Count > 0 ? aotChoices : new List<string> { _bootstrap.aotDllListFilePath },
_bootstrap.aotDllListFilePath
);
aotField.OnValueChanged(value =>
{
_serializedObject.FindProperty(nameof(_bootstrap.aotDllListFilePath)).stringValue = value;
_serializedObject.ApplyModifiedProperties();
});
section.Add(new JFormField("AOT DLL List", aotField));
return section;
}
private static VisualElement CreateSecuritySettingsSection()
{
var section = new JSection("Security Settings");
// Dynamic Secret Key
var dynamicKeyChoices = EditorUtils.GetAvailableDynamicSecretKeys();
var dynamicKeyField = new JDropdown(
dynamicKeyChoices.Count > 0 ? dynamicKeyChoices : new List<string> { _bootstrap.dynamicSecretKeyPath },
_bootstrap.dynamicSecretKeyPath
);
dynamicKeyField.OnValueChanged(value =>
{
_serializedObject.FindProperty(nameof(_bootstrap.dynamicSecretKeyPath)).stringValue = value;
_serializedObject.ApplyModifiedProperties();
});
section.Add(new JFormField("Secret Key", dynamicKeyField));
// Encryption Option
var bundleConfig = EncryptionMapping.GetBundleConfig(_bootstrap.encryptionOption);
var encryptionField = JDropdown<EncryptionOption>.ForEnum(_bootstrap.encryptionOption);
var manifestConfigField = new JObjectField<ScriptableObject>(false);
manifestConfigField.Value = bundleConfig.ManifestConfigScriptableObject;
manifestConfigField.RegisterValueChangedCallback(_ =>
{
var config = EncryptionMapping.GetBundleConfig(_bootstrap.encryptionOption);
manifestConfigField.Value = config.ManifestConfigScriptableObject;
});
var bundleConfigField = new JObjectField<ScriptableObject>(false);
bundleConfigField.Value = bundleConfig.BundleConfigScriptableObject;
bundleConfigField.RegisterValueChangedCallback(_ =>
{
var config = EncryptionMapping.GetBundleConfig(_bootstrap.encryptionOption);
bundleConfigField.Value = config.BundleConfigScriptableObject;
});
encryptionField.OnValueChanged(value =>
{
var enumProperty = _serializedObject.FindProperty(nameof(_bootstrap.encryptionOption));
enumProperty.enumValueIndex = Array.IndexOf(Enum.GetValues(typeof(EncryptionOption)), value);
_serializedObject.ApplyModifiedProperties();
var newConfig = EncryptionMapping.GetBundleConfig(value);
manifestConfigField.Value = newConfig.ManifestConfigScriptableObject;
bundleConfigField.Value = newConfig.BundleConfigScriptableObject;
});
section.Add(new JFormField("Encryption", encryptionField));
section.Add(new JFormField("Manifest Config", manifestConfigField));
section.Add(new JFormField("Bundle Config", bundleConfigField));
return section;
}
private static VisualElement CreateUISettingsSection()
{
var section = new JSection("UI Settings");
// Version Text
var versionField = new JObjectField<TextMeshProUGUI>();
versionField.BindProperty(_serializedObject.FindProperty(nameof(_bootstrap.versionText)));
section.Add(new JFormField("Version Text", versionField));
// Update Status Text
var statusField = new JObjectField<TextMeshProUGUI>();
statusField.BindProperty(_serializedObject.FindProperty(nameof(_bootstrap.updateStatusText)));
section.Add(new JFormField("Update Status Text", statusField));
// Download Progress Text
var progressTextField = new JObjectField<TextMeshProUGUI>();
progressTextField.BindProperty(_serializedObject.FindProperty(nameof(_bootstrap.downloadProgressText)));
section.Add(new JFormField("Progress Text", progressTextField));
// Download Progress Bar
var progressBarField = new JObjectField<Slider>();
progressBarField.BindProperty(_serializedObject.FindProperty(nameof(_bootstrap.downloadProgressBar)));
section.Add(new JFormField("Progress Bar", progressBarField));
// Start Button
var startButtonField = new JObjectField<Button>();
startButtonField.BindProperty(_serializedObject.FindProperty(nameof(_bootstrap.startButton)));
section.Add(new JFormField("Start Button", startButtonField));
return section;
}
private static void UpdateFallbackVisibility()
{
if (_fallbackContainer != null)
{
_fallbackContainer.style.display = _bootstrap.useDefaultAsFallback
? DisplayStyle.None
: DisplayStyle.Flex;
}
}
}
}