-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathIngredientInventoryDisplay.cs
43 lines (32 loc) · 1.1 KB
/
IngredientInventoryDisplay.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class IngredientInventoryDisplay : MonoBehaviour {
public Transform targetTransform;
public BaseIngredientDisplay ingredientDisplayPrefab;
public IngredientInventory IInventory;
void Start () {
IngredientInventory.onChanged += HandleonChanged;
}
void OnDestroy() {
IngredientInventory.onChanged -= HandleonChanged;
}
void HandleonChanged (IngredientInventory IInventory) {
if (this.IInventory == IInventory)
Prime (IInventory);
}
void Update () {
}
public void Prime(IngredientInventory IInventory) {
for (int i = 0; i < targetTransform.childCount; i++) {
Destroy(targetTransform.GetChild(i).gameObject);
}
this.IInventory = IInventory;
List<BaseIngredient> ingredients = IInventory.ingredients;
foreach (BaseIngredient ingredient in ingredients) {
BaseIngredientDisplay display = (BaseIngredientDisplay)Instantiate(ingredientDisplayPrefab);
display.transform.SetParent(targetTransform, false);
display.Prime(ingredient);
}
}
}