更新00
This commit is contained in:
@@ -8,7 +8,7 @@ namespace Stary.Evo
|
||||
{
|
||||
public static readonly EnumEventSystem Global = new EnumEventSystem();
|
||||
|
||||
private readonly Dictionary<int, IEasyEvent> mEvents = new Dictionary<int, IEasyEvent>(50);
|
||||
private readonly Dictionary<string, IEasyEvent> mEvents = new Dictionary<string, IEasyEvent>(50);
|
||||
|
||||
public EnumEventSystem(){}
|
||||
|
||||
@@ -16,7 +16,7 @@ namespace Stary.Evo
|
||||
|
||||
public IUnRegister Register<T>(T key, Action onEvent)where T : IConvertible
|
||||
{
|
||||
var kv = key.ToInt32(null);
|
||||
var kv = typeof(T).ToString()+ key.ToInt32(null);
|
||||
if (mEvents.TryGetValue(kv, out var e))
|
||||
{
|
||||
var easyEvent = e.As<EasyEvent>();
|
||||
@@ -31,7 +31,7 @@ namespace Stary.Evo
|
||||
}
|
||||
public IUnRegister Register<T,T1>(T key, Action<T1> onEvent)where T : IConvertible
|
||||
{
|
||||
var kv = key.ToInt32(null);
|
||||
var kv = typeof(T).ToString()+ key.ToInt32(null);
|
||||
if (mEvents.TryGetValue(kv, out var e))
|
||||
{
|
||||
var easyEvent = e.As<EasyEvent<T1>>();
|
||||
@@ -46,7 +46,7 @@ namespace Stary.Evo
|
||||
}
|
||||
public IUnRegister Register<T,T1,T2>(T key, Action<T1,T2> onEvent)where T : IConvertible
|
||||
{
|
||||
var kv = key.ToInt32(null);
|
||||
var kv = typeof(T).ToString()+ key.ToInt32(null);
|
||||
if (mEvents.TryGetValue(kv, out var e))
|
||||
{
|
||||
var easyEvent = e.As<EasyEvent<T1,T2>>();
|
||||
@@ -61,7 +61,7 @@ namespace Stary.Evo
|
||||
}
|
||||
public IUnRegister Register<T,T1,T2,T3>(T key, Action<T1,T2,T3> onEvent) where T : IConvertible
|
||||
{
|
||||
var kv = key.ToInt32(null);
|
||||
var kv = typeof(T).ToString()+ key.ToInt32(null);
|
||||
|
||||
if (mEvents.TryGetValue(kv, out var e))
|
||||
{
|
||||
@@ -77,7 +77,7 @@ namespace Stary.Evo
|
||||
}
|
||||
public IUnRegister Register<T>(T key, Action<object[]> onEvent) where T : IConvertible
|
||||
{
|
||||
var kv = key.ToInt32(null);
|
||||
var kv = typeof(T).ToString()+ key.ToInt32(null);
|
||||
|
||||
if (mEvents.TryGetValue(kv, out var e))
|
||||
{
|
||||
@@ -93,7 +93,7 @@ namespace Stary.Evo
|
||||
}
|
||||
public void UnRegister<T>(T key, Action onEvent) where T : IConvertible
|
||||
{
|
||||
var kv = key.ToInt32(null);
|
||||
var kv = typeof(T).ToString()+ key.ToInt32(null);
|
||||
|
||||
if (mEvents.TryGetValue(kv, out var e))
|
||||
{
|
||||
@@ -102,7 +102,7 @@ namespace Stary.Evo
|
||||
}
|
||||
public void UnRegister<T,T1>(T key, Action<T1> onEvent) where T : IConvertible
|
||||
{
|
||||
var kv = key.ToInt32(null);
|
||||
var kv = typeof(T).ToString()+ key.ToInt32(null);
|
||||
|
||||
if (mEvents.TryGetValue(kv, out var e))
|
||||
{
|
||||
@@ -111,7 +111,7 @@ namespace Stary.Evo
|
||||
}
|
||||
public void UnRegister<T,T1,T2>(T key, Action<T1,T2> onEvent) where T : IConvertible
|
||||
{
|
||||
var kv = key.ToInt32(null);
|
||||
var kv = typeof(T).ToString()+ key.ToInt32(null);
|
||||
|
||||
if (mEvents.TryGetValue(kv, out var e))
|
||||
{
|
||||
@@ -120,7 +120,7 @@ namespace Stary.Evo
|
||||
}
|
||||
public void UnRegister<T,T1,T2,T3>(T key, Action<T1,T2,T3> onEvent) where T : IConvertible
|
||||
{
|
||||
var kv = key.ToInt32(null);
|
||||
var kv = typeof(T).ToString()+ key.ToInt32(null);
|
||||
|
||||
if (mEvents.TryGetValue(kv, out var e))
|
||||
{
|
||||
@@ -129,7 +129,7 @@ namespace Stary.Evo
|
||||
}
|
||||
public void UnRegister<T>(T key, Action<object[]> onEvent) where T : IConvertible
|
||||
{
|
||||
var kv = key.ToInt32(null);
|
||||
var kv = typeof(T).ToString()+ key.ToInt32(null);
|
||||
|
||||
if (mEvents.TryGetValue(kv, out var e))
|
||||
{
|
||||
@@ -145,7 +145,7 @@ namespace Stary.Evo
|
||||
}
|
||||
public void Send<T>(T key) where T : IConvertible
|
||||
{
|
||||
var kv = key.ToInt32(null);
|
||||
var kv = typeof(T).ToString()+ key.ToInt32(null);
|
||||
|
||||
if (mEvents.TryGetValue(kv, out var e))
|
||||
{
|
||||
@@ -154,7 +154,7 @@ namespace Stary.Evo
|
||||
}
|
||||
public void Send<T,T1>(T key, T1 t1) where T : IConvertible
|
||||
{
|
||||
var kv = key.ToInt32(null);
|
||||
var kv = typeof(T).ToString()+ key.ToInt32(null);
|
||||
|
||||
if (mEvents.TryGetValue(kv, out var e))
|
||||
{
|
||||
@@ -163,7 +163,7 @@ namespace Stary.Evo
|
||||
}
|
||||
public void Send<T,T1,T2>(T key, T1 t1,T2 t2) where T : IConvertible
|
||||
{
|
||||
var kv = key.ToInt32(null);
|
||||
var kv = typeof(T).ToString()+ key.ToInt32(null);
|
||||
|
||||
if (mEvents.TryGetValue(kv, out var e))
|
||||
{
|
||||
@@ -172,7 +172,7 @@ namespace Stary.Evo
|
||||
}
|
||||
public void Send<T,T1,T2,T3>(T key, T1 t1,T2 t2 ,T3 t3) where T : IConvertible
|
||||
{
|
||||
var kv = key.ToInt32(null);
|
||||
var kv = typeof(T).ToString()+ key.ToInt32(null);
|
||||
|
||||
if (mEvents.TryGetValue(kv, out var e))
|
||||
{
|
||||
@@ -181,11 +181,11 @@ namespace Stary.Evo
|
||||
}
|
||||
public void Send<T>(T key, params object[] args) where T : IConvertible
|
||||
{
|
||||
var kv = key.ToInt32(null);
|
||||
var kv = typeof(T).ToString()+ key.ToInt32(null);
|
||||
|
||||
if (mEvents.TryGetValue(kv, out var e))
|
||||
{
|
||||
e.As<EasyEvent<int,object[]>>().Trigger(kv,args);
|
||||
e.As<EasyEvent<string,object[]>>().Trigger(kv,args);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,24 +0,0 @@
|
||||
using YooAsset;
|
||||
|
||||
namespace Stary.Evo
|
||||
{
|
||||
public class RemoteServices : IRemoteServices
|
||||
{
|
||||
private readonly string _defaultHostServer;
|
||||
private readonly string _fallbackHostServer;
|
||||
|
||||
public RemoteServices(string defaultHostServer, string fallbackHostServer)
|
||||
{
|
||||
_defaultHostServer = defaultHostServer;
|
||||
_fallbackHostServer = fallbackHostServer;
|
||||
}
|
||||
string IRemoteServices.GetRemoteMainURL(string fileName)
|
||||
{
|
||||
return $"{_defaultHostServer}/{fileName}";
|
||||
}
|
||||
string IRemoteServices.GetRemoteFallbackURL(string fileName)
|
||||
{
|
||||
return $"{_fallbackHostServer}/{fileName}";
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,3 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 24f14ead8b7e46eaa0eddd6e68db8d56
|
||||
timeCreated: 1741248220
|
||||
@@ -1,51 +0,0 @@
|
||||
using YooAsset;
|
||||
using System.Collections;
|
||||
using Stary.Evo;
|
||||
using UnityEngine.Networking;
|
||||
|
||||
public class RemoteServicesWithAuth : IRemoteServices
|
||||
{
|
||||
private readonly string _defaultHostServer;
|
||||
private readonly string _fallbackHostServer;
|
||||
private string _authToken;
|
||||
private string _authServiceUrl;
|
||||
|
||||
public string CurrentToken { get; private set; }
|
||||
|
||||
public RemoteServicesWithAuth(string defaultHostServer,
|
||||
string fallbackHostServer,
|
||||
string authToken,
|
||||
string authServiceUrl)
|
||||
{
|
||||
_defaultHostServer = defaultHostServer;
|
||||
_fallbackHostServer = fallbackHostServer;
|
||||
_authToken = authToken;
|
||||
_authServiceUrl = authServiceUrl;
|
||||
RefreshToken();
|
||||
}
|
||||
|
||||
private void RefreshToken()
|
||||
{
|
||||
// 这里实现具体的token刷新逻辑
|
||||
CurrentToken = _authToken; // 简单示例直接使用初始token
|
||||
// 实际项目应该通过authServiceUrl获取新token
|
||||
}
|
||||
|
||||
string IRemoteServices.GetRemoteMainURL(string fileName)
|
||||
{
|
||||
// 在原始URL后附加鉴权参数
|
||||
return $"{_defaultHostServer}/{fileName}?token={CurrentToken}";
|
||||
}
|
||||
|
||||
public string GetRemoteFallbackURL(string fileName)
|
||||
{
|
||||
return $"{_fallbackHostServer}/{fileName}?token={CurrentToken}";
|
||||
}
|
||||
|
||||
// UnityWebRequest CreateRequest(string url)
|
||||
// {
|
||||
// var request = base.CreateRequest(url);
|
||||
// request.SetRequestHeader("Authorization", $"Bearer {CurrentToken}");
|
||||
// return request;
|
||||
// }
|
||||
}
|
||||
@@ -1,3 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 6dc545bfe9be45789ff05152e3679e20
|
||||
timeCreated: 1741319247
|
||||
67
Assets/00.StaryEvo/Runtime/Utility/UnityAsyncExtensions.cs
Normal file
67
Assets/00.StaryEvo/Runtime/Utility/UnityAsyncExtensions.cs
Normal file
@@ -0,0 +1,67 @@
|
||||
#pragma warning disable CS1591 // Missing XML comment for publicly visible type or member
|
||||
|
||||
using System;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using UnityEngine;
|
||||
#if ENABLE_UNITYWEBREQUEST && (!UNITY_2019_1_OR_NEWER || UNITASK_WEBREQUEST_SUPPORT)
|
||||
using UnityEngine.Networking;
|
||||
#endif
|
||||
|
||||
namespace Stary.Evo
|
||||
{
|
||||
public static partial class UnityAsyncExtensions
|
||||
{
|
||||
|
||||
|
||||
#if !UNITY_2023_1_OR_NEWER
|
||||
// from Unity2023.1.0a15, AsyncOperationAwaitableExtensions.GetAwaiter is defined in UnityEngine.
|
||||
public static AsyncOperationAwaiter GetAwaiter(this AsyncOperation asyncOperation)
|
||||
{
|
||||
return new AsyncOperationAwaiter(asyncOperation);
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
public struct AsyncOperationAwaiter : ICriticalNotifyCompletion
|
||||
{
|
||||
AsyncOperation asyncOperation;
|
||||
Action<AsyncOperation> continuationAction;
|
||||
|
||||
public AsyncOperationAwaiter(AsyncOperation asyncOperation)
|
||||
{
|
||||
this.asyncOperation = asyncOperation;
|
||||
this.continuationAction = null;
|
||||
}
|
||||
|
||||
public bool IsCompleted => asyncOperation.isDone;
|
||||
|
||||
public void GetResult()
|
||||
{
|
||||
if (continuationAction != null)
|
||||
{
|
||||
asyncOperation.completed -= continuationAction;
|
||||
continuationAction = null;
|
||||
asyncOperation = null;
|
||||
}
|
||||
else
|
||||
{
|
||||
asyncOperation = null;
|
||||
}
|
||||
}
|
||||
|
||||
public void OnCompleted(Action continuation)
|
||||
{
|
||||
UnsafeOnCompleted(continuation);
|
||||
}
|
||||
|
||||
public void UnsafeOnCompleted(Action continuation)
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: a42a4edb452e470b87e698b7d7b7db4a
|
||||
timeCreated: 1743403227
|
||||
@@ -1,6 +1,6 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using Cysharp.Threading.Tasks;
|
||||
using System.Threading.Tasks;
|
||||
using UnityEngine;
|
||||
using UnityEngine.Networking;
|
||||
|
||||
@@ -8,8 +8,8 @@ namespace Stary.Evo
|
||||
{
|
||||
public interface IWebRequestSystem
|
||||
{
|
||||
UniTask<string> Post(string url, string postData);
|
||||
UniTask<string> Get(string url, string token=null);
|
||||
Task<string> Post(string url, string postData);
|
||||
Task<string> Get(string url, string token=null);
|
||||
|
||||
}
|
||||
|
||||
@@ -21,7 +21,7 @@ namespace Stary.Evo
|
||||
/// <param name="url">获取Token值的服务URL地址(很重要)</param>
|
||||
/// <param name="postData">传入请求的参数,此处参数为JOSN格式</param>
|
||||
/// <returns></returns>
|
||||
public async UniTask<string> Post(string url, string postData)
|
||||
public async Task<string> Post(string url, string postData)
|
||||
{
|
||||
using (UnityWebRequest webRequest = UnityWebRequest.Post(url, postData)) //第二种写法此行注释
|
||||
{
|
||||
@@ -51,7 +51,7 @@ namespace Stary.Evo
|
||||
/// <param name="url">请求数据的URL地址</param>
|
||||
/// <param name="token">token验证的参数,此处为authorization</param>
|
||||
/// <returns></returns>
|
||||
public async UniTask<string> Get(string url, string token=null)
|
||||
public async Task<string> Get(string url, string token=null)
|
||||
{
|
||||
try
|
||||
{
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "com.staryevo.main",
|
||||
"version": "1.0.0",
|
||||
"version": "1.0.1",
|
||||
"displayName": "00.StaryEvo",
|
||||
"description": "This is an Framework package",
|
||||
"unity": "2021.3",
|
||||
|
||||
8
Assets/00.StaryEvo/~Samples.meta
Normal file
8
Assets/00.StaryEvo/~Samples.meta
Normal file
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 50c0b79ec6a68a24cb577c05cefb670d
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
Reference in New Issue
Block a user