public bool CanAgentEnter(int id, Point3 pos, bool finalDestination)
{
_threadLock.EnterUpgradeableReadLock();
if (!_cells.TryGetValue(pos, out var cell) || !cell.IsWalkable)
{
_threadLock.ExitUpgradeableReadLock();
return(false);
}
if (cell.IsOccupied && cell.Occupied == id)
{
_threadLock.ExitUpgradeableReadLock();
return(true);
}
if (finalDestination && cell.IsOccupied && cell.Occupied != id)
{
_threadLock.ExitUpgradeableReadLock();
return(false);
}
if (cell.IsTempLocked && cell.TempLock != id)
{
_threadLock.ExitUpgradeableReadLock();
return(false);
}
_threadLock.EnterWriteLock();
cell.TempLock = id;
SetCellCostInternal(cell);
_threadLock.ExitWriteLock();
_threadLock.ExitUpgradeableReadLock();
return(true);
}