Skip to content

Class PrefabLibrary

Namespace: Apogee.Ecs
Assembly: Apogee.Ecs.dll

The prefab files a session knows, as numbers: one handle per file (the same file asked for by its path, its uid:// or both is the same handle), and each file's document, read once. A handle is what and hold; it only means something in the run that made it, which is why snapshots and scenes name the file instead (). A reference that names no file still gets a handle that keeps its text, so an instance of a prefab that is missing keeps what it was made from. Safe to use from several threads.

public sealed class PrefabLibrary

Inheritance

object ← PrefabLibrary

Inherited Members

object.Equals(object?), object.Equals(object?, object?), object.GetHashCode(), object.GetType(), object.ReferenceEquals(object?, object?), object.ToString()

Constructors

PrefabLibrary(VirtualFileSystem, AssetDatabase?)

The prefab files a session knows, as numbers: one handle per file (the same file asked for by its path, its uid:// or both is the same handle), and each file's document, read once. A handle is what and hold; it only means something in the run that made it, which is why snapshots and scenes name the file instead (). A reference that names no file still gets a handle that keeps its text, so an instance of a prefab that is missing keeps what it was made from. Safe to use from several threads.

public PrefabLibrary(VirtualFileSystem files, AssetDatabase? assets)

Parameters

files VirtualFileSystem

Where prefab files are read from and written to.

assets AssetDatabase?

Finds the file a uid:// names (and a prefab that moved); null: only paths are understood.

Methods

Document(uint)

The document of the prefab, read once and kept: the root Prefab element. Null when the handle is not one of this library's or names no file.

public XmlNode? Document(uint handle)

Parameters

handle uint

Returns

XmlNode?

Exceptions

FormatException

The file exists but cannot be read as an XML document (text or cooked).

Load(string)

The handle of the prefab that pathOrRef names: a path (res://prefabs/lamp.aprefab), a uid://…, or path|uid://…. The same file always gives the same handle. A reference that names no file gives a handle too (its is null), so that it can be saved and asked for again; the file is looked for again each time it is asked.

public uint Load(string pathOrRef)

Parameters

pathOrRef string

Returns

uint

Exceptions

FormatException

The text is not an asset reference.

Load(AssetRef)

The handle of the prefab that reference names, or 0 for the empty reference. See .

public uint Load(AssetRef reference)

Parameters

reference AssetRef

Returns

uint

PathOf(uint)

The path of the file a handle names, or null when there is none (the reference names no file that exists) or the handle is not one of this library's.

public string? PathOf(uint handle)

Parameters

handle uint

Returns

string?

RefOf(uint)

The reference a handle names: the file's path and UID, or, when no file has been found for it, the reference it was asked for. Null for a handle this library did not give.

public AssetRef? RefOf(uint handle)

Parameters

handle uint

Returns

AssetRef?

Changed

Raised after the file of a prefab was written by this library's world (see ), with its handle: what an instance of it was made from has changed.

public event Action<uint>? Changed

Event Type

Action<uint>?