Files
unity-zone-system/Runtime/ZonesObjectHolder.cs
Sebastian Bularca 823e146df0 copy from github
2026-03-27 15:13:27 +01:00

36 lines
938 B
C#

using System.Collections.Generic;
using UnityEngine;
namespace Jovian.ZoneSystem {
public class ZonesObjectHolder: MonoBehaviour {
internal List<ZoneInstance> Zones { get; } = new();
public MapPlane mapPlane;
public IReadOnlyList<ZoneInstance> AllZones => Zones;
private void Awake() {
Refresh();
}
#if UNITY_EDITOR
private void OnValidate() {
Refresh();
}
#endif
/// <summary>
/// Re-scans the scene for all ZoneInstances and rebuilds their bounds caches.
/// Call this if you add or remove zones at runtime.
/// </summary>
private void Refresh() {
Zones.Clear();
var found = FindObjectsByType<ZoneInstance>(FindObjectsSortMode.None);
foreach(var z in found) {
z.RebuildBoundsCache();
Zones.Add(z);
}
}
}
}