0b380def78
Replace region-based runtime pathing with interest-cluster coverage windows so active nav areas stay contiguous and spawn anchors participate in initial coverage.
81 lines
2.3 KiB
C#
81 lines
2.3 KiB
C#
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;
|
|
}
|
|
|
|
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;
|
|
}
|
|
}
|
|
|
|
VoxelWorldSpawnAnchor[] spawnAnchors = FindObjectsByType<VoxelWorldSpawnAnchor>(FindObjectsInactive.Exclude, FindObjectsSortMode.None);
|
|
for (int i = 0; i < spawnAnchors.Length; i++)
|
|
{
|
|
VoxelWorldSpawnAnchor anchor = spawnAnchors[i];
|
|
if (anchor != null && anchor.isActiveAndEnabled)
|
|
{
|
|
return anchor.transform;
|
|
}
|
|
}
|
|
|
|
return null;
|
|
}
|
|
|
|
private void ApplyResolvedTarget(Transform resolvedTarget)
|
|
{
|
|
if (currentStreamTarget == resolvedTarget)
|
|
{
|
|
return;
|
|
}
|
|
|
|
currentStreamTarget = resolvedTarget;
|
|
if (worldGenerator != null)
|
|
{
|
|
worldGenerator.SetStreamTarget(currentStreamTarget);
|
|
}
|
|
}
|
|
}
|
|
}
|