NLDClient-yudde/ProjectNLD/Assets/Code/Scripts/Gameplay/UI/GiftCode/UIGiftCodeAwardsController.cs

94 lines
2.1 KiB
C#

using Framework;
using Gameplay;
using TMPro;
using UnityEngine;
using Button = UnityEngine.UI.Button;
public class UIGiftCodeAwardsController: UIWindow
{
//UI GameObj
///Auto Gen Start///
private Button mSureBtn;
private Button mCloseBtn;
private ItemCounts mItems;
///Auto Gen End///
// Use this for initialization
public override void PreLoad(object data = null)
{
base.PreLoad(data);
mItems=data as ItemCounts;
}
public override void OnInit()
{
//bind UI GameObj
mSureBtn= GetComponent<Button>("bg/SureBtn");
mCloseBtn = GetComponent<Button>("ReturnBtn");
BindButton(mSureBtn, OnSureBtnClose);
BindButton(mCloseBtn, OnReturnBtnClose);
}
private void OnReturnBtnClose()
{
CloseWindow();
}
private void OnSureBtnClose()
{
CloseWindow();
}
//invoke when open window
protected override void OnShowWindow(object data = null)
{
if (data != null)
{
mItems=data as ItemCounts;
}
RefreshMaterial(mItems);
}
private async void RefreshMaterial(ItemCounts mItems)
{
string allName = "";
for (int i = 0; i < 3; i++)
{
GameObject itemParent = FindObj(string.Format("UI_Materals/{0}", (i + 1).ToString()));
CommonUtils.DestoryAllChildGameObject(CommonUtils.GetGameObject(itemParent, "item"));
if (i < mItems.Ids.Count)
{
itemParent.SetActive(true);
ItemObj itemObj = new ItemObj((int)mItems.Ids[i], CommonUtils.GetGameObject(itemParent, "item"));
await itemObj.Init();
//CommonUtils.GetComponent<TMP_Text>(itemParent, "value").text = mItems.Counts[i].ToString();
allName += TableManager.Instance.Tables.Item.Get((int)mItems.Ids[i]).ID+"X"+ mItems.Counts[i];
}
else
{
itemParent.SetActive(false);
}
}
GetComponent<TMP_Text>("Text_AwardsText").text = allName;
}
//invoke when reload window
protected override void OnReloadWindow(object data = null)
{
}
public override void OnRelease()
{
base.OnRelease();
}
}