make PatchUploader selector more friendly

This commit is contained in:
ALIENJACK\alien 2025-08-08 17:23:29 +08:00
parent 92302eb3d9
commit 88135a2dc6
4 changed files with 40 additions and 6 deletions

View File

@ -95,8 +95,11 @@ namespace VersionFlow.Editors
var uploaderTypes = builder.GetAllPatcherType(); var uploaderTypes = builder.GetAllPatcherType();
var options = uploaderTypes.Select(t => $"{t.Namespace}.{t.Name}").ToList(); var options = uploaderTypes.Select(t => $"{t.Namespace}.{t.Name}").ToList();
var selectIndex = options.IndexOf(builder.uploaderClassName); var selectIndex = options.IndexOf(builder.uploaderClassName);
selectIndex = EditorGUILayout.Popup("选择上传器", selectIndex, options.ToArray());
selectIndex = EditorGUILayout.Popup("选择上传器", selectIndex, options.Select(op=>PatchUploaderUtility.GetPatcherPrettyName(op)).ToArray());
if (selectIndex != -1) if (selectIndex != -1)
{ {
var selectClassName = options[selectIndex]; var selectClassName = options[selectIndex];
@ -104,9 +107,13 @@ namespace VersionFlow.Editors
} }
var patchLoader = builder.GetPatchLoader(); var patchLoader = builder.GetPatchLoader();
Editor.CreateEditor(patchLoader).OnInspectorGUI(); if (patchLoader != null)
string json = patchLoader.GetCfgJson(); {
builder.uploaderCfgJson = json; Editor.CreateEditor(patchLoader).OnInspectorGUI();
string json = patchLoader.GetCfgJson();
builder.uploaderCfgJson = json;
}
if (GUI.changed) if (GUI.changed)
{ {
EditorUtility.SetDirty(target); EditorUtility.SetDirty(target);

View File

@ -3,6 +3,7 @@ using AlibabaCloud.SDK.Cdn20180510.Models;
using Aliyun.OSS; using Aliyun.OSS;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.ComponentModel;
using System.IO; using System.IO;
using System.Linq; using System.Linq;
using System.Text; using System.Text;
@ -13,7 +14,8 @@ using static VersionFlow.Editors.ICDNPerformer;
namespace VersionFlow.Editors namespace VersionFlow.Editors
{ {
public class Patchloader_AliOSS : PatchUploader<Patchloader_AliOSS.Config>, ICDNPerformer [Description("阿里云OSS")]
public class PatchUpLoader_AliOSS : PatchUploader<PatchUpLoader_AliOSS.Config>, ICDNPerformer
{ {
private OssClient m_ossClient; private OssClient m_ossClient;
private Client m_cdnClient; private Client m_cdnClient;

View File

@ -1,5 +1,6 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.ComponentModel;
using System.Reflection; using System.Reflection;
using UnityEditor; using UnityEditor;
using VersionFlow.Runtime; using VersionFlow.Runtime;
@ -10,13 +11,14 @@ namespace VersionFlow.Editors
{ {
static Dictionary<BuilderConfig, PatchUploader> s_patchInstance = new Dictionary<BuilderConfig, PatchUploader>(); static Dictionary<BuilderConfig, PatchUploader> s_patchInstance = new Dictionary<BuilderConfig, PatchUploader>();
static Dictionary<string, Type> s_patchloaderTypesMapper; static Dictionary<string, Type> s_patchloaderTypesMapper;
static Dictionary<Type, string> s_patcherPrettyNameMapper;
static void PreparePatcherTypes() static void PreparePatcherTypes()
{ {
if (s_patchloaderTypesMapper != null) return; if (s_patchloaderTypesMapper != null) return;
s_patchloaderTypesMapper = new Dictionary<string, Type>(); s_patchloaderTypesMapper = new Dictionary<string, Type>();
s_patcherPrettyNameMapper = new Dictionary<Type, string>();
foreach (var assembly in AppDomain.CurrentDomain.GetAssemblies()) foreach (var assembly in AppDomain.CurrentDomain.GetAssemblies())
{ {
if (assembly.IsDynamic) continue; if (assembly.IsDynamic) continue;
@ -26,6 +28,14 @@ namespace VersionFlow.Editors
if (!typeof(PatchUploader).IsAssignableFrom(type)) continue; if (!typeof(PatchUploader).IsAssignableFrom(type)) continue;
s_patchloaderTypesMapper[type.FullName] = type; s_patchloaderTypesMapper[type.FullName] = type;
if (type.GetCustomAttribute<DescriptionAttribute>() is DescriptionAttribute desAtt)
{
s_patcherPrettyNameMapper[type] = desAtt.Description;
}
else
{
s_patcherPrettyNameMapper[type] = $"{type.Namespace}.{type.Name}";
}
} }
} }
} }
@ -36,6 +46,21 @@ namespace VersionFlow.Editors
return s_patchloaderTypesMapper.Values; return s_patchloaderTypesMapper.Values;
} }
public static Type GetPatcherType(string className)
{
s_patchloaderTypesMapper.TryGetValue(className, out var type);
return type;
}
public static string GetPatcherPrettyName(string className)
{
s_patcherPrettyNameMapper.TryGetValue(GetPatcherType(className), out var prettyName);
return prettyName;
}
public static string GetPatcherPrettyName(Type patcherType)
{
s_patcherPrettyNameMapper.TryGetValue(patcherType, out var prettyName);
return prettyName;
}
public static PatchUploader GetPatchLoader(this BuilderConfig builder) public static PatchUploader GetPatchLoader(this BuilderConfig builder)
{ {