Example #1
0
    private void UpdateView()
    {
        // OPTIMIZATION: for now we don't care about optimize adding just one or removing one item,
        // so we rebuild the view completely (it's fine on Start, but may be nice to change for delta ops)
        // We are not even pooling item views.

        // destroy from temporary copy of children list to avoid invalidation issues (although Destroy is deferred)
        List <Transform> oldItemTransforms = grid.Cast <Transform>().ToList();

        foreach (var oldItemTr in oldItemTransforms)
        {
            Destroy(oldItemTr.gameObject);
        }

        // fill grid layout with all non-exposed items with non-0 quantity
        foreach (Item item in model.Items)
        {
            if (item.Quantity > 0 && !item.Exposed)
            {
                ItemView view = itemViewPrefab.InstantiateUnder(grid).GetComponentOrFail <ItemView>();
                view.SetInventoryView(this);
                view.AssignModel(item);
            }
        }

        RefreshInteractableState();
    }