84 lines
2.2 KiB
C#
84 lines
2.2 KiB
C#
![]() |
using System.Collections.Generic;
|
|||
|
using UnityEngine;
|
|||
|
|
|||
|
public class TestMono : MonoBehaviour
|
|||
|
{
|
|||
|
|
|||
|
public MeshFilter TargetMesh; //<2F><><EFBFBD><EFBFBD>
|
|||
|
public Transform BallGroup; //<2F><><EFBFBD>弯<EFBFBD><E5BCAF>(<28>ؽ<EFBFBD><D8BD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>)
|
|||
|
private List<Transform> m_listBall; //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
private List<MeshData> m_listMeshData; //<2F>ڵ<EFBFBD><DAB5><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
|
|||
|
void Start()
|
|||
|
{
|
|||
|
m_listBall = new List<Transform>();
|
|||
|
foreach (Transform tran in BallGroup)
|
|||
|
{
|
|||
|
m_listBall.Add(tran);
|
|||
|
}
|
|||
|
|
|||
|
|
|||
|
m_listMeshData = new List<MeshData>();
|
|||
|
int totleMeshPoint = TargetMesh.mesh.vertices.Length;
|
|||
|
for (int i = 0; i < totleMeshPoint; i++)
|
|||
|
{
|
|||
|
MeshData data = new MeshData();
|
|||
|
|
|||
|
data.Index = i;
|
|||
|
data.target = __FindNearest(TargetMesh.mesh.vertices[i]);
|
|||
|
if (data.target == null) Debug.Log("<22>пյ<D0BF>");
|
|||
|
data.offset = TargetMesh.mesh.vertices[i] - data.target.localPosition;
|
|||
|
m_listMeshData.Add(data);
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
// Update is called once per frame
|
|||
|
void Update()
|
|||
|
{
|
|||
|
MoveMeshPoint();
|
|||
|
}
|
|||
|
|
|||
|
private void MoveMeshPoint()
|
|||
|
{
|
|||
|
Vector3[] v3 = TargetMesh.mesh.vertices;
|
|||
|
for (int i = 0; i < m_listMeshData.Count; i++)
|
|||
|
{
|
|||
|
MeshData curData = m_listMeshData[i];
|
|||
|
Vector3 dir = curData.target.transform.TransformDirection(curData.offset);
|
|||
|
v3[i] = curData.target.localPosition + dir;
|
|||
|
}
|
|||
|
TargetMesh.mesh.vertices = v3;
|
|||
|
}
|
|||
|
|
|||
|
|
|||
|
|
|||
|
private Transform __FindNearest(Vector3 v3)
|
|||
|
{
|
|||
|
if (m_listBall != null)
|
|||
|
{
|
|||
|
float MaxDis = 999999;
|
|||
|
Transform MaxTran = null;
|
|||
|
for (int i = 0; i < m_listBall.Count; i++)
|
|||
|
{
|
|||
|
float curDis = Vector3.Distance(m_listBall[i].localPosition, v3);
|
|||
|
if (curDis < MaxDis)
|
|||
|
{
|
|||
|
MaxDis = curDis;
|
|||
|
MaxTran = m_listBall[i];
|
|||
|
}
|
|||
|
}
|
|||
|
return MaxTran;
|
|||
|
}
|
|||
|
return null;
|
|||
|
}
|
|||
|
|
|||
|
}
|
|||
|
|
|||
|
public class MeshData
|
|||
|
{
|
|||
|
public int Index; //<2F><><EFBFBD><EFBFBD>
|
|||
|
public Transform target; //Ŀ<><C4BF><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
public Vector3 offset; //<2F><>Ŀ<EFBFBD><C4BF><EFBFBD><EFBFBD><EFBFBD><EFBFBD>λ<EFBFBD>ò<EFBFBD><C3B2><EFBFBD>
|
|||
|
}
|
|||
|
|