随包资源管理窗口添加
This commit is contained in:
parent
7b39db64f8
commit
b997f8266e
104
Assets/VersionFlow/Editor/SetupInstallBundle.cs
Normal file
104
Assets/VersionFlow/Editor/SetupInstallBundle.cs
Normal file
@ -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<string, List<Bundle>> fetchBundles = new Dictionary<string, List<Bundle>>();
|
||||||
|
HashSet<Bundle> selectBundles = new HashSet<Bundle>();
|
||||||
|
|
||||||
|
[MenuItem("VersionFlow/设置随包资源")]
|
||||||
|
public static void Open()
|
||||||
|
{
|
||||||
|
EditorWindow.GetWindow<SetupInstallBundle>().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<Bundle> list))
|
||||||
|
{
|
||||||
|
list = new List<Bundle>();
|
||||||
|
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";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
11
Assets/VersionFlow/Editor/SetupInstallBundle.cs.meta
Normal file
11
Assets/VersionFlow/Editor/SetupInstallBundle.cs.meta
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: 8a34a43d30d215c43a260ffffab68322
|
||||||
|
MonoImporter:
|
||||||
|
externalObjects: {}
|
||||||
|
serializedVersion: 2
|
||||||
|
defaultReferences: []
|
||||||
|
executionOrder: 0
|
||||||
|
icon: {instanceID: 0}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
||||||
Loading…
Reference in New Issue
Block a user