This commit is contained in:
CortexCore
2024-03-11 02:16:25 +08:00
parent 605ccbcf8d
commit 6ef7c5f005
16 changed files with 832 additions and 45 deletions

View File

@@ -175,10 +175,29 @@ namespace BITFactory.Cutting
var button = _brushFieldsContainer.Create<Button>();
button.text =string.IsNullOrEmpty(exportAttribute.Name) ? methodInfo.Name:exportAttribute.Name;
button.clicked += () =>
button.clicked += OnClicked;
return;
void OnClicked()
{
methodInfo.Invoke(arg2, null);
};
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;
}
}
}
}
}
}

View File

@@ -4,6 +4,7 @@ using System.Collections.Generic;
using System.Runtime.CompilerServices;
using BITKit;
using BITKit.StateMachine;
using PaintIn3D;
using Unity.Collections.LowLevel.Unsafe;
using Unity.Mathematics;
using UnityEngine;
@@ -174,5 +175,69 @@ namespace BITFactory.Cutting
}
}
}
/// <summary>
/// 填充笔刷,用于填充应该被裁剪的区域,类似油漆桶
/// </summary>
[Serializable]
public sealed class CuttingFillBrush : CuttingToolBrush
{
[SerializeField] private Transform transform;
public override string Name => "填充切削";
public override string Description => "仅在该程序中使用,用于预览被裁剪的区域";
[Export(name:"自动填充")]
private void AutoFill()
{
var p3dTexture = transform.GetComponentInChildren<P3dPaintableTexture>();
var texture = p3dTexture.Current.ToTexture2D();
var colors = texture.GetPixels();
var size = new float2(texture.width, texture.height);
//洪水填充
throw new InGameException("暂未实现,算法有些复杂");
}
}
/// <summary>
/// 印花笔刷,用于在表面上印花
/// </summary>
[Serializable]
public sealed class DecalBrush : CuttingToolBrush
{
public override string Name => "印花笔刷";
public override string Description => "在表面上印花,例如预览打印文字或者Logo,图案等";
[Inject]
private IDecalTool _decalTool;
private ITransform _previewTransform;
public override void OnStateEntry(IState old)
{
base.OnStateEntry(old);
_previewTransform = _decalTool.Create(string.Empty);
}
public override void OnStateExit(IState old, IState newState)
{
base.OnStateExit(old, newState);
_previewTransform.Dispose();
}
public override void HandlePoint(bool isPreview, float3 normal, float3 point)
{
if (isPreview is false) return;
_previewTransform.Position = point+(float3)Vector3.up*0.1f;
_previewTransform.Rotation = Quaternion.LookRotation(normal);
}
[Export(name:"选择图片")]
private void SelectImage()
{
throw new InGameException("暂未实现",new NotImplementedException("需要一些小小的base64转换才能储存,暂未实现"));
}
}
}

View File

@@ -0,0 +1,29 @@
using System;
using System.Collections;
using System.Collections.Generic;
using BITKit;
using BITKit.Entities;
using Unity.Mathematics;
using UnityEngine;
using UnityEngine.Rendering.Universal;
namespace BITFactory.Cutting
{
[CustomType(typeof(IDecalTool))]
public class UnityDecalTool : EntityBehavior,IDecalTool
{
[SerializeField] private DecalProjector decalProjector;
private void Start()
{
decalProjector.gameObject.SetActive(false);
}
public ITransform Create(string base64, float3 position = default, quaternion rotation = default, float3 scale = default)
{
var decal = Instantiate(decalProjector, position, rotation);
decal.gameObject.SetActive(true);
return decal.transform.ToUnityTransform();
}
}
}

View File

@@ -12,7 +12,8 @@
"GUID:517785bb4600a5140b47eac5fa49b8fc",
"GUID:d525ad6bd40672747bde77962f1c401e",
"GUID:49b49c76ee64f6b41bf28ef951cb0e50",
"GUID:f51ebe6a0ceec4240a699833d6309b23"
"GUID:f51ebe6a0ceec4240a699833d6309b23",
"GUID:15fc0a57446b3144c949da3e2b9737a9"
],
"includePlatforms": [],
"excludePlatforms": [],