055b87a85c
Introduce a DI-wired NavMesh sidecar for voxel chunks so world streaming stays actor-driven and world state remains the canonical source for navigation rebuilds.
117 lines
3.3 KiB
C#
117 lines
3.3 KiB
C#
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
using UnityEngine.AI;
|
|
|
|
namespace InfiniteWorld.VoxelWorld.Contracts
|
|
{
|
|
public interface IChunkNavSourceReader
|
|
{
|
|
float ChunkWorldSize { get; }
|
|
void GetLoadedChunkCoords(List<Vector2Int> results);
|
|
bool TryGetChunkNavSourceSnapshot(Vector2Int coord, out ChunkNavSourceSnapshot snapshot);
|
|
}
|
|
|
|
public interface IWorldInterestReader
|
|
{
|
|
int InterestVersion { get; }
|
|
void GetInterestPoints(List<WorldInterestPoint> results);
|
|
}
|
|
|
|
public readonly struct ChunkNavSourceSnapshot
|
|
{
|
|
public ChunkNavSourceSnapshot(Vector2Int coord, int version, ChunkNavBuildSourceDescriptor[] sources)
|
|
{
|
|
Coord = coord;
|
|
Version = version;
|
|
Sources = sources;
|
|
}
|
|
|
|
public Vector2Int Coord { get; }
|
|
public int Version { get; }
|
|
public ChunkNavBuildSourceDescriptor[] Sources { get; }
|
|
}
|
|
|
|
public readonly struct ChunkNavBuildSourceDescriptor
|
|
{
|
|
public ChunkNavBuildSourceDescriptor(NavMeshBuildSourceShape shape, Matrix4x4 transform, Vector3 size, Mesh mesh, int area)
|
|
{
|
|
Shape = shape;
|
|
Transform = transform;
|
|
Size = size;
|
|
Mesh = mesh;
|
|
Area = area;
|
|
}
|
|
|
|
public NavMeshBuildSourceShape Shape { get; }
|
|
public Matrix4x4 Transform { get; }
|
|
public Vector3 Size { get; }
|
|
public Mesh Mesh { get; }
|
|
public int Area { get; }
|
|
|
|
public static ChunkNavBuildSourceDescriptor CreateBox(Matrix4x4 transform, Vector3 size, int area = 0)
|
|
{
|
|
return new ChunkNavBuildSourceDescriptor(NavMeshBuildSourceShape.Box, transform, size, null, area);
|
|
}
|
|
|
|
public static ChunkNavBuildSourceDescriptor CreateMesh(Matrix4x4 transform, Mesh mesh, int area = 0)
|
|
{
|
|
return new ChunkNavBuildSourceDescriptor(NavMeshBuildSourceShape.Mesh, transform, Vector3.zero, mesh, area);
|
|
}
|
|
}
|
|
|
|
public readonly struct WorldInterestPoint
|
|
{
|
|
public WorldInterestPoint(Vector3 position, float priority, WorldInterestKind kind)
|
|
{
|
|
Position = position;
|
|
Priority = priority;
|
|
Kind = kind;
|
|
}
|
|
|
|
public Vector3 Position { get; }
|
|
public float Priority { get; }
|
|
public WorldInterestKind Kind { get; }
|
|
}
|
|
|
|
public enum WorldInterestKind
|
|
{
|
|
PlayerActor = 0,
|
|
ActiveNpc = 1,
|
|
Other = 2
|
|
}
|
|
|
|
public readonly struct ChunkNavGeometryReadyMessage
|
|
{
|
|
public ChunkNavGeometryReadyMessage(Vector2Int coord, int version)
|
|
{
|
|
Coord = coord;
|
|
Version = version;
|
|
}
|
|
|
|
public Vector2Int Coord { get; }
|
|
public int Version { get; }
|
|
}
|
|
|
|
public readonly struct ChunkNavGeometryRemovedMessage
|
|
{
|
|
public ChunkNavGeometryRemovedMessage(Vector2Int coord, int version)
|
|
{
|
|
Coord = coord;
|
|
Version = version;
|
|
}
|
|
|
|
public Vector2Int Coord { get; }
|
|
public int Version { get; }
|
|
}
|
|
|
|
public readonly struct WorldInterestChangedMessage
|
|
{
|
|
public WorldInterestChangedMessage(int version)
|
|
{
|
|
Version = version;
|
|
}
|
|
|
|
public int Version { get; }
|
|
}
|
|
}
|