ChunkPrefabPointer
A class in Root.Township, Alta.Chunks.
Points at static chunk content loaded through Addressables. The static methods reference count which chunks use each piece and spawn or destroy it a little each frame, within a time budget.
- Listed in World, chunks and saving
- Inherits or implements
ScriptableObject - Derived types
NormalPrefabPointer - Nested types
PointerInstance
Constructors
| Member | What it is |
|---|---|
ChunkPrefabPointer() | Use ScriptableObject.CreateInstance instead of new; Unity loads the saved ones from assets. |
Fields
10 private and internal fields
| Member | What it is |
|---|---|
private uint id | Backing field for Identifier. |
private static Dictionary<string, ChunkPrefabPointer.PointerInstance> inRam | Addressable pointer instances currently loaded, keyed by asset reference. |
private static ChunkPrefabPointer.PointerInstance lastSpawned | The pointer instance LoadNext last tried to spawn. |
private static Logger logger | NLog logger for this class. |
private static Transform pointerFolder | Parent transform named "Static Objects" for spawned pointer prefabs. |
private GameObject prefab | Backing field for Prefab. |
private static List<ChunkPrefabPointer.PointerInstance> spawnedPointer | Pointers spawned in the current LoadNext pass, whose load tasks get completed at the end of it. |
private static Stopwatch stopwatch | Times each LoadAndUnload pass against its millisecond allowance. |
private static Queue<ChunkPrefabPointer.PointerInstance> waitingForLoad | Pointer instances that a chunk started using and that still need spawning. |
private static Queue<ChunkPrefabPointer.PointerInstance> waitingForUnload | Spawned pointer instances that no chunk uses any more and that wait to be destroyed. |
Properties
Methods
| Member | What it is |
|---|---|
static T CreatePointer<T>(DirectoryInfo pointersFolder, uint pointerIndex) | Editor helper to create a pointer asset. Returns null in this build. |
static string GetPointersResourcesPath(uint index) | The resources path for a pointer index, under PointersResourcesFolder. |
static void LoadAndUnload(float allowance) | Spawns queued content then destroys unused content until the time allowance (ms) runs out. Called by StreamerManager every frame. |
static async void Unuse(string reference, Chunk chunk) | Drops a chunk's use of the content. When nothing uses it, it is queued to despawn and the asset is released. |
static async Task Use(string reference, Chunk chunk) | Loads the Addressable asset if needed and records the chunk as a user, queueing it to spawn on first use. |
static async Task UseOld(AssetReference reference, Chunk chunk) | Older version of Use that takes an AssetReference. |
static async Task WaitForLoad(string reference) | Waits until used content has spawned. Logs an error if Use was not called first. |
4 private and internal methods
| Member | What it is |
|---|---|
private static void ClearStaticPointerInstances() | Clears the loaded-pointer caches and queues. Hooked to ApplicationManager.GameReload in the static constructor. |
private static void EnsurePointerFolderExists() | Creates the "Static Objects" parent object if it doesn't exist yet. |
private static void LoadNext(float allowance) | Spawns queued pointer prefabs until the time allowance runs out, then completes their load tasks. Called by LoadAndUnload. |
private static void UnloadNext(float allowance) | Destroys spawned pointer prefabs that no chunk uses any more, until the time allowance runs out. Called by LoadAndUnload. |
Used in
Members of other types that take, return or hold a ChunkPrefabPointer: