RandomGFGoStop/Assets/Scripts/UI/MainPanel.cs

261 lines
7.3 KiB
C#

using System;
using System.Collections;
using System.Collections.Generic;
using TMPro;
using UnityEngine;
public class MainPanel : MonoBehaviour
{
[SerializeField] private UnityEngine.UI.Image aiImage;
[SerializeField] private TextMeshProUGUI TargetLevelIndexTMP, t_point;
[SerializeField] private TextMeshProUGUI adviceTMP;
[SerializeField] private string PrologueEventID;
[SerializeField] private List<string> speechBubbleNomalText = new List<string>();
[SerializeField] private List<string> speechBubbleTutorialText = new List<string>();
private WaitForSeconds typingSecond = new WaitForSeconds(0.08f);
private IEnumerator typingCoroutine = null;
private WaitForSeconds adviceSecond = new WaitForSeconds(15.0f);
private IEnumerator adviceCoroutine = null;
private string adviceText = String.Empty;
#region MonoBehaviour
private void Awake()
{
if (GameManager.Instance != null)
{
GameManager.Event.RegistEvent(EEventType.OnSynchronizeAIChllengeModeAIData, this.OnSynchronizeAIImageOpenState);
GameManager.Event.RegistEvent(EEventType.OnSynchronizeNormalGameData, this.OnSynchronizeNormalGameData);
}
this.OnSynchronizeAIImageOpenState();
this.OnSynchronizeNormalGameData();
if (GameManager.DB.ExistSaveData() == true)
{
GameManager.Sound.PlayBGM(EBGMType.BGM_1);
}
else
{
GameManager.DB.SaveDatas();
//EventScript eventScript = Instantiate(Resources.Load<EventScript>(ResourceManager.PREFAB_PATH + "Script/" + "EventScript"), transform);
//if (eventScript != null)
//{
// eventScript.InitEventScript(new BansheeGz.BGDatabase.BGId(PrologueEventID));
//}
}
GameManager.ADS.ShowBanner();
}
private void OnEnable()
{
//aiImage.rectTransform.DOScale(1.025f, 5f).From(Vector3.one).SetLoops(-1, LoopType.Yoyo).SetEase(Ease.Linear).SetRecyclable(true);
/*DateTime loadTime = GameManager.Timer.LoadTime();
float second = DateTime.Now.Second - loadTime.Second;
if (second <= 0 || second > 10.0f)
{
PlayAdvice(10.0f);
}
else
{
PlayAdvice(second);
}*/
PlayAdvice();
var data = DB_HuntingData.GetEntity((GameManager.DB.GetUnlockTargetIndex(true) << 1) - 2);
if (data != null) aiImage.sprite = data.DBF_HuntingImage;
OnSynchronizeNormalGameData();
GameManager.DB.CheckDayReset();
}
private void OnDisable()
{
/*if (DOTween.IsTweening(aiImage.rectTransform))
aiImage.rectTransform.DOKill();*/
GameManager.Timer.SaveTime();
if (adviceCoroutine != null)
{
StopCoroutine(adviceCoroutine);
adviceCoroutine = null;
}
if (typingCoroutine != null)
{
StopCoroutine(typingCoroutine);
typingCoroutine = null;
}
}
private void OnDestroy()
{
if (GameManager.Instance != null)
{
GameManager.Event.RemoveEvent(EEventType.OnSynchronizeAIChllengeModeAIData, this.OnSynchronizeAIImageOpenState);
GameManager.Event.RegistEvent(EEventType.OnSynchronizeNormalGameData, this.OnSynchronizeNormalGameData);
}
if (adviceCoroutine != null)
{
StopCoroutine(adviceCoroutine);
}
if (typingCoroutine != null)
{
StopCoroutine(typingCoroutine);
}
}
#endregion
private void OnSynchronizeAIImageOpenState()
{
//var data = GameManager.DB.GetHuntingData(GameManager.DB.GetUnlockTargetIndex());
//aiImage.sprite = GameManager.Resource.GetAISpriteFromResources(data.TextureIndex);
}
private void OnSynchronizeNormalGameData()
{
TargetLevelIndexTMP.text = $"Lv.{GameManager.DB.NormalGameLevel}";
t_point.text = $"{GameManager.DB.NormalGameLevel * DBManager.NORMAL_GAME_STAKE_PER_LEVEL}";
}
public void ClickStartGame()
{
if (GameManager.DB.Gold > 0)
{
//if (GameManager.DB.InterstitialADCount <= 0)
//{
// GameManager.ADS.OnCompletedInterstitialAd += OnCompletedInterstitialAd;
// GameManager.ADS.ShowInterstitialAd();
//}
//else
//{
// GameManager.Event.InvokeEvent(EEventType.OnStartNormalGame);
//}
GameManager.Event.InvokeEvent(EEventType.OnStartNormalGame);
}
else
{
GameManager.UI.ShowNStackPopup(EPopupType.GoldChargePopup);
}
}
private void PlayAdvice()
{
if (adviceTMP != null && adviceCoroutine == null)
{
adviceCoroutine = Advice();
StartCoroutine(adviceCoroutine);
}
}
private IEnumerator Advice()
{
while (gameObject != null)
{
if (adviceTMP != null)
{
int random = UnityEngine.Random.Range(1, 11);
int borderline = 4;
if(GameManager.DB.NormalGameLevel <= 5)
{
borderline = 6;
}
if(random > borderline)
{
adviceText = GetSpeechBubbleNomalText();
}
else
{
adviceText = GetSpeechBubbleTutorialText();
}
}
AdviceTyping(adviceText);
yield return adviceSecond;
}
}
private void AdviceTyping(string text)
{
if (adviceTMP != null)
{
if (typingCoroutine != null)
{
StopCoroutine(typingCoroutine);
typingCoroutine = null;
}
typingCoroutine = Typing(text);
StartCoroutine(typingCoroutine);
}
}
private IEnumerator Typing(string text)
{
adviceTMP.text = String.Empty;
for (int i = 0; i < text.Length; i++)
{
if ('$' == text[i])
{
adviceTMP.text += "\n";
}
else
{
adviceTMP.text += text[i];
}
yield return typingSecond;
}
typingCoroutine = null;
}
private string GetSpeechBubbleNomalText()
{
if(speechBubbleNomalText.Count > 0)
{
int random = UnityEngine.Random.Range(0, speechBubbleNomalText.Count);
return speechBubbleNomalText[random];
}
else
{
return "";
}
}
private string GetSpeechBubbleTutorialText()
{
if (speechBubbleTutorialText.Count > 0)
{
int random = UnityEngine.Random.Range(0, speechBubbleTutorialText.Count);
return speechBubbleTutorialText[random];
}
else
{
return "";
}
}
private void OnCompletedInterstitialAd(bool isComplete)
{
GameManager.ADS.OnCompletedInterstitialAd -= OnCompletedInterstitialAd;
if(isComplete == true || GameManager.DB.IsRemoveADS == true)
{
GameManager.DB.ResetInterstitialADCount();
GameManager.Event.InvokeEvent(EEventType.OnStartNormalGame);
}
}
}