You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
43 lines
1.5 KiB
43 lines
1.5 KiB
using System;
|
|
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using UnityEngine;
|
|
/// <summary>
|
|
/// 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.
|
|
/// </summary>
|
|
public class ViewItemInfoPanel : MonoBehaviour
|
|
{
|
|
private List<ItemNameDisplay> names;// = new List<ItemNameDisplay>();
|
|
private void Awake()
|
|
{
|
|
UpdateComponentInfo();
|
|
}
|
|
|
|
private void UpdateComponentInfo()
|
|
{
|
|
names = GetComponentsInChildren<ItemNameDisplay>().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);
|
|
}
|
|
}
|
|
}
|
|
|