using System;
namespace V3.Objects
{
///
/// Static helper class that generates unique IDs for game objects.
///
// ReSharper disable once ClassNeverInstantiated.Global
public sealed class IdGenerator
{
private static int sCurrentId;
private static int? sIdOnce;
private IdGenerator()
{
throw new NotImplementedException();
}
///
/// Get an ID for a new game object.
///
/// the ID to use for a new game object
public static int GetNextId()
{
int id;
if (sIdOnce.HasValue)
{
id = sIdOnce.Value;
ClearIdOnce();
}
else
{
id = sCurrentId;
sCurrentId++;
}
return id;
}
///
/// Sets the ID to use only for the next object that is created.
///
/// the id for the next object
public static void SetIdOnce(int id)
{
sIdOnce = id;
}
///
/// Clear the ID stored by SetIdOnce that is used only for the
/// next object.
///
public static void ClearIdOnce()
{
sIdOnce = null;
}
}
}