06 Item Shop

This example scene is located in Assets/Plugins/Weaver/Examples/06 Meta Asset List. It demonstrates the use of a Meta Asset List to create a user interface that can display the details of its items without actually loading all the items into memory until they are needed.

  • ItemMetaData contains the details of an item (name, cost, description, etc.).
  • Item just holds an ItemMetaData field. It could have any other functionality, but all this example actually uses is the meta data.
  • Assets/Plugins/Weaver/Examples/06 Meta Asset List/All Items.asset is an Asset List. Specifically, an ItemList which inherits from MetaAssetList<Item, ItemMetaData>. It automatically gathers all prefabs with an Item component in the target folder when entering play mode or compiling a runtime build so they can be accessed efficiently as a simple list at runtime. When doing so it also retrieves the ItemMetaData of each Item and serializes that data alongside their resource paths so the meta-data of an Item can be accessed without loading the actual prefab.
  • ItemDisplay uses various UI components to show the details of an Item.
    • Note that everything will always show "Is Loaded" while in the Unity Editor, but they will only be loaded on demand in a runtime build. This ensures that the list always contains the correct references and data for the assets currently in the target directory while achieving the desired memory management at runtime.
  • ItemShop simply initializes an ItemDisplay for each Item in the ItemList.
  • This example could be adapted to any scenario where you want to access certain details of objects without loading them upfront:
    • A shop could use the item meta-data to sort and categorise entries, and only load ones that are currently visible.
    • A shop for custom character skins could show a preview image of each without loading the fully detailed character models.
    • An enemy spawning or loot drop system could act based on chance values in the meta-data.