60 lines
1.5 KiB
C#
60 lines
1.5 KiB
C#
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using System.Text;
|
|
using Pinwheel.Griffin;
|
|
using Quadtree;
|
|
using UnityEngine;
|
|
|
|
namespace BITKit.OpenWorld
|
|
{
|
|
public class PolarisTerrainChunkService : WorldChunkService<PolarisTerrainChunkService>
|
|
{
|
|
private class ChunkData:IWorldChunkObject
|
|
{
|
|
public Collider Collider { get; set; }
|
|
public Bounds GetBounds() => Bounds;
|
|
public Bounds Bounds { get; set; }
|
|
public Node<IWorldChunkObject> ParentNode { get; set; }
|
|
public void QuadTree_Root_Initialized(IQuadtreeRoot<IWorldChunkObject, Node<IWorldChunkObject>> root)
|
|
{
|
|
}
|
|
|
|
public int Id { get; set; }
|
|
public int Lod
|
|
{
|
|
get => lod;
|
|
set
|
|
{
|
|
Collider.enabled = value is 0;
|
|
lod = value;
|
|
}
|
|
}
|
|
private int lod=-1;
|
|
}
|
|
[SerializeField] private GStylizedTerrain[] terrains;
|
|
protected override void Start()
|
|
{
|
|
base.Start();
|
|
var reporter = new StringBuilder();
|
|
foreach (var terrain in terrains)
|
|
{
|
|
reporter.AppendLine($"正在注册地形 {terrain.name},尺寸:{terrain.TerrainData.Geometry.Width}x{terrain.TerrainData.Geometry.Length}");
|
|
foreach (var chunk in terrain.GetChunks())
|
|
{
|
|
var data =new ChunkData()
|
|
{
|
|
Collider = chunk.MeshColliderComponent,
|
|
Bounds = chunk.MeshColliderComponent.bounds
|
|
};
|
|
data.Collider.enabled = false;
|
|
Register(data);
|
|
reporter.AppendLine($"注册地形碰撞体 {chunk.name},尺寸:{data.Bounds.size}");
|
|
}
|
|
}
|
|
Debug.Log(reporter);
|
|
OnTick(Time.deltaTime);
|
|
}
|
|
}
|
|
}
|
|
|