using Uigenx.Protocol; using UnityEditor; using UnityEngine; namespace Uigenx.Editor { public static class UgxMenu { const string Root = "Tools/UI Creator/"; [MenuItem(Root + "Connect", priority = 10)] public static void Connect() => UgxEditorBridge.Connect(); [MenuItem(Root + "Disconnect", priority = 11)] public static void Disconnect() => UgxEditorBridge.Stop(); [MenuItem(Root + "Disconnect", true)] static bool CanDisconnect() => UgxEditorBridge.State != Uigenx.Bridge.UgxBridgeState.Disconnected; /// /// Protocol v1 has no `sync.request`, so a sync is triggered by reconnecting: the daemon /// pushes the current bundle when it receives `hello`. /// [MenuItem(Root + "Sync now", priority = 30)] public static void SyncNow() { UgxEditorBridge.Disconnect(); UgxEditorBridge.Connect(); } [MenuItem(Root + "Pull data schema", priority = 31)] public static void PullDataSchema() { var result = UgxSchemaReflector.Reflect(); int fields = 0; foreach (var source in result.Sources) fields += source.Fields.Count; Debug.Log("[ugx] data schema: " + result.Sources.Count + " source(s), " + fields + " path(s). " + "Connect the bridge to send it to the studio."); } [MenuItem(Root + "Rebuild screen registry", priority = 32)] public static void RebuildRegistry() { var settings = UgxProjectSettings.Load(); if (UgxScreenRegistryBuilder.RebuildFromDisk(settings.AssetsUiFolder) != null) return; var registry = UgxScreenRegistryBuilder.Rebuild(new UgxBundleManifest(), settings.AssetsUiFolder); Debug.Log("[ugx] no manifest on disk, so " + UgxScreenRegistryBuilder.RegistryPath(settings.AssetsUiFolder) + " was created empty with " + registry.Entries.Count + " screen(s). Export from the studio."); } [MenuItem(Root + "Rebuild font assets", priority = 33)] public static void RebuildFontAssets() { var settings = UgxProjectSettings.Load(); var report = UgxFontAssetBuilder.BuildFromDisk(settings.AssetsUiFolder); foreach (var warning in report.Warnings) Debug.LogWarning("[ugx] " + warning); Debug.Log("[ugx] font assets: " + report.Created.Count + " created, " + report.Rebuilt.Count + " rebuilt, " + report.Unchanged.Count + " unchanged."); } [MenuItem(Root + "Open studio", priority = 50)] public static void OpenStudio() { var settings = UgxProjectSettings.Load(); var projectPath = settings.ResolveUicProjectPath(); var daemon = projectPath == null ? null : UgxDaemonInfo.Load(projectPath); if (daemon == null) { Debug.LogWarning("[ugx] no daemon is running, start the studio first"); return; } Application.OpenURL(daemon.ResolveUrl().Replace("ws://", "http://").Replace("wss://", "https://")); } [MenuItem(Root + "Dump theme...", priority = 70)] public static void DumpTheme() { var path = EditorUtility.SaveFilePanel("Dump UI Toolkit theme", "", "unity-theme.json", "json"); if (string.IsNullOrEmpty(path)) return; UgxThemeDumper.Dump(path); } [MenuItem(Root + "Open project settings", priority = 90)] public static void OpenSettings() => SettingsService.OpenProjectSettings(UgxSettingsProvider.Path); } }