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));
}
}
}

View File

@@ -1,10 +1,13 @@
using System;
using System.Collections;
using System.Collections.Generic;
using System.Reflection;
using System.Runtime.CompilerServices;
using BITKit;
using BITKit.StateMachine;
using Newtonsoft.Json;
using PaintIn3D;
using Unity.Collections;
using Unity.Collections.LowLevel.Unsafe;
using Unity.Mathematics;
using UnityEngine;
@@ -26,14 +29,9 @@ namespace BITFactory.Cutting
public override string Name => "点切削";
public override string Description => "按住鼠标左键进行画笔切削";
[BITKit.Export("切削半径")]
[Export("切削半径")]
public float Radius = 0;
public override unsafe void* GetExport(string name)
{
return name == nameof(Radius) ? UnsafeUtility.AddressOf(ref Radius) : base.GetExport(name);
}
public override void HandlePoint(bool isPreview, float3 normal, float3 point)
{
if (!isPreview) return;
@@ -84,15 +82,6 @@ namespace BITFactory.Cutting
private float3 _normal=Vector3.up;
private readonly IntervalUpdate _interrupt = new(0.1f);
public override unsafe void* GetExport(string name)
{
return name switch
{
nameof(snapDifference)=>UnsafeUtility.AddressOf(ref snapDifference),
_ => base.GetExport(name)
};
}
public override void OnStateExit(IState old, IState newState)
{
base.OnStateExit(old, newState);
@@ -183,7 +172,21 @@ namespace BITFactory.Cutting
{
[SerializeField] private Transform transform;
public override string Name => "填充切削";
public override string Description => "仅在该程序中使用,用于预览被裁剪的区域";
public override string Description => "仅在该程序中使用,用于预览被裁剪的区域\n事实上现在用于测试运行时序列化字段";
[Export(name:"字符串列表")] private List<string> stringList = new();
[Export(name:"单浮点列表")] private List<float> floatList = new();
[Export(name:"整数列表")] private List<int> intList = new();
[Export(name:"字符串数组")] private string[] stringArray = Array.Empty<string>();
[Export(name:"单浮点数组")] private float[] floatArray = Array.Empty<float>();
[Export(name:"整数数组")] private int[] intArray = Array.Empty<int>();
[Export(name:"float3数组")] private float3 position;
public override void ReleasePoint(float3 normal, float3 point)
{
base.ReleasePoint(normal, point);
stringList.Add(JsonConvert.SerializeObject((Vector3)point));
}
[Export(name:"自动填充")]
private void AutoFill()

View File

@@ -19,16 +19,6 @@ namespace BITFactory.Cutting
[Export("位置")] private Vector3 point;
[Export("半径")] private float radius = 0.01f;
public override unsafe void* GetExport(string name)
{
var x = __makeref(radius);
return name switch
{
nameof(radius) => UnsafeUtility.AddressOf(ref radius),
nameof(point) => UnsafeUtility.AddressOf(ref point),
_ => base.GetExport(name)
};
}
[Export("确认")]
private void Release()

View File

@@ -13,7 +13,8 @@
"GUID:d525ad6bd40672747bde77962f1c401e",
"GUID:49b49c76ee64f6b41bf28ef951cb0e50",
"GUID:f51ebe6a0ceec4240a699833d6309b23",
"GUID:15fc0a57446b3144c949da3e2b9737a9"
"GUID:15fc0a57446b3144c949da3e2b9737a9",
"GUID:e0cd26848372d4e5c891c569017e11f1"
],
"includePlatforms": [],
"excludePlatforms": [],