合并代码
This commit is contained in:
@@ -4,25 +4,30 @@ using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
public class DataPlate {
|
||||
public Action OnChange;
|
||||
public Action<int> OnChangeDesignPoint;
|
||||
public Action<int> OnChangeEdgePoint;
|
||||
|
||||
#region 核心数据
|
||||
/// <summary> 边缘平滑度 </summary>
|
||||
public float edgeSmooth = 0.01f;
|
||||
/// <summary> 板片位置(本地坐标系) </summary>
|
||||
public Vector3 position;
|
||||
/// <summary> 设计点 </summary>
|
||||
public List<DataDesignPoint> designPoints = new List<DataDesignPoint>();
|
||||
public List<DataPoint> points = new List<DataPoint>();
|
||||
#endregion
|
||||
|
||||
/// <summary> 模型中心点偏移 </summary>
|
||||
public Vector3 centerOffset;
|
||||
#region 次要数据
|
||||
/// <summary> 平面网格 </summary>
|
||||
public Mesh polygon;
|
||||
/// <summary> 边缘点 </summary>
|
||||
public List<Vector2> edgePoints = new List<Vector2>();
|
||||
public List<Vector3> edgePoints = new List<Vector3>();
|
||||
#endregion
|
||||
|
||||
#region 可视化数据
|
||||
/// <summary> 可视化对象 </summary>
|
||||
public Transform transform;
|
||||
/// <summary> 可视化多边形网格 </summary>
|
||||
public MeshFilter polygonMeshFilter;
|
||||
/// <summary> 可视化边缘线 </summary>
|
||||
public LineRenderer edgeLineRenderer;
|
||||
#endregion
|
||||
|
||||
//平面网格数据
|
||||
/// <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,37 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
public class DataPoint {
|
||||
/// <summary> 绑定的板片 </summary>
|
||||
public readonly DataPlate plate;
|
||||
/// <summary> 初始化 </summary>
|
||||
public DataPoint(DataPlate plate) => this.plate = plate;
|
||||
|
||||
#region 核心数据
|
||||
/// <summary> 点前(-) 是否是曲线 </summary>
|
||||
public bool isCurveFront;
|
||||
/// <summary> 点后(+) 是否是曲线 </summary>
|
||||
public bool isCurveAfter;
|
||||
/// <summary> 设计点位置(本地坐标系) </summary>
|
||||
public Vector3 position;
|
||||
/// <summary> 贝塞尔曲线前(-) </summary>
|
||||
public Vector3 frontBezier;
|
||||
/// <summary> 贝塞尔曲线后(+) </summary>
|
||||
public Vector3 afterBezier;
|
||||
#endregion
|
||||
|
||||
#region 可视化数据
|
||||
/// <summary> 可视化对象 </summary>
|
||||
public Transform transform;
|
||||
/// <summary> 可视化贝塞尔点前(-) </summary>
|
||||
public Transform frontBezierTransform;
|
||||
/// <summary> 可视化贝塞尔点后(+) </summary>
|
||||
public Transform afterBezierTransform;
|
||||
/// <summary> 可视化贝塞尔线前(-) </summary>
|
||||
public LineRenderer frontBezierLineRenderer;
|
||||
/// <summary> 可视化贝塞尔线后(+) </summary>
|
||||
public LineRenderer afterBezierLineRenderer;
|
||||
#endregion
|
||||
}
|
||||
+1
-1
@@ -1,5 +1,5 @@
|
||||
fileFormatVersion: 2
|
||||
guid: efaf2ad171011c7448092aa48eaf41c4
|
||||
guid: 753c1b80d6d80af4baaa095760bdc3f5
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
@@ -0,0 +1,12 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
public class DataTriangle {
|
||||
public Vector3 a;
|
||||
public Vector3 b;
|
||||
public Vector3 c;
|
||||
public override string ToString() {
|
||||
return $"{a} , {b} , {c}";
|
||||
}
|
||||
}
|
||||
+1
-1
@@ -1,5 +1,5 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 6e74baea99ddf044c8a16b4d0eacf8ca
|
||||
guid: 0119f0f1ae644424b8ed9bd212d86ec1
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
@@ -1,61 +0,0 @@
|
||||
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;
|
||||
}
|
||||
}
|
||||
@@ -1,34 +0,0 @@
|
||||
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 };
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user