63 lines
1.9 KiB
C#
63 lines
1.9 KiB
C#
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
|
|
public class PetList : ListView<PetCell>
|
|
{
|
|
public override int Count => TablePet.Instance.Count;
|
|
|
|
protected override void ConfigCell(PetCell pCell)
|
|
{
|
|
DataPet tData = TablePet.Instance[pCell.Index];
|
|
pCell.DelPurchase = OnBuyPet;
|
|
pCell.DelAd = OnAdPet;
|
|
pCell.DelUse = OnUsePet;
|
|
pCell.ConfigCell(tData, PlayerData.Instance.HasPet(tData.PetID), PlayerData.Instance.CurrentPetID == tData.PetID);
|
|
}
|
|
|
|
private void OnBuyPet(int pPetID)
|
|
{
|
|
DataPet tData = TablePet.Instance.GetData(pPetID.ToString());
|
|
|
|
if (PlayerData.Instance.Diamond >= tData.Price)
|
|
{
|
|
PlayerData.Instance.Diamond -= tData.Price;
|
|
UIUtils.DropDiamond(tData.Price);
|
|
|
|
PlayerData.Instance.GetPet(pPetID);
|
|
PlayerData.Instance.UsePet(pPetID);
|
|
|
|
PetManager.Instance.SetPet(PlayerData.Instance.CurrentPetID);
|
|
|
|
LoadData();
|
|
}
|
|
}
|
|
|
|
private void OnAdPet(int pPetID)
|
|
{
|
|
AdsUtils.PlayReward(Const.AdsValue.GetPet + "_" + pPetID.ToString(), () =>
|
|
{
|
|
int tCount = PlayerData.Instance.AddPetProgress(pPetID);
|
|
DataPet tPet = TablePet.Instance.GetData(pPetID.ToString());
|
|
int tOnlineCount = TKGSDKManager.Instance.GetConfigInt(TKGParamKey.SkinAdCount.ToString());
|
|
if (tCount >= (tOnlineCount > 0 ? tOnlineCount : tPet.AdCount))
|
|
{
|
|
PlayerData.Instance.GetPet(pPetID);
|
|
PlayerData.Instance.UsePet(pPetID);
|
|
|
|
PetManager.Instance.SetPet(PlayerData.Instance.CurrentPetID);
|
|
}
|
|
|
|
LoadData();
|
|
});
|
|
}
|
|
|
|
private void OnUsePet(int pPetID)
|
|
{
|
|
PlayerData.Instance.UsePet(pPetID);
|
|
|
|
PetManager.Instance.SetPet(PlayerData.Instance.CurrentPetID);
|
|
|
|
LoadData();
|
|
}
|
|
} |