This commit is contained in:
CortexCore
2024-04-16 04:15:06 +08:00
parent b673a9438d
commit 0362b2c606
183 changed files with 5695 additions and 1453 deletions

View File

@@ -2,6 +2,7 @@ using System;
using System.Collections;
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using AYellowpaper.SerializedCollections;
@@ -120,85 +121,7 @@ namespace BITFactory.Cutting
_brushFieldsContainer.Clear();
var fields = arg2.GetType().GetFields(ReflectionHelper.Flags);
foreach (var fieldInfo in fields)
{
if (Attribute.IsDefined(fieldInfo, typeof(ExportAttribute)) is false) continue;
var exportAttribute = fieldInfo.GetCustomAttribute<ExportAttribute>();
// var runtimeFieldInfo = arg2.GetType().GetRuntimeField(fieldInfo.Name);
// runtimeFieldInfo= arg2.GetType().GetField(fieldInfo.Name);
//
// Debug.Log(runtimeFieldInfo);
// var _ref = TypedReference.MakeTypedReference(arg2, new []{runtimeFieldInfo});
var handler = UXDataBindingService.CreateBinding(arg2.GetExport(fieldInfo.Name),fieldInfo.GetValue(arg2));
//var handler = UXDataBindingService.CreateBinding(_ref);
_brushFieldsContainer.Add(handler.visualElement);
handler.visualElement.GetType().GetProperty("label")!.SetValue(handler.visualElement,
string.IsNullOrEmpty(exportAttribute.Name) ? fieldInfo.Name:exportAttribute.Name
);
//var handler = UXDataBindingService.CreateBinding(ref arg2.GetExport(fieldInfo.Name));
// switch (fieldInfo.GetValue(arg2))
// {
// case float _float:
// var floatField = _brushFieldsContainer.Create<FloatField>();
// floatField.label =string.IsNullOrEmpty(exportAttribute.Name) ? fieldInfo.Name:exportAttribute.Name;
// floatField.value = _float;
// floatField.RegisterValueChangedCallback(evt =>
// {
// fieldInfo.SetValue(arg2, evt.newValue);
// });
// break;
// case Vector3 _vector3:
// var vector3Field = _brushFieldsContainer.Create<Vector3Field>();
// vector3Field.label =string.IsNullOrEmpty(exportAttribute.Name) ? fieldInfo.Name:exportAttribute.Name;
// vector3Field.value = _vector3;
// vector3Field.RegisterValueChangedCallback(evt =>
// {
// fieldInfo.SetValue(arg2, evt.newValue);
// });
// break;
// }
}
foreach (var methodInfo in arg2.GetType().GetMethods(ReflectionHelper.Flags))
{
if (Attribute.IsDefined(methodInfo, typeof(ExportAttribute)) is false) continue;
var exportAttribute = methodInfo.GetCustomAttribute<ExportAttribute>();
var button = _brushFieldsContainer.Create<Button>();
button.text =string.IsNullOrEmpty(exportAttribute.Name) ? methodInfo.Name:exportAttribute.Name;
button.clicked += OnClicked;
return;
void OnClicked()
{
try
{
methodInfo.Invoke(arg2, 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;
}
}
}
}
_brushFieldsContainer.Add(UXDataBindingService.Create(arg2));
}
}
}