mergemilitary/Assets/Scripts/UIs/CustomControl/DiamondList/DiamondList.cs

58 lines
1.4 KiB
C#
Raw Normal View History

2022-07-04 11:17:39 +00:00
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class DiamondList : ListView<DiamondCell>
{
public override int Count => TableIAP.Instance.Count;
private int mCurrentBuyIndex;
private void OnEnable()
{
#if USE_IAP
IAPTool.Instance.OnPurchaseDone += OnPurchaseResult;
#endif
}
private void OnDisable()
{
#if USE_IAP
IAPTool.Instance.OnPurchaseDone -= OnPurchaseResult;
#endif
}
protected override void ConfigCell(DiamondCell pCell)
{
pCell.DelPurchase = OnPurchase;
pCell.ConfigCell(TableIAP.Instance[pCell.Index]);
}
private void OnPurchase(int pIndex)
{
mCurrentBuyIndex = pIndex;
#if USE_IAP
IAPTool.Instance.BuyProductByID(TableIAP.Instance[pIndex].ProductID);
#endif
}
private void OnPurchaseResult(string pID, bool pResult)
{
#if USE_IAP
if (pResult)
{
DataIAP tData = TableIAP.Instance.GetData(pID);
if (tData != null)
{
PlayerData.Instance.Diamond += tData.DiamondNum;
UIUtils.FlyDiamond((mCellList[mCurrentBuyIndex] as DiamondCell).IconPos, tData.DiamondNum);
AudioManager.Instance.PlaySound(AudioClipType.GetCoin);
}
}
else
{
UIUtils.ShowTips(LanguageConfig.Instance.GetText("PayFail"));
}
#endif
}
}