51 lines
1.1 KiB
C#
51 lines
1.1 KiB
C#
using UnityEngine;
|
|
|
|
public class MegaModLODManager : MonoBehaviour
|
|
{
|
|
public GameObject theCamera;
|
|
|
|
public GameObject meshContainer;
|
|
|
|
public MegaModLOD[] levelsOfDetail;
|
|
|
|
public int currentLOD = -1;
|
|
|
|
private float lastLODCheckTime;
|
|
|
|
private float LODCheckInterval = 0.2f;
|
|
|
|
private void Update()
|
|
{
|
|
if (!(Time.time - lastLODCheckTime > LODCheckInterval))
|
|
{
|
|
return;
|
|
}
|
|
float num = Vector3.Distance(base.transform.position, theCamera.transform.position);
|
|
int num2 = levelsOfDetail.Length - 1;
|
|
for (int num3 = levelsOfDetail.Length - 1; num3 >= 0; num3--)
|
|
{
|
|
if (num > levelsOfDetail[num3].distance)
|
|
{
|
|
num2 = num3;
|
|
break;
|
|
}
|
|
}
|
|
if (num2 != currentLOD)
|
|
{
|
|
currentLOD = num2;
|
|
MegaModifyObject component = meshContainer.GetComponent<MegaModifyObject>();
|
|
if (component != null)
|
|
{
|
|
meshContainer.GetComponent<MeshFilter>().mesh = levelsOfDetail[num2].mesh;
|
|
component.MeshUpdated();
|
|
for (int i = 0; i < component.mods.Length; i++)
|
|
{
|
|
MegaModifier megaModifier = component.mods[i];
|
|
megaModifier.ModEnabled = megaModifier.MaxLOD >= currentLOD;
|
|
}
|
|
}
|
|
}
|
|
lastLODCheckTime = Time.time;
|
|
}
|
|
}
|