using System; using System.Collections; using System.Collections.Generic; using System.Linq; using UnityEngine; /// /// This component searches all children for a bunch of other components such as names, descriptions, stats, etc /// and updates them with all necessary information whenever it is updated. /// It is assumed that children of a view info panel never get destroyed separately, as it is treated as one object. /// Similarly, it is assumed that all children already exist at the time of startup. /// public class ViewItemInfoPanel : MonoBehaviour { private List names; private List stats; private List types; private List prices; private List descr; private List rarity; private void Awake() { UpdateComponentInfo(); } private void UpdateComponentInfo() { names = GetComponentsInChildren().ToList(); Debug.Assert(names != null,this); stats = GetComponentsInChildren().ToList(); types = GetComponentsInChildren().ToList(); prices = GetComponentsInChildren().ToList(); descr = GetComponentsInChildren().ToList(); rarity = GetComponentsInChildren().ToList(); //if (names == null) names = ; // TODO: Create and add all other types in here as components! } // When this is set, it updates all relevant game objects to reflect the item's propertiese. public void SetItemInfo(Item item) { if (item == null) { gameObject.SetActive(false); // If the seelcted item doesn't exist, disable the whole panel return; } if(names == null) UpdateComponentInfo(); // Assume that if the names component is null, we probably never initialised //gameObject.SetActive(true); foreach (var name in names) { name.SetName(item.name); } foreach (var itemStatsDisplay in stats) { itemStatsDisplay.SetStats(item.GetStats()); } foreach (var type in types) { type.SetType(item.GetItemType().ToString()); } foreach (var price in prices) { price.SetPrice(item.basePrice); // TODO: Price modifier here! } foreach (var descriptionDisplay in descr) { descriptionDisplay.SetDescription(item.description); } foreach (var itemClass in rarity) { itemClass.SetClass(item.rarity); } } }