thewar_client/Client/Assets/1_Script/System/GetItemWindows.cs

111 lines
3.1 KiB
C#

using System.Collections.Generic;
using UnityEngine;
public class GetItemWindows : SingletonMonoBehaviour<GetItemWindows>
{
//아이템 획득 정보 필요
//아이템 이펙트
[SerializeField] GameObject itemImgPrefab;
[SerializeField] Transform content;
List<GameObject> items = new List<GameObject>();
RectTransform rect;
private bool isAnim = false;
private readonly float minWidth = 1600f;
private readonly float boxSize = 150f;
private readonly float spacing = 50f;
protected override void OnAwake()
{
gameObject.SetActive(false);
rect = content.GetComponent<RectTransform>();
for (int n = 0; n < 50; n++)
{
items.Add(Instantiate(itemImgPrefab, content));
items[n].SetActive(false);
}
}
public void SetUI(long addGold, long addCash, List<DeckUnitInfo> deckUnit, List<Equipment> equipment, List<ConsumableItem> consumableItem, List<EtcItem> etcItem)
{
isAnim = true;
gameObject.SetActive(true);
int num = 0;
if (addGold > 0)
{
Debug.Log($"{addGold}골드 획득!");
items[num++].SetActive(true);
}
if (addCash > 0)
{
Debug.Log($"{addCash}케쉬 획득!");
items[num++].SetActive(true);
}
if (deckUnit != null && deckUnit.Count != 0)
{
for(int n = 0; n < deckUnit.Count; n++)
{
Debug.Log($"{deckUnit[n].unit_data_id}케릭터 획득!");
items[num++].SetActive(true);
}
}
if (equipment != null && equipment.Count != 0)
{
for (int n = 0; n < equipment.Count; n++)
{
Debug.Log($"{equipment[n].equipment_data_id}장비 획득!");
items[num++].SetActive(true);
}
}
if (consumableItem != null && consumableItem.Count != 0)
{
for (int n = 0; n < consumableItem.Count; n++)
{
Debug.Log($"{consumableItem[n].consumable_item_data_id}아이탬 {consumableItem[n].count}개획득!");
items[num++].SetActive(true);
}
}
if (etcItem != null && etcItem.Count != 0)
{
for (int n = 0; n < etcItem.Count; n++)
{
Debug.Log($"{etcItem[n].etc_item_data_id}아이탬 {etcItem[n].count}개획득!");
items[num++].SetActive(true);
}
}
//임시
float size = (boxSize * num) + (spacing * num);
rect.offsetMin = Vector2.zero;
rect.offsetMax = new Vector2(minWidth < size ? size : minWidth, 0);
isAnim = false;
}
public void OnExit()
{
for (int n = 0; n < items.Count; n++)
{
if (items[n].activeSelf)
items[n].SetActive(false);
else
break;
}
if (!isAnim)
gameObject.SetActive(false);
}
[ContextMenu("test")]
public void test()
{
Debug.Log(content.GetComponent<RectTransform>().offsetMin);
Debug.Log(content.GetComponent<RectTransform>().offsetMax);
}
}