Skip to main content

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.

Constructors​

MemberWhat it is
ChunkPrefabPointer()Use ScriptableObject.CreateInstance instead of new; Unity loads the saved ones from assets.

Fields​

10 private and internal fields
MemberWhat it is
private uint idBacking field for Identifier.
private static Dictionary<string, ChunkPrefabPointer.PointerInstance> inRamAddressable pointer instances currently loaded, keyed by asset reference.
private static ChunkPrefabPointer.PointerInstance lastSpawnedThe pointer instance LoadNext last tried to spawn.
private static Logger loggerNLog logger for this class.
private static Transform pointerFolderParent transform named "Static Objects" for spawned pointer prefabs.
private GameObject prefabBacking field for Prefab.
private static List<ChunkPrefabPointer.PointerInstance> spawnedPointerPointers spawned in the current LoadNext pass, whose load tasks get completed at the end of it.
private static Stopwatch stopwatchTimes each LoadAndUnload pass against its millisecond allowance.
private static Queue<ChunkPrefabPointer.PointerInstance> waitingForLoadPointer instances that a chunk started using and that still need spawning.
private static Queue<ChunkPrefabPointer.PointerInstance> waitingForUnloadSpawned pointer instances that no chunk uses any more and that wait to be destroyed.

Properties​

MemberWhat it is
static int CurrentlyLoaded { get; }How many pointed-to prefabs are spawned right now.
uint Identifier { get; }The pointer's ID.
static string PointersResourcesFolder { get; }PointersRepository, or Android/PointersRepository on Android.
GameObject Prefab { get; }The prefab this pointer stands for.

Methods​

MemberWhat 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
MemberWhat 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: