1
This commit is contained in:
46
Assets/BITKit/Unity/Scripts/WorldChunk/ChunkBehaviour.cs
Normal file
46
Assets/BITKit/Unity/Scripts/WorldChunk/ChunkBehaviour.cs
Normal file
@@ -0,0 +1,46 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using BITKit.OpenWorld;
|
||||
using UnityEngine;
|
||||
#if UNITY_EDITOR
|
||||
using UnityEditor;
|
||||
#endif
|
||||
namespace BITKit.OpenWorld
|
||||
{
|
||||
public class ChunkBehaviour : ChunkObject
|
||||
{
|
||||
public event Action<int,int> OnLodChangedEvent;
|
||||
protected override void OnLodChanged(int oldLod, int newLod)
|
||||
{
|
||||
base.OnLodChanged(oldLod, newLod);
|
||||
OnLodChangedEvent?.Invoke(oldLod,newLod);
|
||||
}
|
||||
|
||||
[BIT]
|
||||
private void CalculateBounds()
|
||||
{
|
||||
if(TryGetComponent<Collider>(out var _collider))
|
||||
{
|
||||
var bounds1 = _collider.bounds;
|
||||
size = bounds1.size;
|
||||
offset = bounds1.center - transform.position;
|
||||
|
||||
return;
|
||||
}
|
||||
Bounds bounds = new();
|
||||
foreach (var x in GetComponentsInChildren<Collider>())
|
||||
{
|
||||
bounds.Encapsulate(x.bounds);
|
||||
if (x.bounds.size.sqrMagnitude > 64)
|
||||
{
|
||||
Debug.LogWarning($"{x.gameObject.name}:Size is too large, please check the size of the collider");
|
||||
}
|
||||
}
|
||||
size = bounds.size;
|
||||
offset = bounds.center - transform.position;
|
||||
EditorUtility.SetDirty(this);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user