1
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Runtime.InteropServices;
|
||||
@@ -25,6 +26,53 @@ namespace BITKit.IData
|
||||
}
|
||||
private static readonly Dictionary<Type,IUXDataBinder> _Binders = new();
|
||||
private static readonly CacheList<IUXDataBinder> _Instances = new();
|
||||
|
||||
public static VisualElement Create(object target)
|
||||
{
|
||||
var visualElement = new VisualElement();
|
||||
var fields = target.GetType().GetFields(ReflectionHelper.Flags);
|
||||
foreach (var fieldInfo in fields.Where(x=>x.GetCustomAttribute<ExportAttribute>() is not null))
|
||||
{
|
||||
var handler = UXDataBindingService.Create(target,fieldInfo);
|
||||
var ui = handler.CreateUI(target, fieldInfo);
|
||||
visualElement.Add(ui);
|
||||
}
|
||||
|
||||
foreach (var methodInfo in target.GetType().GetMethods(ReflectionHelper.Flags))
|
||||
{
|
||||
if (Attribute.IsDefined(methodInfo, typeof(ExportAttribute)) is false) continue;
|
||||
var exportAttribute = methodInfo.GetCustomAttribute<ExportAttribute>();
|
||||
|
||||
var button = visualElement.Create<Button>();
|
||||
button.text =string.IsNullOrEmpty(exportAttribute.Name) ? methodInfo.Name:exportAttribute.Name;
|
||||
|
||||
button.clicked += OnClicked;
|
||||
|
||||
continue;
|
||||
void OnClicked()
|
||||
{
|
||||
try
|
||||
{
|
||||
methodInfo.Invoke(target, null);
|
||||
}
|
||||
catch (TargetInvocationException targetInvocationException)
|
||||
{
|
||||
if (targetInvocationException.InnerException is InGameException e is false) return;
|
||||
switch (e)
|
||||
{
|
||||
case {InnerException:not null}:
|
||||
Alert.Print(e.Message,e.InnerException.Message);
|
||||
break;
|
||||
default:
|
||||
Alert.Print(e.Message,e.Source);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return visualElement;
|
||||
}
|
||||
|
||||
public static IUXDataBinder Create(object target,FieldInfo fieldInfo)
|
||||
{
|
||||
|
Reference in New Issue
Block a user