73 lines
1.5 KiB
C#
73 lines
1.5 KiB
C#
using System;
|
|
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using System.Runtime.InteropServices;
|
|
using BITKit;
|
|
using BITKit.OpenWorld;
|
|
using Quadtree;
|
|
using UnityEngine;
|
|
|
|
|
|
namespace BITFALL.OpenWorld
|
|
{
|
|
public class RuntimeSetActiveChunk : MonoBehaviour,IWorldChunkObject
|
|
{
|
|
[SerializeField, ReadOnly] private Vector3 size;
|
|
[SerializeField,ReadOnly] private int _lod=-1;
|
|
public Node<IWorldChunkObject> ParentNode { get; set; }
|
|
public Bounds GetBounds()
|
|
{
|
|
if (_isInitialized) return _bounds;
|
|
_bounds = new Bounds(transform.position,Vector3.one);
|
|
foreach (var x in _renderers = GetComponentsInChildren<Renderer>(true))
|
|
{
|
|
_bounds.Encapsulate(x.bounds);
|
|
}
|
|
size = _bounds.size;
|
|
_isInitialized = true;
|
|
return _bounds;
|
|
}
|
|
private bool _isInitialized;
|
|
private Bounds _bounds;
|
|
|
|
public void QuadTree_Root_Initialized(IQuadtreeRoot<IWorldChunkObject, Node<IWorldChunkObject>> root)
|
|
{
|
|
}
|
|
public int Id { get; set; }
|
|
private Renderer[] _renderers;
|
|
public int Lod
|
|
{
|
|
get => _lod;
|
|
set
|
|
{
|
|
_lod = value;
|
|
var _active = value is 0 or 1;
|
|
if(_active==active)return;
|
|
active = _active;
|
|
foreach (var x in _renderers)
|
|
{
|
|
try
|
|
{
|
|
x.enabled = active;
|
|
}
|
|
catch (Exception e)
|
|
{
|
|
BIT4Log.LogException(e);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
private bool active;
|
|
internal void Initialize()
|
|
{
|
|
GetBounds();
|
|
foreach (var x in _renderers)
|
|
{
|
|
x.enabled = false;
|
|
}
|
|
active = false;
|
|
}
|
|
}
|
|
}
|
|
|