Files
TheDeclineOfWarriors/Assets/Features/VoxelWorld/Contracts/NavMeshWorldContracts.cs
T
Alexander Borisov 0b380def78 refactor nav coverage into clustered windows
Replace region-based runtime pathing with interest-cluster coverage windows so active nav areas stay contiguous and spawn anchors participate in initial coverage.
2026-04-08 13:52:00 +03:00

147 lines
4.0 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 interface INavCoverageReader
{
bool IsPositionCovered(Vector3 worldPosition);
void GetCoverageWindows(List<NavCoverageWindowSnapshot> 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,
SpawnAnchor = 2,
Other = 3
}
public readonly struct NavCoverageWindowSnapshot
{
public NavCoverageWindowSnapshot(int id, Bounds bounds, NavCoverageState state, int interestCount)
{
Id = id;
Bounds = bounds;
State = state;
InterestCount = interestCount;
}
public int Id { get; }
public Bounds Bounds { get; }
public NavCoverageState State { get; }
public int InterestCount { get; }
}
public enum NavCoverageState
{
Pending = 0,
Building = 1,
Ready = 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; }
}
}