Detailed Method Reference

Namespace: Canley.Utility.CSV.Standard
Class: CSVTable<T>

Definition

public void SpawnUI(List<T> data, GameObject prefab, Transform parent)
  • Description: Instantiates UI prefabs for a collection of records and populates them using components that implement the displayable interface.

  • Workflow:

    1. Null Guard: Validates that the data list, prefab object, and parent transform are all non-null before proceeding.
    2. Iteration: Loops through each record instance within the provided collection.
    3. Instantiation & Binding: Spawns a game object instance of the prefab under the target parent transform, queries it for an ICSVDisplayable<T> component, and passes the record data to it for visual rendering.
  • Parameters:

    • data: The list of strongly-typed records to instantiate UI elements for.
    • prefab: The UI template GameObject containing a display script.
    • parent: The parent Transform container where the instantiated UI elements will be placed.
  • Returns: void

  • Example:

public void PopulateInventoryList(CSVTable<ItemRecord> itemTable, GameObject itemRowPrefab, Transform contentPanel)
{
    var activeItems = itemTable.GetRecords(i => i.isUnlocked);
    itemTable.SpawnUI(activeItems, itemRowPrefab, contentPanel);
    Debug.Log(message: "Spawned UI elements for unlocked inventory items.");
}

TIP

Make sure your UI prefab features a component implementing ICSVDisplayable<T> so the method can automatically wire up the record data to your UI elements upon instantiation.