71 lines
1.2 KiB
C#
71 lines
1.2 KiB
C#
using UnityEngine;
|
|
|
|
public class MegaPointCacheInstance : MonoBehaviour
|
|
{
|
|
[HideInInspector]
|
|
public MegaPointCache mod;
|
|
|
|
[HideInInspector]
|
|
public MegaModifyObject modobj;
|
|
|
|
public GameObject obj;
|
|
|
|
[HideInInspector]
|
|
public Mesh mesh;
|
|
|
|
public float time;
|
|
|
|
public float speed = 1f;
|
|
|
|
public int updateRate;
|
|
|
|
public int frame;
|
|
|
|
public bool recalcNorms = true;
|
|
|
|
public bool recalcBounds = true;
|
|
|
|
public void SetSource(GameObject srcobj)
|
|
{
|
|
if ((bool)srcobj)
|
|
{
|
|
if (this.mesh == null)
|
|
{
|
|
this.mesh = MegaUtils.GetMesh(base.gameObject);
|
|
}
|
|
Mesh mesh = MegaUtils.GetMesh(srcobj);
|
|
if (mesh.vertexCount == this.mesh.vertexCount)
|
|
{
|
|
obj = srcobj;
|
|
mod = srcobj.GetComponent<MegaPointCache>();
|
|
modobj = srcobj.GetComponent<MegaModifyObject>();
|
|
this.mesh = MegaUtils.GetMesh(base.gameObject);
|
|
}
|
|
}
|
|
}
|
|
|
|
private void Update()
|
|
{
|
|
if (!mod || !modobj || !mesh)
|
|
{
|
|
return;
|
|
}
|
|
time += Time.deltaTime * speed;
|
|
frame--;
|
|
if (frame < 0)
|
|
{
|
|
frame = updateRate;
|
|
mod.ModifyInstance(modobj, time);
|
|
mesh.vertices = mod.sverts;
|
|
if (recalcNorms)
|
|
{
|
|
mesh.RecalculateNormals();
|
|
}
|
|
if (recalcBounds)
|
|
{
|
|
mesh.RecalculateBounds();
|
|
}
|
|
}
|
|
}
|
|
}
|