代码合并
This commit is contained in:
@@ -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:
|
||||
Reference in New Issue
Block a user