Get RAPTOR

RaptorModelNameReservers

Lets a module reserve model names.

NamespaceAssemblyKindStability
Raptor.EditorToolsRaptor.Editorclasspreview, since 0.1.0

A reserver is a test for model names that are used by something RAPTOR does not track, such as a file a module exports under that name. RaptorModelPlacement.NameTaken treats a reserved name as taken, so new models and variants cannot use it.

A reserver without a scope applies to every model name. A scoped reserver applies only when a caller passes that scope to RaptorModelPlacement.NameTaken. Use a scope for names that clash with one kind of model, such as a module's vehicle exports.

The first registration of an id wins and later ones do nothing, so a registrant can safely run twice. A reserver that throws is logged once per id, and the name is treated as reserved. The registry is editor-only and is cleared on domain reload, after which the registrants run again.

public static class RaptorModelNameReservers

Properties

Count

public static int Count { get; }

The number of reservers.

Ids

public static IReadOnlyList<string> Ids { get; }

A snapshot of every reserver id, in registration order.

Version

public static int Version { get; }

Increments on every change.

Methods

IsRegistered

public static bool IsRegistered(string id)

Whether a reserver with this id is registered.

ParameterTypeDescription
idstringThe reserver's stable id.

Returns: True when registered.

IsReserved

public static bool IsReserved(string name)

Whether an unscoped reserver reserves name.

ParameterTypeDescription
namestringThe name.

Returns: True when the name is reserved.

IsReserved

public static bool IsReserved(string name, string scope)

Whether an unscoped reserver, or one registered for scope, reserves name.

ParameterTypeDescription
namestringThe name.
scopestringThe scope, or null or empty to check only unscoped reservers.

Returns: True when the name is reserved.

Register

public static bool Register(string id, Func<string, bool> isReserved, string scope = null)

Adds a reserver. When scope is null or empty, the reserver applies to every model name. Otherwise it applies only to callers that pass that scope. Returns false and keeps the existing reserver when id is already registered.

ParameterTypeDefaultDescription
idstringThe reserver's stable id.
isReservedFunc<string, bool>Returns true when the name is reserved.
scopestringnullThe scope, or null or empty to apply to every name.

Returns: False when the id is taken.

Call from an [InitializeOnLoad] static constructor on the main thread.

TryGetScope

public static bool TryGetScope(string id, out string scope)

Gets the scope a reserver was registered with.

ParameterTypeDescription
idstringThe reserver's stable id.
scopeout stringThe scope, or null or empty when the reserver applies to every name.

Returns: False when the id is unknown.