Make Setting Wnd More pretty
This commit is contained in:
parent
5510c1f3fe
commit
3881ae8232
@ -126,6 +126,11 @@ namespace VersionFlow.Editors
|
||||
EditorUtility.SetDirty(target);
|
||||
patchLoader.CfgChanged(builder, builder.UploaderCfgDict.GetUploaderCfg(patchLoader.GetType()));
|
||||
}
|
||||
|
||||
if (!patchLoader.Status)
|
||||
{
|
||||
EditorGUILayout.HelpBox(patchLoader.Status, MessageType.Error);
|
||||
}
|
||||
}
|
||||
|
||||
private void DrawGroupItems()
|
||||
|
||||
93
Assets/VersionFlow/Editor/MsgBool.cs
Normal file
93
Assets/VersionFlow/Editor/MsgBool.cs
Normal 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();
|
||||
}
|
||||
}
|
||||
}
|
||||
11
Assets/VersionFlow/Editor/MsgBool.cs.meta
Normal file
11
Assets/VersionFlow/Editor/MsgBool.cs.meta
Normal file
@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: d23328d75cc93354ea1a595833f504a2
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@ -7,6 +7,7 @@ namespace VersionFlow.Editors
|
||||
{
|
||||
public abstract class PatchUploader : ScriptableObject
|
||||
{
|
||||
public abstract MsgBool Status { get; }
|
||||
public PatchUploader() { }
|
||||
public abstract void CfgChanged(BuilderConfig builder, string cfgJson);
|
||||
public abstract void UploadFile(string remoteFilePath, MemoryStream localfileStream);
|
||||
@ -21,17 +22,20 @@ namespace VersionFlow.Editors
|
||||
[SerializeField]
|
||||
protected CONFIG m_cfg;
|
||||
|
||||
MsgBool m_status;
|
||||
public override MsgBool Status => m_status;
|
||||
|
||||
public sealed override void CfgChanged(BuilderConfig builder, string cfgJson)
|
||||
{
|
||||
m_builder = builder;
|
||||
try
|
||||
{
|
||||
m_cfg = JsonUtility.FromJson<CONFIG>(cfgJson);
|
||||
OnCfgChanged();
|
||||
m_status = OnCfgChanged();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Debug.LogError(ex);
|
||||
m_status = ex.Message;
|
||||
}
|
||||
}
|
||||
|
||||
@ -40,6 +44,6 @@ namespace VersionFlow.Editors
|
||||
return JsonUtility.ToJson(m_cfg);
|
||||
}
|
||||
|
||||
protected abstract void OnCfgChanged();
|
||||
protected abstract MsgBool OnCfgChanged();
|
||||
}
|
||||
}
|
||||
@ -23,17 +23,20 @@ namespace VersionFlow.Editors
|
||||
private OssClient m_ossClient;
|
||||
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
|
||||
{
|
||||
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 });
|
||||
Debug.Log("AliOSS SDK 初始化成功");
|
||||
return true;
|
||||
}
|
||||
catch
|
||||
{
|
||||
Debug.LogError("AliOSS SDK 初始化失败,请检查相关参数配置");
|
||||
return "AliOSS SDK 初始化失败,请检查相关参数配置";
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -8,7 +8,10 @@ namespace VersionFlow.Editors
|
||||
[Description("本地文件系统")]
|
||||
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)
|
||||
{
|
||||
|
||||
@ -1,4 +1,5 @@
|
||||
using UnityEditor;
|
||||
using System;
|
||||
using UnityEditor;
|
||||
using UnityEngine;
|
||||
using VersionFlow.Runtime;
|
||||
|
||||
@ -32,23 +33,42 @@ namespace VersionFlow.Editors
|
||||
private void OnGUI()
|
||||
{
|
||||
EditorGUILayout.BeginHorizontal();
|
||||
if (GUILayout.Toggle(m_currentEditor == m_builderEditor, "上传设置", GUI.skin.button))
|
||||
{
|
||||
m_currentEditor = m_builderEditor;
|
||||
}
|
||||
if (GUILayout.Toggle(m_currentEditor == m_settingEditor, "运行时设置", GUI.skin.button))
|
||||
EditorGUILayout.BeginVertical(GUILayout.Width(200));
|
||||
{
|
||||
m_currentEditor = m_settingEditor;
|
||||
DrawEditorTabRegion();
|
||||
}
|
||||
EditorGUILayout.EndVertical();
|
||||
|
||||
EditorGUILayout.BeginVertical(EditorStyles.helpBox);
|
||||
{
|
||||
m_builderEditorScroll = EditorGUILayout.BeginScrollView(m_builderEditorScroll);
|
||||
m_currentEditor.OnInspectorGUI();
|
||||
DrawSelectEditor();
|
||||
EditorGUILayout.EndScrollView();
|
||||
}
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Reference in New Issue
Block a user