This commit is contained in:
CortexCore 2024-07-17 17:06:45 +08:00
parent e686eb89ab
commit c80a4a2245
7 changed files with 415 additions and 86 deletions

View File

@ -1,4 +1,5 @@
using System;
using System.Reflection;
namespace BITKit
{
@ -57,6 +58,29 @@ namespace BITKit
[AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct | AttributeTargets.Field | AttributeTargets.Method, AllowMultiple = true, Inherited = true)]
public class ExportAttribute : System.Attribute
{
public static string GetName(object obj)
{
var att = obj.GetType().GetCustomAttribute<ExportAttribute>();
att = obj switch
{
FieldInfo field => field.GetCustomAttribute<ExportAttribute>(),
MethodInfo method => method.GetCustomAttribute<ExportAttribute>(),
PropertyInfo property => property.GetCustomAttribute<ExportAttribute>(),
_ => att
};
if (att is null) return obj.GetType().Name;
if (string.IsNullOrEmpty(att.Name))
{
return obj switch
{
FieldInfo field => field.Name,
MethodInfo method => method.Name,
PropertyInfo property => property.Name,
_ => att.Name
};
}
return att.Name;
}
public readonly string Name;
public readonly IExportSetting Settings;
public ExportAttribute(){}

View File

@ -480,7 +480,7 @@ namespace BITKit.Net
await BITApp.SwitchToMainThread();
if (value is Exception e)
{
throw new InGameException(e.Message,e);
throw new InGameException(e.Message);
}
if (UniTask.CompletedTask is T t)
{

View File

@ -303,8 +303,6 @@ namespace BITKit.Net
returnWriter.Write((byte)NetCommandType.ReturnToClient);
returnWriter.Write(requestId);
try
{
if (reader.ReadBoolean())
{
var path = reader.ReadString();
@ -321,25 +319,41 @@ namespace BITKit.Net
pars = new object[] { };
}
if (isAwaitable)
try
{
dynamic result = methodInfo.Invoke(handle, pars)!;
if (methodInfo.ReturnType == typeof(void) || methodInfo.ReturnType == typeof(UniTask))
if (isAwaitable)
{
await result;
value = -1;
dynamic result = methodInfo.Invoke(handle, pars)!;
if (methodInfo.ReturnType == typeof(void) || methodInfo.ReturnType == typeof(UniTask))
{
await result;
value = -1;
}
else
{
value = await result;
}
}
else
{
value = await result;
value = methodInfo.Invoke(handle, pars);
}
}
else
catch (Exception e)
{
value = methodInfo.Invoke(handle, pars);
}
if(e is TargetInvocationException tie)
e = tie.InnerException;
returnWriter.Write(false);
returnWriter.Write(e.Message);
var _bytes = returnMS.ToArray();
_sendQueue.Enqueue((Id,_bytes));
BIT4Log.LogException(e);
return;
}
returnWriter.Write(true);
if (value is not null)
{
@ -373,16 +387,7 @@ namespace BITKit.Net
var _bytes = returnMS.ToArray();
_sendQueue.Enqueue((Id,_bytes));
}
}
catch (Exception e)
{
returnWriter.Write(false);
returnWriter.Write(e.Message);
var _bytes = returnMS.ToArray();
_sendQueue.Enqueue((Id,_bytes));
BIT4Log.LogException(e);
}
}
break;
case NetCommandType.ReturnToServer:

View File

@ -48,10 +48,12 @@ namespace BITKit
T value;
#else
[UnityEngine.SerializeField]
bool allow;
private bool allow;
[UnityEngine.SerializeField]
T value;
private T value;
[UnityEngine.SerializeField]
#endif
private bool debug;
public bool Allow { get => allow; set => allow = value;}
public T Value
{

View File

@ -0,0 +1,62 @@
using System;
using System.Reflection;
namespace BITKit
{
public interface IWrapper
{
public object Obj { get; set; }
}
public interface IWrapper<T>:IWrapper
{
public T Value { get; set; }
}
public class ValueWrapper<T> : IWrapper<T>
{
public T Value { get; set; }=default;
public object Obj { get => Value; set => Value = (T)value; }
}
public class FieldWrapper<T> : IWrapper<T>
{
private readonly FieldInfo _field;
private readonly object _target;
public FieldWrapper(FieldInfo field, object target)
{
_field = field;
_target = target ?? throw new ArgumentNullException(nameof(target));
}
public T Value
{
get => (T)_field.GetValue(_target);
set => _field.SetValue(_target, value);
}
public object Obj
{
get => _field.GetValue(_target);
set => _field.SetValue(_target, value);
}
}
public class FuncWrapper<T> : IWrapper<T>
{
private readonly Func<T> _get;
private readonly Action<T> _set;
public FuncWrapper(Func<T> get, Action<T> set)
{
_get = get;
_set = set;
}
public T Value
{
get => _get();
set => _set(value);
}
public object Obj
{
get => _get();
set => _set((T)value);
}
}
}

File diff suppressed because one or more lines are too long

View File

@ -30,6 +30,7 @@ namespace BITKit.UX
CurrentPanel = null;
History.Clear();
EntryGroup = new EntryGroup<IUXPanel>();
WindowEntryGruop = new();
}