Skip to main content

StorageOrganizer

A class in Root.Township, Alta.Inventory.

Shows a storage dock's contents as a baked stack of item meshes (such as a pile of logs on a rack), with a matching collider, and draws it only while visible. Component next to the dock on storage prefabs; both sides bake the collider, only clients draw.

Constructors​

MemberWhat it is
StorageOrganizer()Unity makes components itself; use AddComponent or spawn a prefab instead of new.

Fields​

17 private and internal fields
MemberWhat it is
private Matrix4x4 androidMeshPositionWorld matrix the stack is drawn and laid out with.
private Bounds boundsLocal box the items are stacked inside.
private Mesh collisionMeshMesh baked into the collider: the item's collision mesh, or its first rendering mesh.
private int cullingIndexIndex of this stack's sphere in the culling group.
private int currentQuantityHow many item meshes are shown now.
private PickupDock dockThe dock whose contents are shown.
private AnimationCurve dockedToItemsCurve from stored quantity to the number of meshes shown.
private bool hasDynamicVisibilityUse the visibility detector instead of a static culling sphere, for storage that moves.
private BoxCollider interactionColliderBox collider resized to fit the baked stack.
private static Logger loggerLogger for this class.
private Material[] materialsMaterials for each rendering mesh, from the item's renderers.
private MeshCollider meshColliderCollider that gets the baked stack mesh.
private Mesh[] meshesThe item's source meshes, one per rendering filter.
private IUnityUpdateMethod renderHandle for the per-frame Render call.
private Mesh[] renderingMeshesBaked stack meshes drawn on clients.
private StackingInstructionSetup stackingSetupLayout from the item's StackingComponent, holding the item positions and max count.
private VisibilityDetector visibilityDetectorDetector used when hasDynamicVisibility is on.

Methods​

16 private and internal methods
MemberWhat it is
private void Awake()Turns the colliders off and hooks the dock's quantity, docked and undocked events.
private void BecameInvisible()Stops drawing when the visibility detector says the stack is off screen.
private void BecameVisible()Starts drawing each frame when the visibility detector says the stack is on screen.
private void CheckQuantities()Works out how many items to show from the stored quantity and rebakes the collider and rendering meshes when that changes.
private void Clean(Interactor interactor, Pickup pickup, PickupDock dock)On undock, clears the setup once the dock is empty.
private void CleanStaticVisibility()Removes this stack's sphere from the culling group.
private void ClearSetup()Forgets the stacking setup, sets the shown count to 0 and turns the colliders off.
private void IUpdateOnMove.Moved()When the storage is moved, re-registers its culling sphere at the new spot (static visibility only).
private void OnDestroy()Frees the baked meshes and unhooks visibility and the draw call.
private void OnDrawGizmosSelected()Editor: draws the stacking bounds as a wire box.
private void Render()Draws the baked meshes each frame while visible, updating positions first if the storage has moved.
private void SetMeshEnabled(bool isEnabled)Turns the mesh collider and interaction collider on or off.
private void Setup(Interactor interactor, Pickup pickup, PickupDock dock)When an item is first docked, reads its StackingComponent meshes and materials and builds the stacking layout for bounds.
private void SetupStaticCulling()Registers a culling sphere around the bounds so UpdateVisibility starts and stops drawing.
private void Start()Client: hooks the visibility detector when hasDynamicVisibility is on.
private void UpdateVisibility(CullingGroupEvent sphere)Culling group callback: starts drawing when the sphere becomes visible, stops otherwise.