This commit is contained in:
parent
e686eb89ab
commit
c80a4a2245
|
@ -1,4 +1,5 @@
|
||||||
using System;
|
using System;
|
||||||
|
using System.Reflection;
|
||||||
|
|
||||||
namespace BITKit
|
namespace BITKit
|
||||||
{
|
{
|
||||||
|
@ -57,6 +58,29 @@ namespace BITKit
|
||||||
[AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct | AttributeTargets.Field | AttributeTargets.Method, AllowMultiple = true, Inherited = true)]
|
[AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct | AttributeTargets.Field | AttributeTargets.Method, AllowMultiple = true, Inherited = true)]
|
||||||
public class ExportAttribute : System.Attribute
|
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 string Name;
|
||||||
public readonly IExportSetting Settings;
|
public readonly IExportSetting Settings;
|
||||||
public ExportAttribute(){}
|
public ExportAttribute(){}
|
||||||
|
|
|
@ -480,7 +480,7 @@ namespace BITKit.Net
|
||||||
await BITApp.SwitchToMainThread();
|
await BITApp.SwitchToMainThread();
|
||||||
if (value is Exception e)
|
if (value is Exception e)
|
||||||
{
|
{
|
||||||
throw new InGameException(e.Message,e);
|
throw new InGameException(e.Message);
|
||||||
}
|
}
|
||||||
if (UniTask.CompletedTask is T t)
|
if (UniTask.CompletedTask is T t)
|
||||||
{
|
{
|
||||||
|
|
|
@ -303,8 +303,6 @@ namespace BITKit.Net
|
||||||
returnWriter.Write((byte)NetCommandType.ReturnToClient);
|
returnWriter.Write((byte)NetCommandType.ReturnToClient);
|
||||||
returnWriter.Write(requestId);
|
returnWriter.Write(requestId);
|
||||||
|
|
||||||
try
|
|
||||||
{
|
|
||||||
if (reader.ReadBoolean())
|
if (reader.ReadBoolean())
|
||||||
{
|
{
|
||||||
var path = reader.ReadString();
|
var path = reader.ReadString();
|
||||||
|
@ -321,25 +319,41 @@ namespace BITKit.Net
|
||||||
pars = new object[] { };
|
pars = new object[] { };
|
||||||
}
|
}
|
||||||
|
|
||||||
if (isAwaitable)
|
try
|
||||||
{
|
{
|
||||||
dynamic result = methodInfo.Invoke(handle, pars)!;
|
if (isAwaitable)
|
||||||
|
|
||||||
if (methodInfo.ReturnType == typeof(void) || methodInfo.ReturnType == typeof(UniTask))
|
|
||||||
{
|
{
|
||||||
await result;
|
dynamic result = methodInfo.Invoke(handle, pars)!;
|
||||||
value = -1;
|
|
||||||
|
if (methodInfo.ReturnType == typeof(void) || methodInfo.ReturnType == typeof(UniTask))
|
||||||
|
{
|
||||||
|
await result;
|
||||||
|
value = -1;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
value = await result;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else
|
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);
|
returnWriter.Write(true);
|
||||||
if (value is not null)
|
if (value is not null)
|
||||||
{
|
{
|
||||||
|
@ -373,16 +387,7 @@ namespace BITKit.Net
|
||||||
var _bytes = returnMS.ToArray();
|
var _bytes = returnMS.ToArray();
|
||||||
_sendQueue.Enqueue((Id,_bytes));
|
_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;
|
break;
|
||||||
case NetCommandType.ReturnToServer:
|
case NetCommandType.ReturnToServer:
|
||||||
|
|
|
@ -48,10 +48,12 @@ namespace BITKit
|
||||||
T value;
|
T value;
|
||||||
#else
|
#else
|
||||||
[UnityEngine.SerializeField]
|
[UnityEngine.SerializeField]
|
||||||
bool allow;
|
private bool allow;
|
||||||
[UnityEngine.SerializeField]
|
[UnityEngine.SerializeField]
|
||||||
T value;
|
private T value;
|
||||||
|
[UnityEngine.SerializeField]
|
||||||
#endif
|
#endif
|
||||||
|
private bool debug;
|
||||||
public bool Allow { get => allow; set => allow = value;}
|
public bool Allow { get => allow; set => allow = value;}
|
||||||
public T Value
|
public T Value
|
||||||
{
|
{
|
||||||
|
|
|
@ -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
|
@ -30,6 +30,7 @@ namespace BITKit.UX
|
||||||
CurrentPanel = null;
|
CurrentPanel = null;
|
||||||
History.Clear();
|
History.Clear();
|
||||||
EntryGroup = new EntryGroup<IUXPanel>();
|
EntryGroup = new EntryGroup<IUXPanel>();
|
||||||
|
WindowEntryGruop = new();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue