RaptorModelNameReservers
Lets a module reserve model names.
| Namespace | Assembly | Kind | Stability |
|---|---|---|---|
Raptor.EditorTools | Raptor.Editor | class | preview, 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 RaptorModelNameReserversProperties
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.
| Parameter | Type | Description |
|---|---|---|
id | string | The reserver's stable id. |
Returns: True when registered.
IsReserved
public static bool IsReserved(string name)Whether an unscoped reserver reserves name.
| Parameter | Type | Description |
|---|---|---|
name | string | The 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.
| Parameter | Type | Description |
|---|---|---|
name | string | The name. |
scope | string | The 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.
| Parameter | Type | Default | Description |
|---|---|---|---|
id | string | The reserver's stable id. | |
isReserved | Func<string, bool> | Returns true when the name is reserved. | |
scope | string | null | The 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.
| Parameter | Type | Description |
|---|---|---|
id | string | The reserver's stable id. |
scope | out string | The scope, or null or empty when the reserver applies to every name. |
Returns: False when the id is unknown.
Related types
- RaptorModelPlacement: Free spots and free names for a new model.