代码合并

This commit is contained in:
MuHua-123
2024-11-08 18:15:06 +08:00
parent 5f169b90bb
commit 497b43a446
146 changed files with 2858 additions and 110 deletions
+8
View File
@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 9ce7a65aa37a4934ba8d85a6136d8c32
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,15 @@
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class DataDesignPoint {
public readonly DataPlate dataPlate;
public DataDesignPoint(DataPlate dataPlate) { this.dataPlate = dataPlate; }
public int index;
public Vector2 postiton;
public Vector2 leftBezier;//贝塞尔曲线左(逆时针+)
public Vector2 rightBezier;//贝塞尔曲线右(顺时针-)
public List<Vector2> edgePoints = new List<Vector2>();
}
@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 215036ac2145e9f45835ea28080aee53
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,29 @@
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class PrefabBezierPoint : MonoBehaviour {
public LineRenderer bezierLine;
private Vector2 position;
private DataDesignPoint value;
private Action<Vector2> callback;
public DataPlate DataPlate => value.dataPlate;
public Vector2 Position => position + value.postiton;
public void SetValue(DataDesignPoint value, Action<Vector2> callback) {
this.value = value;
this.callback = callback;
}
public void SetPosition(Vector2 position) {
this.position = position;
float lx = position.x * 50;
float ly = position.y * 50;
transform.localPosition = new Vector3(lx, ly, transform.localPosition.z);
bezierLine.SetPosition(1, position);
}
public void Change(Vector2 localPosition) {
Vector2 position = localPosition - value.postiton;
SetPosition(position);
callback?.Invoke(position);
}
}
@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 1a3d9fd1b34a70c4ca6a4edaf6715131
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,54 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using MuHua;
public class PrefabDesignPoint : MonoBehaviour, ITemplate<DataDesignPoint> {
public LineRenderer lineRenderer;
public EdgeCollider2D edgeCollider;
public PrefabBezierPoint bezierPoint1;
public PrefabBezierPoint bezierPoint2;
private DataDesignPoint value;
public int Index => value.index;
public Vector2 Position => value.postiton;
public List<Vector2> EdgePoints => value.edgePoints;
public DataPlate DataPlate => value.dataPlate;
public int MaxIndex => DataPlate.designPoints.Count;
public int NextIndex => DataPlateTool.NormalIndex(Index + 1, MaxIndex);
public void SetValue(DataDesignPoint value) {
this.value = value;
bezierPoint1.SetValue(value, (obj) => { value.leftBezier = obj; });
bezierPoint2.SetValue(value, (obj) => { value.rightBezier = obj; });
DataPlate.OnChangeDesignPoint += DataPlate_OnChangeDesignPoint;
DataPlate_OnChangeDesignPoint(Index);
}
private void OnDestroy() {
DataPlate.OnChangeDesignPoint -= DataPlate_OnChangeDesignPoint;
}
private void DataPlate_OnChangeDesignPoint(int index) {
if (index != Index) { return; }
transform.localPosition = Position;
//添加全部点
int maxIndex = EdgePoints.Count + 1;
lineRenderer.positionCount = maxIndex;
Vector2[] vectors = new Vector2[maxIndex];
for (int i = 0; i < EdgePoints.Count; i++) {
Vector2 position = EdgePoints[i] - Position;
lineRenderer.SetPosition(i, position);
vectors[i] = position;
}
//添加最后一个点
int last = maxIndex - 1;
DataDesignPoint nextDesignPoint = DataPlate.FindDesignPoint(NextIndex);
Vector2 position2 = nextDesignPoint.postiton - Position;
lineRenderer.SetPosition(last, position2);
vectors[last] = position2;
//更新2D线段碰撞器
edgeCollider.points = vectors;
//更新贝塞尔曲线
bezierPoint1.SetPosition(value.leftBezier);
bezierPoint2.SetPosition(value.rightBezier);
}
}
@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 76c13895912b8cd48a099779cbd0af65
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
+25
View File
@@ -0,0 +1,25 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UIElements;
public class DataMouseInput {
public Vector3 ScreenPosition;
public float ScrollWheel;
public DataMouseInput(MouseDownEvent evt) {
ScreenPosition = evt.localMousePosition;
}
public DataMouseInput(MouseMoveEvent evt) {
ScreenPosition = evt.localMousePosition;
}
public DataMouseInput(MouseUpEvent evt) {
ScreenPosition = evt.localMousePosition;
}
public DataMouseInput(MouseOutEvent evt) {
ScreenPosition = evt.localMousePosition;
}
public DataMouseInput(WheelEvent evt) {
ScreenPosition = evt.localMousePosition;
ScrollWheel = evt.delta.y;
}
}
+11
View File
@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: d06cc200114296b4c9aef60a8def59b9
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
+8
View File
@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: a9716b7730eb4544cae971a8de6cf9d4
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:
+28
View File
@@ -0,0 +1,28 @@
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class DataPlate {
public Action OnChange;
public Action<int> OnChangeDesignPoint;
public Action<int> OnChangeEdgePoint;
/// <summary> 边缘平滑度 </summary>
public float edgeSmooth = 0.01f;
/// <summary> 设计点 </summary>
public List<DataDesignPoint> designPoints = new List<DataDesignPoint>();
/// <summary> 模型中心点偏移 </summary>
public Vector3 centerOffset;
/// <summary> 边缘点 </summary>
public List<Vector2> edgePoints = new List<Vector2>();
//平面网格数据
/// <summary> 顶点 </summary>
public List<Vector3> vertices = new List<Vector3>();
/// <summary> UV </summary>
public List<Vector2> uv = new List<Vector2>();
/// <summary> 三角形 </summary>
public List<int> triangles = new List<int>();
}
@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 7f57f20fad19ed740adccdb0da9c4469
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,61 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using MuHua;
public class PrefabPlate : MonoBehaviour, ITemplate<DataPlate> {
public Transform DesignPointParent;
public Transform DesignPointTemplate;
public Transform PlateEdgeParent;
public Transform PlateEdgeTemplate;
private DataPlate value;
private Vector3 localPosition;
public MeshFilter MeshFilter => GetComponent<MeshFilter>();
public MeshCollider MeshCollider => GetComponent<MeshCollider>();
public ModuleViewCamera viewCamera => ModuleCore.I.PlateDesignViewCamera;
public void SetValue(DataPlate value) {
this.value = value;
localPosition = viewCamera.CurrentViewSpaceCenter;
value.OnChange += DataPlate_OnChange;
value.Compute();
}
private void OnDestroy() {
value.OnChange -= DataPlate_OnChange;
}
public void DataPlate_OnChange() {
CreateDesignPoint();
//CreatePrefabEdgePoint();
CreatePolygonMesh();
//重置坐标
transform.localPosition = localPosition + value.centerOffset;
localPosition = transform.localPosition;
}
/// <summary> 生成设计点 </summary>
private void CreateDesignPoint() {
DesignPointParent.Instantiate(DesignPointTemplate, value.designPoints);
}
/// <summary> 生成边缘点 </summary>
private void CreatePrefabEdgePoint() {
PlateEdgeParent.DestroySon(PlateEdgeTemplate);
for (int i = 0; i < value.edgePoints.Count; i++) {
Transform temp = Instantiate(PlateEdgeTemplate, PlateEdgeParent);
temp.gameObject.SetActive(true);
PrefabPlateEdge plateEdge = temp.GetComponent<PrefabPlateEdge>();
plateEdge.SetValue(i, value);
}
}
/// <summary> 生成网格 </summary>
private void CreatePolygonMesh() {
Mesh mesh = new Mesh();
mesh.vertices = value.vertices.ToArray();
mesh.uv = value.uv.ToArray();
mesh.triangles = value.triangles.ToArray();
mesh.RecalculateBounds();
mesh.RecalculateNormals();
mesh.RecalculateTangents();
MeshFilter.mesh = mesh;
MeshCollider.sharedMesh = mesh;
}
}
@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: efaf2ad171011c7448092aa48eaf41c4
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,34 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using MuHua;
public class PrefabPlateEdge : MonoBehaviour {
public LineRenderer lineRenderer;
public EdgeCollider2D edgeCollider;
[HideInInspector] public int index;
[HideInInspector] public DataPlate value;
public int MaxIndex => value.edgePoints.Count;
public int NextIndex => DataPlateTool.NormalIndex(index + 1, MaxIndex);
public Vector3 CurrentPosition => value.FindEdgePoint(index);
public Vector3 NextPosition => value.FindEdgePoint(NextIndex);
public void SetValue(int index, DataPlate value) {
this.index = index;
this.value = value;
value.OnChangeEdgePoint += UpdateLineRenderer;
UpdateLineRenderer(index);
}
private void OnDestroy() {
value.OnChangeEdgePoint -= UpdateLineRenderer;
}
public void UpdateLineRenderer(int index) {
if (index != this.index && index != NextIndex) { return; }
transform.localPosition = CurrentPosition;
Vector3 direction = NextPosition - CurrentPosition;
lineRenderer.SetPosition(1, direction);
edgeCollider.points = new Vector2[] { Vector2.zero, direction };
}
}
@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 6e74baea99ddf044c8a16b4d0eacf8ca
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
+31
View File
@@ -0,0 +1,31 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
[CreateAssetMenu(fileName = "PresetsPlate", menuName = "数据模块/预设模板")]
public class DataPresetsPlate : ScriptableObject {
public List<Vector2> designPoints;
public DataPlate ToPlate() {
DataPlate data = new DataPlate();
data.designPoints = new List<DataDesignPoint>();
int maxIndex = designPoints.Count;
for (int i = 0; i < designPoints.Count; i++) {
Vector2 position = designPoints[i];
int left = DataPlateTool.NormalIndex(i + 1, maxIndex);
int right = DataPlateTool.NormalIndex(i - 1, maxIndex);
Vector2 leftBezier = (designPoints[left] - position) * 0.5f;
Vector2 rightBezier = (designPoints[right] - position) * 0.5f;
DataDesignPoint designPoint = CreateDataDesignPoint(i, position, data);
designPoint.leftBezier = leftBezier;
designPoint.rightBezier = rightBezier;
data.designPoints.Add(designPoint);
}
return data;
}
private DataDesignPoint CreateDataDesignPoint(int index, Vector2 position, DataPlate data) {
DataDesignPoint designPoint = new DataDesignPoint(data);
designPoint.index = index;
designPoint.postiton = position;
return designPoint;
}
}
@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: de9e8e0217c52a447a49c55f818131ef
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant: