112 lines
3.1 KiB
C#
112 lines
3.1 KiB
C#
using System;
|
|
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using Sirenix.OdinInspector;
|
|
using TMPro;
|
|
using UnityEngine;
|
|
using UnityEngine.UI;
|
|
|
|
namespace Beyond {
|
|
public class ItemMenu : MonoBehaviour
|
|
{
|
|
[SerializeField]
|
|
private ItemMenuButton m_itemMenuButtonPrefab;
|
|
[SerializeField]
|
|
private ItemObject[] m_items;
|
|
[SerializeField]
|
|
private TextMeshProUGUI m_itemName;
|
|
[SerializeField]
|
|
private TextMeshProUGUI m_description;
|
|
[SerializeField]
|
|
private TextMeshProUGUI m_itemStats;
|
|
[SerializeField]
|
|
private TextMeshProUGUI m_itemBonuses;
|
|
[SerializeField]
|
|
private RectTransform m_buttonListObject;
|
|
[SerializeField]
|
|
private Image m_image;
|
|
|
|
// Start is called before the first frame update
|
|
|
|
// Start is called before the first frame update
|
|
void ClearChildren(RectTransform root)
|
|
{
|
|
List<GameObject> objs = new List<GameObject>();
|
|
for (int i = 0; i < root.childCount; i++)
|
|
{
|
|
objs.Add(root.GetChild(i).gameObject);
|
|
}
|
|
foreach (var o in objs)
|
|
{
|
|
#if UNITY_EDITOR
|
|
DestroyImmediate(o);
|
|
#else
|
|
Destroy(o);
|
|
#endif
|
|
}
|
|
}
|
|
|
|
internal void OnItemClicked(ItemMenuButton itemMenuButton)
|
|
{
|
|
var item = itemMenuButton.m_itemObject;
|
|
m_itemName.text = item.name;
|
|
m_description.text = item.description;
|
|
string txt = "";
|
|
for (int i=0; i<item.bonuses.Length; i++)
|
|
{
|
|
txt += item.bonuses[i].ToString() + " ";
|
|
}
|
|
m_itemBonuses.text = txt;
|
|
for (int i = 0; i < item.stats.Length; i++)
|
|
{
|
|
txt += item.stats[i].ToString() + " ";
|
|
}
|
|
m_itemStats.text = txt;
|
|
m_image.sprite = item.image;
|
|
}
|
|
|
|
[Button]
|
|
void UpdateItems()
|
|
{
|
|
|
|
m_description.ForceMeshUpdate();
|
|
var size = m_description.GetRenderedValues(false);
|
|
m_description.rectTransform.SetSizeWithCurrentAnchors(RectTransform.Axis.Vertical, size.y);
|
|
}
|
|
|
|
// Start is called before the first frame update
|
|
[Button]
|
|
public void Populate()
|
|
{
|
|
if (m_items == null)
|
|
{
|
|
Debug.LogWarning("Items are null");
|
|
return;
|
|
}
|
|
if (m_itemMenuButtonPrefab == null)
|
|
{
|
|
Debug.LogWarning("m_itemMenuButtonPrefab slot is null");
|
|
return;
|
|
}
|
|
ClearChildren(m_buttonListObject);
|
|
for (int i = 0; i < m_items.Length; i++)
|
|
{
|
|
var item = Instantiate<ItemMenuButton>(m_itemMenuButtonPrefab, m_buttonListObject.transform);
|
|
item.SetItem(m_items[i]);
|
|
item.m_id = i;
|
|
}
|
|
}
|
|
|
|
void Start()
|
|
{
|
|
|
|
}
|
|
|
|
// Update is called once per frame
|
|
void Update()
|
|
{
|
|
|
|
}
|
|
}
|
|
}
|