79 lines
1.9 KiB
C#
79 lines
1.9 KiB
C#
using UnityEngine;
|
|
|
|
namespace Artngame.SKYMASTER
|
|
{
|
|
[ExecuteInEditMode]
|
|
public class RecalcBOUNDS_SM : MonoBehaviour
|
|
{
|
|
private MeshFilter AA;
|
|
|
|
private Transform this_transform;
|
|
|
|
public bool calcBounds;
|
|
|
|
public bool alwaysCalcBounds;
|
|
|
|
public float boundsBigNumber = 1000000f;
|
|
|
|
public bool realtiveBoundsCalc;
|
|
|
|
public void Start()
|
|
{
|
|
if (Application.isPlaying)
|
|
{
|
|
AA = GetComponent(typeof(MeshFilter)) as MeshFilter;
|
|
this_transform = base.transform;
|
|
}
|
|
}
|
|
|
|
public void Awake()
|
|
{
|
|
if (AA == null)
|
|
{
|
|
AA = GetComponent(typeof(MeshFilter)) as MeshFilter;
|
|
this_transform = base.transform;
|
|
}
|
|
float num = boundsBigNumber;
|
|
if (AA.sharedMesh != null)
|
|
{
|
|
AA.sharedMesh.bounds = new Bounds(Vector3.zero, new Vector3(num, 20f, num));
|
|
}
|
|
}
|
|
|
|
public void Update()
|
|
{
|
|
if ((calcBounds && Application.isPlaying) || alwaysCalcBounds)
|
|
{
|
|
if (AA == null)
|
|
{
|
|
AA = GetComponent(typeof(MeshFilter)) as MeshFilter;
|
|
this_transform = base.transform;
|
|
}
|
|
calcBounds = false;
|
|
float num = boundsBigNumber;
|
|
AA.sharedMesh.bounds = new Bounds(Vector3.zero, new Vector3(num, 20f, num));
|
|
}
|
|
if (realtiveBoundsCalc && Vector3.Distance(Camera.main.transform.position, this_transform.position) < 1000f)
|
|
{
|
|
Vector3 position = Camera.main.transform.position;
|
|
Vector3 vector = Vector3.Normalize(Camera.main.transform.forward);
|
|
float num2 = (Camera.main.farClipPlane - Camera.main.nearClipPlane) / 2f + Camera.main.nearClipPlane;
|
|
Vector3 position2 = position + vector * num2;
|
|
Vector3 center = base.transform.InverseTransformPoint(position2);
|
|
if (Application.isPlaying)
|
|
{
|
|
AA.mesh.bounds = new Bounds(center, Vector3.one);
|
|
}
|
|
}
|
|
}
|
|
|
|
private void shiftMesh()
|
|
{
|
|
Mesh sharedMesh = AA.sharedMesh;
|
|
Vector3[] vertices = sharedMesh.vertices;
|
|
sharedMesh.vertices = vertices;
|
|
sharedMesh.RecalculateBounds();
|
|
}
|
|
}
|
|
}
|