99 lines
2.6 KiB
C#
99 lines
2.6 KiB
C#
using asap.core;
|
||
using DG.Tweening;
|
||
using GameCore;
|
||
using System.Collections.Generic;
|
||
using TMPro;
|
||
using UnityEngine;
|
||
using UnityEngine.UI;
|
||
|
||
public class RechargeItem : MonoBehaviour
|
||
{
|
||
RechargeItemData data;
|
||
GameObject bg_cliam;
|
||
GameObject bg_normal;
|
||
GameObject mask;
|
||
GameObject locked;
|
||
GameObject fx_unlocked;
|
||
TMP_Text taskDescText;
|
||
Image bar;
|
||
TMP_Text barText;
|
||
RewardItemNew rewardItem;
|
||
private void Awake()
|
||
{
|
||
bar = transform.Find("bg_normal/bg_bar/bar").GetComponent<Image>();
|
||
barText = transform.Find("bg_normal/bg_bar/text_num").GetComponent<TMP_Text>();
|
||
bg_cliam = transform.Find("bg_cliam").gameObject;
|
||
bg_normal = transform.Find("bg_normal").gameObject;
|
||
locked = transform.Find("locked").gameObject;
|
||
fx_unlocked = transform.Find("fx_unlocked").gameObject;
|
||
taskDescText = transform.Find("text_task").GetComponent<TMP_Text>();
|
||
|
||
rewardItem = transform.Find("reward").GetComponent<RewardItemNew>();
|
||
|
||
mask = transform.Find("bg_done").gameObject;
|
||
|
||
}
|
||
|
||
public void Init(RechargeItemData taskItemData)
|
||
{
|
||
this.data = taskItemData;
|
||
SetItem();
|
||
}
|
||
void SetItem()
|
||
{
|
||
Refresh();
|
||
taskDescText.text = data.desc;
|
||
var itemData = GContext.container.Resolve<PlayerItemData>().GetItemDataByDropIdLureInflation(null, data.reward);
|
||
if (itemData != null)
|
||
{
|
||
rewardItem.gameObject.SetActive(true);
|
||
rewardItem.SetData(itemData[0]);
|
||
}
|
||
barText.text = data.progress.ToPercentageString();
|
||
bar.fillAmount = data.progress;
|
||
}
|
||
|
||
public void Play()
|
||
{
|
||
bar.DOFillAmount(data.newProgress, 0.5f).OnUpdate
|
||
(
|
||
() =>
|
||
{
|
||
barText.text = bar.fillAmount.ToPercentageString();
|
||
}
|
||
).OnComplete(SetReceive);
|
||
}
|
||
void SetReceive()
|
||
{
|
||
if (data.rewardState == 1)
|
||
{
|
||
data.rewardState = 2;
|
||
Refresh();
|
||
fx_unlocked.SetActive(true);
|
||
}
|
||
}
|
||
void Refresh()
|
||
{
|
||
mask.SetActive(data.rewardState == 2);
|
||
bg_cliam.SetActive(data.rewardState == 2);
|
||
bg_normal.gameObject.SetActive(data.rewardState < 2);
|
||
locked.SetActive(data.rewardState != 2);
|
||
}
|
||
}
|
||
|
||
|
||
public class RechargeItemData
|
||
{
|
||
public int id;
|
||
public string desc;
|
||
public int reward;
|
||
/// <summary>
|
||
/// 0,不能领,1能领还没领,2已经领过
|
||
/// </summary>
|
||
public int rewardState;
|
||
public float progress;
|
||
public float newProgress;
|
||
}
|
||
|
||
|