chicken_dy/Assets/Scripts/UI/CustomControl/EndingCell.cs

147 lines
4.3 KiB
C#

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class EndingCell : MonoBehaviour
{
[SerializeField] Text mTxtEndingName;
[SerializeField] GameObject mGobCheck;
[SerializeField] GameObject mGobGood;
[SerializeField] Button mBtnTip;
[SerializeField] Button mBtnAdTip;
[SerializeField] Button mBtnShareTip;
[SerializeField] GameObject mGobPlayingTip;
private int mLevelID;
private int mEndingID;
private EndingData mEdData;
private List<AudioClip> mTipSoundList;
private TimerUnit mTipPlayTimer;
private int mTipIndex;
private void Awake()
{
UIUtils.BindBtn(mBtnTip, OnClickTip);
UIUtils.BindBtn(mBtnAdTip, OnClickAdTip);
UIUtils.BindBtn(mBtnShareTip, OnClickShareTip);
}
private void OnDisable()
{
if (mTipPlayTimer != null)
{
mTipPlayTimer.Destroy();
mTipPlayTimer = null;
}
}
public void Init(int pLevelID, int pEndingID)
{
mLevelID = pLevelID;
mEndingID = pEndingID;
mEdData = GameConfig.Instance.GetLevelData(mLevelID).Endings[pEndingID];
mTxtEndingName.text = mEdData.EndingName;
mGobCheck.SetActive(PlayerData.Instance.HasUnlockedEnding(mLevelID, mEndingID));
mGobGood.SetActive(mEdData.IsGoodEnding);
bool tHasWatchedAdTip = PlayerData.Instance.HasWatchedEndingAdTip(mLevelID, mEndingID);
mBtnTip.gameObject.SetActive(tHasWatchedAdTip);
if (!tHasWatchedAdTip) // 没看过提示
{
if (TKGSDKManager.Instance.GetRewardWay() == TKGSDKManager.WayOfReward.Share) // 只展示分享
{
mBtnShareTip.gameObject.SetActive(true);
}
else if(TKGSDKManager.Instance.GetRewardWay() == TKGSDKManager.WayOfReward.RewardAd) // 只展示激励视频广告
{
mBtnShareTip.gameObject.SetActive(true);
}
}
else // 已经看过提示了,就这俩按钮都不展示
{
mBtnAdTip.gameObject.SetActive(!tHasWatchedAdTip);
mBtnShareTip.gameObject.SetActive(!tHasWatchedAdTip);
}
mGobPlayingTip.SetActive(false);
}
private void OnClickTip()
{
string[] tTemplateEndingStrs = mEdData.EndingCode.Split(';');
mTipSoundList = new List<AudioClip>();
for (int i = 0; i < tTemplateEndingStrs[0].Length; i++)
{
int tSoundIndex = tTemplateEndingStrs[0][i] == 'X' ? 0 : (int.Parse(tTemplateEndingStrs[0][i].ToString()) - 1);
mTipSoundList.Add(ResourceManager.Instance.LoadRes<AudioClip>(Const.Path.GetSound(mLevelID, tSoundIndex)));
}
if (mTipPlayTimer == null)
{
mTipPlayTimer = TimerManager.Instance.CreateTimerUnit();
}
mTipIndex = 0;
mTipPlayTimer.CancelTimer();
mTipPlayTimer.StartTimer(PlayOneTip, 0.3f);
mGobPlayingTip.SetActive(true);
}
private void PlayOneTip()
{
AudioManager.Instance.PlaySound(mTipSoundList[mTipIndex]);
mTipIndex++;
if (mTipIndex < mTipSoundList.Count)
{
mTipPlayTimer.StartTimer(PlayOneTip, 1f);
}
else
{
mGobPlayingTip.SetActive(false);
}
}
private void OnClickAdTip()
{
TKGSDKManager.Instance.ShowRewardAd(TKGRVPositionName.RV_sound_unlock, WatchAdSucceed, () =>
{
UIManager.Instance.OpenUI<PanelNoAdsTip>();
});
WatchAdSucceed(true);
}
private void OnClickShareTip()
{
TKGSDKManager.Instance.ShareShareAppMessageByType(TKGSDKManager.ShareType.ShareAppFixedImg);
Invoke("RewardSucc", 0.5f);
}
private void RewardSucc()
{
WatchAdSucceed(true);
}
private void WatchAdSucceed(bool pResult)
{
if (!pResult)
return;
PlayerData.Instance.AddEndingAdTip(mLevelID, mEndingID);
mBtnTip.gameObject.SetActive(true);
mBtnAdTip.gameObject.SetActive(false);
mBtnShareTip.gameObject.SetActive(false);
OnClickTip();
//TKGSDKManager.Instance.LogEvent(Const.AdsEvent.UnlockTip, Const.AdsEvtID.Level, PlayerData.Instance.CurrentLevel.ToString());
}
}