53 lines
857 B
C#
53 lines
857 B
C#
using System;
|
|
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using NGS.AdvancedCullingSystem.Dynamic;
|
|
using UnityEngine;
|
|
|
|
namespace BITFALL.Props
|
|
{
|
|
public class Prop_Optimize : MonoBehaviour
|
|
{
|
|
[SerializeField] private new Rigidbody rigidbody;
|
|
[SerializeField] private Collider[] colliders;
|
|
|
|
private bool isSleeping;
|
|
private void Start()
|
|
{
|
|
if(colliders?.Length == 0)
|
|
colliders = GetComponentsInChildren<Collider>();
|
|
|
|
}
|
|
|
|
private void OnBecameInvisible()
|
|
{
|
|
if (!rigidbody)
|
|
{
|
|
Destroy(this);
|
|
|
|
return;
|
|
}
|
|
|
|
rigidbody.Sleep();
|
|
rigidbody.useGravity = false;
|
|
|
|
foreach (var x in colliders)
|
|
{
|
|
x.enabled = false;
|
|
}
|
|
}
|
|
private void OnBecameVisible()
|
|
{
|
|
if (rigidbody)
|
|
{
|
|
rigidbody.useGravity = true;
|
|
}
|
|
foreach (var x in colliders)
|
|
{
|
|
x.enabled = true;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|