PrefabLibrary
namespace Griff.Runtime;
public sealed class PrefabLibraryCreates entities from a project’s prefab files, for PrefabLoader. Each prefab is read once into a fixed template (EntityTemplate) and every spawn is a copy of it, so spawning reads no file and parses no JSON. Where the files come from says whether they change (IAssetSource): an exported game’s never do; in the editor, a prefab saved while a game plays is read again and the next spawn is of the new version (Changed says so). One library is safe to spawn from on any number of threads at once (a balance simulation’s games, each on its own core).
Methods
Section titled “Methods”Dispose
Section titled “Dispose”public void Dispose()Stops listening for changes to the files.
Instantiate
Section titled “Instantiate”public Entity Instantiate(string nameOrPath)A new entity from the prefab named nameOrPath (“Bullet” or “Prefabs/Bullet.prefab”).
Remember
Section titled “Remember”public void Remember(string path, PrefabVersion version)Says the prefab file at path is now version, written by the editor itself, which has brought its copies up to date already: the next spawn is of it, and its file settling isn’t a change.
VersionOf
Section titled “VersionOf”public PrefabVersion? VersionOf(string path)The version of the prefab file at path (a full path) as this library has it: read now if it hasn’t been, and kept until the file changes. Null if there’s no such file or it isn’t JSON.
Events
Section titled “Events”Changed
Section titled “Changed”public event Action<PrefabChange>? ChangedRaised when a prefab file is found to be another version than the one last read (or made, or deleted): saved in the editor, written by an agent, or changed outside it (a pull, a text editor). Not raised for a version the editor said it wrote (Remember). It may come on any thread.