1
This commit is contained in:
73
Src/Unity/Scripts/WorldChunk/ChunkLodObject.cs
Normal file
73
Src/Unity/Scripts/WorldChunk/ChunkLodObject.cs
Normal file
@@ -0,0 +1,73 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using Quadtree;
|
||||
using UnityEngine;
|
||||
|
||||
namespace BITKit.OpenWorld
|
||||
{
|
||||
public class ChunkLodObject : MonoBehaviour, IWorldChunkObject
|
||||
{
|
||||
[Serializable]
|
||||
public struct Data
|
||||
{
|
||||
public Renderer[] renderers;
|
||||
}
|
||||
|
||||
[SerializeField]
|
||||
private Data[] 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)
|
||||
{
|
||||
foreach (var x in lodObjects[_lod].renderers)
|
||||
{
|
||||
if(x)x.enabled = false;
|
||||
}
|
||||
}
|
||||
_lod = value;
|
||||
if (_lod is -1) return;
|
||||
if (lodObjects.Length <= _lod) return;
|
||||
foreach (var x in lodObjects[_lod].renderers)
|
||||
{
|
||||
if(x)x.enabled = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private void Start()
|
||||
{
|
||||
_bounds = new Bounds(transform.position, initialSize);
|
||||
foreach (var x in lodObjects)
|
||||
foreach (var xx in x.renderers)
|
||||
{
|
||||
xx.enabled = false;
|
||||
}
|
||||
UnityWorldChunkService.Singleton.Register(this);
|
||||
destroyCancellationToken.Register(Dispose);
|
||||
}
|
||||
|
||||
private void Dispose()
|
||||
{
|
||||
UnityWorldChunkService.Singleton.Unregister(this);
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user