Files
TheDeclineOfWarriors/Assets/Scripts/VoxelWorld/SceneWorldInterestReader.cs
T
Alexander Borisov 1681e44c5e add documentation
2026-04-08 20:58:33 +03:00

69 lines
2.2 KiB
C#

using System.Collections.Generic;
using InfiniteWorld.VoxelWorld;
using InfiniteWorld.VoxelWorld.Contracts;
using UnityEngine;
namespace VoxelWorldScene
{
/// <summary>
/// Combines the world generator's current stream target with scene spawn anchors into one interest feed for nav coverage.
/// </summary>
public sealed class SceneWorldInterestReader : IWorldInterestReader
{
private readonly VoxelWorldGenerator worldGenerator;
private VoxelWorldSpawnAnchor[] spawnAnchors;
private int lastAnchorRefreshFrame = -1;
public SceneWorldInterestReader(VoxelWorldGenerator worldGenerator)
{
this.worldGenerator = worldGenerator;
}
/// <summary>
/// Mirrors the generator's interest version so downstream systems can invalidate cached plans when scene interest changes.
/// </summary>
public int InterestVersion => worldGenerator != null ? worldGenerator.InterestVersion : 0;
/// <summary>
/// Appends both dynamic actor interest and static spawn-anchor interest into the supplied list.
/// </summary>
public void GetInterestPoints(List<WorldInterestPoint> results)
{
if (results == null)
{
return;
}
worldGenerator?.GetInterestPoints(results);
RefreshSpawnAnchors();
if (spawnAnchors == null)
{
return;
}
for (int i = 0; i < spawnAnchors.Length; i++)
{
VoxelWorldSpawnAnchor anchor = spawnAnchors[i];
if (anchor == null || !anchor.isActiveAndEnabled)
{
continue;
}
results.Add(new WorldInterestPoint(anchor.transform.position, anchor.Priority, WorldInterestKind.SpawnAnchor));
}
}
private void RefreshSpawnAnchors()
{
if (lastAnchorRefreshFrame == Time.frameCount)
{
return;
}
lastAnchorRefreshFrame = Time.frameCount;
spawnAnchors = Object.FindObjectsByType<VoxelWorldSpawnAnchor>(FindObjectsInactive.Exclude, FindObjectsSortMode.None);
}
}
}