add voxel world runtime navmesh sidecar
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.
This commit is contained in:
@@ -0,0 +1,75 @@
|
||||
using InfiniteWorld.VoxelWorld;
|
||||
using Players;
|
||||
using UnityEngine;
|
||||
|
||||
namespace VoxelWorldScene
|
||||
{
|
||||
[DisallowMultipleComponent]
|
||||
[RequireComponent(typeof(VoxelWorldGenerator))]
|
||||
public sealed class VoxelWorldPlayerStreamTargetBinding : MonoBehaviour
|
||||
{
|
||||
[SerializeField] private VoxelWorldGenerator worldGenerator;
|
||||
[SerializeField] private Transform explicitStreamTarget;
|
||||
|
||||
private Transform currentStreamTarget;
|
||||
|
||||
private void Awake()
|
||||
{
|
||||
if (worldGenerator == null)
|
||||
{
|
||||
worldGenerator = GetComponent<VoxelWorldGenerator>();
|
||||
}
|
||||
|
||||
ApplyResolvedTarget(ResolveTarget());
|
||||
}
|
||||
|
||||
private void Update()
|
||||
{
|
||||
ApplyResolvedTarget(ResolveTarget());
|
||||
}
|
||||
|
||||
private void OnDisable()
|
||||
{
|
||||
ApplyResolvedTarget(null);
|
||||
}
|
||||
|
||||
private Transform ResolveTarget()
|
||||
{
|
||||
if (explicitStreamTarget != null)
|
||||
{
|
||||
return explicitStreamTarget;
|
||||
}
|
||||
|
||||
if (currentStreamTarget != null)
|
||||
{
|
||||
return currentStreamTarget;
|
||||
}
|
||||
|
||||
CameraFollow[] cameraFollows = FindObjectsByType<CameraFollow>(FindObjectsInactive.Exclude, FindObjectsSortMode.None);
|
||||
for (int i = 0; i < cameraFollows.Length; i++)
|
||||
{
|
||||
CameraFollow follow = cameraFollows[i];
|
||||
if (follow != null && follow.IsOwner)
|
||||
{
|
||||
return follow.Target;
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
private void ApplyResolvedTarget(Transform resolvedTarget)
|
||||
{
|
||||
if (currentStreamTarget == resolvedTarget)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
currentStreamTarget = resolvedTarget;
|
||||
if (worldGenerator != null)
|
||||
{
|
||||
worldGenerator.SetStreamTarget(currentStreamTarget);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user