73 lines
2.0 KiB
C#
73 lines
2.0 KiB
C#
using System;
|
|
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using Quadtree;
|
|
#if UNITY_EDITOR
|
|
using UnityEditor;
|
|
#endif
|
|
using UnityEngine;
|
|
|
|
namespace BITKit.OpenWorld
|
|
{
|
|
/// <summary>
|
|
/// 这个应该载入后就销毁,托管给纯class
|
|
/// </summary>
|
|
public sealed class ColliderChunkObject : MonoBehaviour
|
|
{
|
|
[SerializeField] private Collider[] colliders;
|
|
[SerializeField] private ChunkBehaviour chunkBehaviour;
|
|
[SerializeField] private bool getCollidersOnStart;
|
|
private void Start()
|
|
{
|
|
try
|
|
{
|
|
if (getCollidersOnStart)
|
|
{
|
|
GetCollidersInChildren();
|
|
}
|
|
chunkBehaviour.OnLodChangedEvent += OnLodChanged;
|
|
if(colliders is {Length:0})colliders = GetComponentsInChildren<Collider>();
|
|
}
|
|
catch (Exception e)
|
|
{
|
|
BIT4Log.Warning<ColliderChunkObject>(gameObject.name);
|
|
BIT4Log.LogException(e);
|
|
}
|
|
|
|
}
|
|
private void OnLodChanged(int arg1, int arg2)
|
|
{
|
|
var enabledCollider = arg2 is 0;
|
|
foreach (var x in colliders)
|
|
{
|
|
try
|
|
{
|
|
x.enabled = enabledCollider;
|
|
}
|
|
catch (UnassignedReferenceException)
|
|
{
|
|
GetCollidersInChildren();
|
|
OnLodChanged(arg1, arg2);
|
|
return;
|
|
}
|
|
catch (Exception e)
|
|
{
|
|
BIT4Log.Warning<ColliderChunkObject>(gameObject.name);
|
|
BIT4Log.LogException(e);
|
|
}
|
|
|
|
}
|
|
}
|
|
[BIT]
|
|
private void GetCollidersInChildren()
|
|
{
|
|
colliders = GetComponentsInChildren<Collider>();
|
|
#if UNITY_EDITOR
|
|
EditorUtility.SetDirty(this);
|
|
#endif
|
|
}
|
|
|
|
}
|
|
}
|
|
|