BITFALL/Assets/BITKit/Unity/Scripts/WorldChunk/ChunkLodObject.cs

74 lines
1.5 KiB
C#
Raw Normal View History

2024-03-17 02:24:55 +08:00
using System;
using System.Collections;
using System.Collections.Generic;
using Quadtree;
using UnityEngine;
namespace BITKit.OpenWorld
{
public class ChunkLodObject : MonoBehaviour, IWorldChunkObject
{
2024-03-22 20:16:32 +08:00
[Serializable]
public struct Data
{
public Renderer[] renderers;
}
2024-03-17 02:24:55 +08:00
[SerializeField]
2024-03-22 20:16:32 +08:00
private Data[] lodObjects;
2024-03-17 02:24:55 +08:00
[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
{
2024-03-18 18:20:23 +08:00
if (_lod is not -1)
{
2024-03-22 20:16:32 +08:00
foreach (var x in lodObjects[_lod].renderers)
{
if(x)x.enabled = false;
}
2024-03-18 18:20:23 +08:00
}
2024-03-17 02:24:55 +08:00
_lod = value;
if (_lod is -1) return;
2024-03-22 20:16:32 +08:00
if (lodObjects.Length <= _lod) return;
foreach (var x in lodObjects[_lod].renderers)
{
if(x)x.enabled = true;
}
2024-03-17 02:24:55 +08:00
}
}
private void Start()
{
_bounds = new Bounds(transform.position, initialSize);
foreach (var x in lodObjects)
2024-03-22 20:16:32 +08:00
foreach (var xx in x.renderers)
{
xx.enabled = false;
}
2024-03-18 18:20:23 +08:00
UnityWorldChunkService.Singleton.Register(this);
2024-03-17 02:24:55 +08:00
destroyCancellationToken.Register(Dispose);
}
private void Dispose()
{
2024-03-18 18:20:23 +08:00
UnityWorldChunkService.Singleton.Unregister(this);
2024-03-17 02:24:55 +08:00
}
}
}