55 lines
1.3 KiB
C#
55 lines
1.3 KiB
C#
using UnityEngine;
|
|
|
|
namespace Misaki.AoVolume
|
|
{
|
|
[ExecuteInEditMode]
|
|
internal class AoVolume : MonoBehaviour
|
|
{
|
|
private VolumeEntity _entity = VolumeEntity.Invalid;
|
|
|
|
public bool dynamicVolume;
|
|
public VolumeData data;
|
|
|
|
private void UpdateMatrixData()
|
|
{
|
|
data.worldMatrix = transform.localToWorldMatrix;
|
|
data.inverseWorldMatrix = transform.worldToLocalMatrix;
|
|
}
|
|
|
|
private void OnEnable()
|
|
{
|
|
if (_entity.IsValid)
|
|
{
|
|
return;
|
|
}
|
|
|
|
UpdateMatrixData();
|
|
_entity = VolumeDatabase.Instance.CreateEntity(data);
|
|
}
|
|
|
|
private void OnDisable()
|
|
{
|
|
VolumeDatabase.Instance.DestroyEntity(ref _entity);
|
|
}
|
|
|
|
private void Update()
|
|
{
|
|
if (dynamicVolume && transform.hasChanged)
|
|
{
|
|
UpdateMatrixData();
|
|
ref var oldData = ref VolumeDatabase.Instance.GetDataRef(_entity);
|
|
oldData = data;
|
|
|
|
transform.hasChanged = false;
|
|
}
|
|
}
|
|
|
|
private void OnDrawGizmos()
|
|
{
|
|
Gizmos.matrix = transform.localToWorldMatrix;
|
|
Gizmos.color = Color.green;
|
|
Gizmos.DrawWireCube(Vector3.zero, data.size);
|
|
}
|
|
}
|
|
}
|