using System; using UnityEngine.AI; namespace Game.Scripts.Runtime.Navigation { /// /// Lightweight cache around NavMesh availability checks so gameplay code /// can gracefully degrade when a bake is not present. /// public static class NavMeshRuntimeUtility { private static bool? _cachedHasNavMesh; /// /// Returns true if there is any baked NavMesh data loaded at runtime. /// Result is cached until is called. /// public static bool HasNavMeshData() { if (_cachedHasNavMesh.HasValue) { return _cachedHasNavMesh.Value; } try { var triangulation = NavMesh.CalculateTriangulation(); var hasData = triangulation.vertices != null && triangulation.vertices.Length > 0; _cachedHasNavMesh = hasData; return hasData; } catch (Exception) { _cachedHasNavMesh = false; return false; } } /// /// Clears the cached NavMesh availability state. Call this after baking at runtime. /// public static void InvalidateCache() { _cachedHasNavMesh = null; } } }