Make Setting Wnd More pretty

This commit is contained in:
Alienjack 2025-09-03 16:55:12 +08:00
parent 5510c1f3fe
commit 3881ae8232
7 changed files with 608 additions and 469 deletions

View File

@ -126,6 +126,11 @@ namespace VersionFlow.Editors
EditorUtility.SetDirty(target); EditorUtility.SetDirty(target);
patchLoader.CfgChanged(builder, builder.UploaderCfgDict.GetUploaderCfg(patchLoader.GetType())); patchLoader.CfgChanged(builder, builder.UploaderCfgDict.GetUploaderCfg(patchLoader.GetType()));
} }
if (!patchLoader.Status)
{
EditorGUILayout.HelpBox(patchLoader.Status, MessageType.Error);
}
} }
private void DrawGroupItems() private void DrawGroupItems()

View File

@ -0,0 +1,93 @@
namespace VersionFlow.Editors
{
/// <summary>
/// String和Bool的缝合怪
/// </summary>
public struct MsgBool
{
public string ErrorMsg;
public bool Value;
public override readonly string ToString()
{
if (Value)
{
return true.ToString();
}
else
{
return ErrorMsg;
}
}
public static implicit operator MsgBool(string errorMsg)
{
return new MsgBool { Value = false, ErrorMsg = errorMsg };
}
public static implicit operator MsgBool(bool value)
{
return new MsgBool { Value = value };
}
public static implicit operator bool(MsgBool msgBool)
{
return msgBool.Value;
}
public static implicit operator (bool, string)(MsgBool msgBool)
{
return (msgBool.Value, msgBool.ErrorMsg);
}
public static implicit operator string(MsgBool msgBool)
{
return msgBool.ToString();
}
}
public struct MsgBool<T>
{
public string ErrorMsg;
public bool Value;
public T Result;
public override readonly string ToString()
{
if (Value)
{
if (Result != null) return Result.ToString();
return true.ToString();
}
else
{
return ErrorMsg;
}
}
public static implicit operator MsgBool<T>(string errorMsg)
{
return new MsgBool<T> { Value = false, ErrorMsg = errorMsg };
}
public static implicit operator MsgBool<T>(bool value)
{
return new MsgBool<T> { Value = value };
}
public static implicit operator MsgBool<T>(T result)
{
return new MsgBool<T> { Value = true, Result = result };
}
public static implicit operator bool(MsgBool<T> msgBool)
{
return msgBool.Value;
}
public static implicit operator string(MsgBool<T> msgBool)
{
return msgBool.ToString();
}
}
}

View File

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: d23328d75cc93354ea1a595833f504a2
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -7,6 +7,7 @@ namespace VersionFlow.Editors
{ {
public abstract class PatchUploader : ScriptableObject public abstract class PatchUploader : ScriptableObject
{ {
public abstract MsgBool Status { get; }
public PatchUploader() { } public PatchUploader() { }
public abstract void CfgChanged(BuilderConfig builder, string cfgJson); public abstract void CfgChanged(BuilderConfig builder, string cfgJson);
public abstract void UploadFile(string remoteFilePath, MemoryStream localfileStream); public abstract void UploadFile(string remoteFilePath, MemoryStream localfileStream);
@ -21,17 +22,20 @@ namespace VersionFlow.Editors
[SerializeField] [SerializeField]
protected CONFIG m_cfg; protected CONFIG m_cfg;
MsgBool m_status;
public override MsgBool Status => m_status;
public sealed override void CfgChanged(BuilderConfig builder, string cfgJson) public sealed override void CfgChanged(BuilderConfig builder, string cfgJson)
{ {
m_builder = builder; m_builder = builder;
try try
{ {
m_cfg = JsonUtility.FromJson<CONFIG>(cfgJson); m_cfg = JsonUtility.FromJson<CONFIG>(cfgJson);
OnCfgChanged(); m_status = OnCfgChanged();
} }
catch (Exception ex) catch (Exception ex)
{ {
Debug.LogError(ex); m_status = ex.Message;
} }
} }
@ -40,6 +44,6 @@ namespace VersionFlow.Editors
return JsonUtility.ToJson(m_cfg); return JsonUtility.ToJson(m_cfg);
} }
protected abstract void OnCfgChanged(); protected abstract MsgBool OnCfgChanged();
} }
} }

View File

@ -23,17 +23,20 @@ namespace VersionFlow.Editors
private OssClient m_ossClient; private OssClient m_ossClient;
private Client m_cdnClient; private Client m_cdnClient;
protected override void OnCfgChanged() protected override MsgBool OnCfgChanged()
{ {
if (string.IsNullOrWhiteSpace(m_cfg.BucketName)) return "BucketName无效";
if (string.IsNullOrWhiteSpace(m_cfg.UploadPath)) return "UploadPath无效";
try try
{ {
m_ossClient = new OssClient(m_cfg.endPoint, m_cfg.accessKeyId, m_cfg.accessKeySecret); m_ossClient = new OssClient(m_cfg.endPoint, m_cfg.accessKeyId, m_cfg.accessKeySecret);
m_cdnClient = new Client(new AlibabaCloud.OpenApiClient.Models.Config { AccessKeyId = m_cfg.accessKeyId, AccessKeySecret = m_cfg.accessKeySecret }); m_cdnClient = new Client(new AlibabaCloud.OpenApiClient.Models.Config { AccessKeyId = m_cfg.accessKeyId, AccessKeySecret = m_cfg.accessKeySecret });
Debug.Log("AliOSS SDK 初始化成功"); return true;
} }
catch catch
{ {
Debug.LogError("AliOSS SDK 初始化失败,请检查相关参数配置"); return "AliOSS SDK 初始化失败,请检查相关参数配置";
} }
} }

View File

@ -8,7 +8,10 @@ namespace VersionFlow.Editors
[Description("本地文件系统")] [Description("本地文件系统")]
public class PatchUploader_LocalFileSystem : PatchUploader<PatchUploader_LocalFileSystem.Config>, IAsyncDownloader public class PatchUploader_LocalFileSystem : PatchUploader<PatchUploader_LocalFileSystem.Config>, IAsyncDownloader
{ {
protected override void OnCfgChanged() { } protected override MsgBool OnCfgChanged()
{
return true;
}
public override void UploadFile(string remoteFilePath, MemoryStream localfileStream) public override void UploadFile(string remoteFilePath, MemoryStream localfileStream)
{ {

View File

@ -1,4 +1,5 @@
using UnityEditor; using System;
using UnityEditor;
using UnityEngine; using UnityEngine;
using VersionFlow.Runtime; using VersionFlow.Runtime;
@ -32,23 +33,42 @@ namespace VersionFlow.Editors
private void OnGUI() private void OnGUI()
{ {
EditorGUILayout.BeginHorizontal(); EditorGUILayout.BeginHorizontal();
if (GUILayout.Toggle(m_currentEditor == m_builderEditor, "上传设置", GUI.skin.button))
{ {
m_currentEditor = m_builderEditor; EditorGUILayout.BeginVertical(GUILayout.Width(200));
}
if (GUILayout.Toggle(m_currentEditor == m_settingEditor, "运行时设置", GUI.skin.button))
{ {
m_currentEditor = m_settingEditor; DrawEditorTabRegion();
} }
EditorGUILayout.EndVertical(); EditorGUILayout.EndVertical();
EditorGUILayout.BeginVertical(EditorStyles.helpBox); EditorGUILayout.BeginVertical(EditorStyles.helpBox);
{ {
m_builderEditorScroll = EditorGUILayout.BeginScrollView(m_builderEditorScroll); m_builderEditorScroll = EditorGUILayout.BeginScrollView(m_builderEditorScroll);
m_currentEditor.OnInspectorGUI(); DrawSelectEditor();
EditorGUILayout.EndScrollView(); EditorGUILayout.EndScrollView();
} }
EditorGUILayout.EndVertical(); EditorGUILayout.EndVertical();
} }
EditorGUILayout.EndHorizontal();
}
private void DrawSelectEditor()
{
m_currentEditor.OnInspectorGUI();
}
private void DrawEditorTabRegion()
{
DrawEditorTabItem(m_builderEditor, "上传设置");
DrawEditorTabItem(m_settingEditor, "运行时设置");
void DrawEditorTabItem(Editor targetEditor, string name)
{
if (GUILayout.Toggle(m_currentEditor == targetEditor, name, new GUIStyle(GUI.skin.button) { margin = new RectOffset() }, GUILayout.Height(40)))
{
m_currentEditor = targetEditor;
}
}
}
} }
} }