From b997f8266e329852f17c6195ba2ebea267851ef1 Mon Sep 17 00:00:00 2001 From: "ALIENJACK\\alien" Date: Tue, 12 Aug 2025 18:25:57 +0800 Subject: [PATCH] =?UTF-8?q?=E9=9A=8F=E5=8C=85=E8=B5=84=E6=BA=90=E7=AE=A1?= =?UTF-8?q?=E7=90=86=E7=AA=97=E5=8F=A3=E6=B7=BB=E5=8A=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../VersionFlow/Editor/SetupInstallBundle.cs | 104 ++++++++++++++++++ .../Editor/SetupInstallBundle.cs.meta | 11 ++ 2 files changed, 115 insertions(+) create mode 100644 Assets/VersionFlow/Editor/SetupInstallBundle.cs create mode 100644 Assets/VersionFlow/Editor/SetupInstallBundle.cs.meta diff --git a/Assets/VersionFlow/Editor/SetupInstallBundle.cs b/Assets/VersionFlow/Editor/SetupInstallBundle.cs new file mode 100644 index 0000000..523ce65 --- /dev/null +++ b/Assets/VersionFlow/Editor/SetupInstallBundle.cs @@ -0,0 +1,104 @@ +using System; +using System.Collections.Generic; +using System.IO; +using UnityEditor; +using UnityEngine; +using VersionFlow.Runtime; + +namespace VersionFlow.Editors +{ + public class SetupInstallBundle : EditorWindow + { + Dictionary> fetchBundles = new Dictionary>(); + HashSet selectBundles = new HashSet(); + + [MenuItem("VersionFlow/设置随包资源")] + public static void Open() + { + EditorWindow.GetWindow().Show(); + } + + void OnGUI() + { + if (GUILayout.Button("拉取资源清单")) + { + FetchRemoteManifest(); + } + + DrawBundleGroup(); + } + + private void DrawBundleGroup() + { + foreach (var item in fetchBundles) + { + EditorGUILayout.LabelField($"{item.Key}", new GUIStyle(EditorStyles.largeLabel)); + EditorGUILayout.BeginVertical(EditorStyles.helpBox); + { + foreach (var bundle in item.Value) + DrawBundleItem(bundle); + } + EditorGUILayout.EndVertical(); + } + } + + private void DrawBundleItem(Bundle bundle) + { + using (new EditorGUILayout.HorizontalScope()) + { + GUILayout.Space(20); + var rect = GUILayoutUtility.GetLastRect(); + rect.height = 20; + rect.width = 20; + if (bundle.InstallBundle) + { + GUI.DrawTexture(rect, EditorGUIUtility.FindTexture("d_UnityLogo")); + } + EditorGUILayout.LabelField(bundle.BundleName, new GUIStyle(EditorStyles.boldLabel)); + var rect1 = GUILayoutUtility.GetLastRect(); + EditorGUILayout.LabelField($"{GetByteSizeString(bundle.Size)}", new GUIStyle(EditorStyles.label) { alignment = TextAnchor.MiddleRight }); + var rect2 = GUILayoutUtility.GetLastRect(); + + var clickRegionRect = new Rect(rect.x, rect.y, rect.width + rect1.width + rect2.width, rect1.height + 4); + EditorGUI.DrawRect(clickRegionRect, selectBundles.Contains(bundle) ? new Color(0, 1, 1, 0.2f) : new Color(0, 0, 0, 0)); + } + } + + private void FetchRemoteManifest() + { + fetchBundles.Clear(); + + var builder = PatchUploaderUtility.FindBuilderInProject(); + var remoteInfo = BuilderConfigEditor.FetchRemoteVersion(builder); + + foreach (var bundle in remoteInfo.remoteVersion.Bundles) + { + if (!fetchBundles.TryGetValue(bundle.Group, out List list)) + { + list = new List(); + fetchBundles[bundle.Group] = list; + + if (bundle.InstallBundle) + selectBundles.Add(bundle); + } + + list.Add(bundle); + } + } + + public static void PerformInstallBundles() + { + var builder = PatchUploaderUtility.FindBuilderInProject(); + BuilderConfigEditor.SetInstallBundles(builder, false); + } + + private static string GetByteSizeString(long byteCount) + { + if (byteCount < 1024) return $"{byteCount}B"; + + if (byteCount < 1024 * 1024) return $"{byteCount / (1024f):.00}KB"; + + else return $"{byteCount / (1024f * 1024):.00}MB"; + } + } +} \ No newline at end of file diff --git a/Assets/VersionFlow/Editor/SetupInstallBundle.cs.meta b/Assets/VersionFlow/Editor/SetupInstallBundle.cs.meta new file mode 100644 index 0000000..7f034bd --- /dev/null +++ b/Assets/VersionFlow/Editor/SetupInstallBundle.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 8a34a43d30d215c43a260ffffab68322 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: