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;// = new List(); private void Awake() { UpdateComponentInfo(); } private void UpdateComponentInfo() { names = GetComponentsInChildren().ToList(); Debug.Assert(names != null,this); //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); } } }