57 lines
1.2 KiB
C#
57 lines
1.2 KiB
C#
|
using System;
|
||
|
using System.Collections;
|
||
|
using System.Collections.Generic;
|
||
|
using Quadtree;
|
||
|
using UnityEngine;
|
||
|
|
||
|
namespace BITKit.OpenWorld
|
||
|
{
|
||
|
public class ChunkLodObject : MonoBehaviour, IWorldChunkObject
|
||
|
{
|
||
|
[SerializeField]
|
||
|
private List<Renderer> lodObjects;
|
||
|
[SerializeField,ReadOnly] private int _lod = -1;
|
||
|
[SerializeField,ReadOnly] private int id;
|
||
|
[SerializeField] private Vector3 initialSize;
|
||
|
private Bounds _bounds;
|
||
|
public Bounds GetBounds() => _bounds;
|
||
|
public Node<IWorldChunkObject> ParentNode { get; set; }
|
||
|
public void QuadTree_Root_Initialized(IQuadtreeRoot<IWorldChunkObject, Node<IWorldChunkObject>> root)
|
||
|
{
|
||
|
}
|
||
|
public int Id
|
||
|
{
|
||
|
get=>id;
|
||
|
set=>id = value;
|
||
|
}
|
||
|
public int Lod
|
||
|
{
|
||
|
get=>_lod;
|
||
|
set
|
||
|
{
|
||
|
if (_lod is not -1) lodObjects[_lod].enabled = false;
|
||
|
_lod = value;
|
||
|
if (_lod is -1) return;
|
||
|
if (lodObjects.Count > _lod)
|
||
|
lodObjects[_lod].enabled = true;
|
||
|
}
|
||
|
}
|
||
|
|
||
|
|
||
|
private void Start()
|
||
|
{
|
||
|
_bounds = new Bounds(transform.position, initialSize);
|
||
|
foreach (var x in lodObjects)
|
||
|
if (x)
|
||
|
x.enabled = false;
|
||
|
UnityWorldChunkService.Register(this);
|
||
|
destroyCancellationToken.Register(Dispose);
|
||
|
}
|
||
|
|
||
|
private void Dispose()
|
||
|
{
|
||
|
UnityWorldChunkService.Unregister(this);
|
||
|
}
|
||
|
}
|
||
|
}
|