enemy spawner
This commit is contained in:
47
Game/Scripts/Runtime/Navigation/NavMeshRuntimeUtility.cs
Normal file
47
Game/Scripts/Runtime/Navigation/NavMeshRuntimeUtility.cs
Normal file
@@ -0,0 +1,47 @@
|
||||
using System;
|
||||
using UnityEngine.AI;
|
||||
|
||||
namespace Game.Scripts.Runtime.Navigation
|
||||
{
|
||||
/// <summary>
|
||||
/// Lightweight cache around NavMesh availability checks so gameplay code
|
||||
/// can gracefully degrade when a bake is not present.
|
||||
/// </summary>
|
||||
public static class NavMeshRuntimeUtility
|
||||
{
|
||||
private static bool? _cachedHasNavMesh;
|
||||
|
||||
/// <summary>
|
||||
/// Returns true if there is any baked NavMesh data loaded at runtime.
|
||||
/// Result is cached until <see cref="InvalidateCache"/> is called.
|
||||
/// </summary>
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Clears the cached NavMesh availability state. Call this after baking at runtime.
|
||||
/// </summary>
|
||||
public static void InvalidateCache()
|
||||
{
|
||||
_cachedHasNavMesh = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user