468 lines
13 KiB
C#
468 lines
13 KiB
C#
using DG.Tweening;
|
|
using OneStore.Common; // 지우면 안됨
|
|
using System;
|
|
using System.Collections;
|
|
using TMPro;
|
|
using UnityEngine;
|
|
using UnityEngine.AddressableAssets;
|
|
using UnityEngine.Networking;
|
|
using UnityEngine.UI;
|
|
|
|
public class TitleCanvas : MonoBehaviour
|
|
{
|
|
private enum TitleCanvasState
|
|
{
|
|
CheckInternet,
|
|
CheckVersion,
|
|
DownloadData,
|
|
LoadUnlockHuntingImage,
|
|
LoadScene,
|
|
}
|
|
|
|
public Image BackgroundImage;
|
|
[SerializeField] private MaskableProgressBar MaskableBar;
|
|
[SerializeField] private RectTransform blinkRT;
|
|
[SerializeField] private TextMeshProUGUI progressbarText, t_ver;
|
|
|
|
[SerializeField] private AgeIndication ageIndication = null;
|
|
|
|
private TitleCanvasState state = TitleCanvasState.CheckInternet;
|
|
|
|
//private Coroutine DownloadDataCoroutine = null;
|
|
//private Coroutine LoadUnlockHuntingImageCoroutine = null;
|
|
bool AgeIndicate = true;
|
|
bool AgeEnd = false;
|
|
|
|
private void Awake()
|
|
{
|
|
Screen.sleepTimeout = SleepTimeout.NeverSleep;
|
|
|
|
if (GameManager.Instance != null)
|
|
Debug.Log("base: Call Manager");
|
|
|
|
MaskableBar.FillAmount = 1.0f;
|
|
|
|
t_ver.text = Application.version;
|
|
#if UNITY_EDITOR
|
|
t_ver.text += "(E)";
|
|
#else
|
|
t_ver.text += StoreEnvironment.GetStoreType() == StoreType.ONESTORE ? "(O)" : "(G)";
|
|
#endif
|
|
|
|
//blinkRT.DOAnchorPosX(250, 1.5f).SetEase(Ease.OutExpo).SetLoops(-1, LoopType.Restart).From(Vector2.left * 250);
|
|
}
|
|
|
|
float AgeIndicate_time = 2.5f;
|
|
private void Update()
|
|
{
|
|
if (AgeIndicate)
|
|
{
|
|
if (AgeIndicate_time > 0f)
|
|
{
|
|
AgeIndicate_time -= Time.deltaTime;
|
|
if (AgeIndicate_time <= 0f)
|
|
{
|
|
AgeIndicate = false;
|
|
AgeEnd = true;
|
|
BackgroundImage.color = Color.white;
|
|
}
|
|
}
|
|
}
|
|
|
|
if (AgeEnd)
|
|
{
|
|
if (GameManager.Addressable != null)
|
|
{
|
|
AgeEnd = false;
|
|
OnCompleteAgeIndicationHide();
|
|
}
|
|
}
|
|
}
|
|
|
|
private void OnDestroy()
|
|
{
|
|
if (DOTween.IsTweening(blinkRT))
|
|
blinkRT.DOKill();
|
|
|
|
//GameManager.BGDatabase.ReleaseHuntingUnlockImage();
|
|
GameManager.OnCompleteCreatemanager -= OnCompleteCreatemanager;
|
|
|
|
GameManager.Network.OnNetworkOnline -= OnNetworkOnline;
|
|
|
|
GameManager.BGDatabase.OnCompleteLoadHuntingImage -= OnSucceedLoadUnlockHuntingImage;
|
|
|
|
ageIndication.OnCompleteHide -= OnCompleteAgeIndicationHide;
|
|
|
|
GameManager.Addressable.NotifiyCatalogUpdated -= OnCatalogUpdated;
|
|
GameManager.Addressable.NotifiySizeDownloaded -= OnSizeDownloaded;
|
|
GameManager.Addressable.NotifiyDownloadFinished -= OnDownloadFinished;
|
|
GameManager.OnCompleteCreatemanager -= OnCompleteCreatemanager;
|
|
}
|
|
|
|
private void OnCompleteCreatemanager()
|
|
{
|
|
Debug.Log("OnCompleteCreatemanager : " + InternetTime.Ins.Time);
|
|
DateTime loadTime = GameManager.Timer.LoadTime();
|
|
if (loadTime.Day != InternetTime.Ins.Time.Day)
|
|
{
|
|
GameManager.DB.ResetADSRewardActionCount();
|
|
GameManager.DB.ResetFreeHeartCount();
|
|
GameManager.DB.ResetFreeKeyCount();
|
|
}
|
|
if (GameManager.DB.Get_SaveData().Month != InternetTime.Ins.Time.Month)
|
|
{
|
|
GameManager.DB.Set_Month(InternetTime.Ins.Time.Month);
|
|
GameManager.DB.ResetTotalCashPerMonth();
|
|
}
|
|
|
|
state = TitleCanvasState.CheckInternet;
|
|
StartCurrentState();
|
|
}
|
|
|
|
private void StartCurrentState()
|
|
{
|
|
switch (state)
|
|
{
|
|
case TitleCanvasState.CheckInternet:
|
|
StartCoroutine(CheckInternet());
|
|
break;
|
|
case TitleCanvasState.CheckVersion:
|
|
/*Addressables.ClearDependencyCacheAsync("TestPopup");
|
|
|
|
Addressables.DownloadDependenciesAsync("TestPopup").Completed += (handle) =>
|
|
{
|
|
if (handle.Status == AsyncOperationStatus.Succeeded)
|
|
{
|
|
StartCoroutine(LoadTestPopup());
|
|
|
|
/*Addressables.LoadResourceLocationsAsync("TestPopup").Completed += (handle) =>
|
|
{
|
|
if (handle.Status == AsyncOperationStatus.Succeeded)
|
|
{
|
|
//Addressables.LoadAssetsAsync(handle.Result).
|
|
|
|
|
|
}
|
|
};
|
|
}
|
|
};*/
|
|
GameManager.ADS.InitADSManager();
|
|
CheckVersion();
|
|
break;
|
|
case TitleCanvasState.DownloadData:
|
|
//DownloadData(); // 리소스 다운로드 없음
|
|
NextState();
|
|
StartCurrentState();
|
|
break;
|
|
case TitleCanvasState.LoadUnlockHuntingImage:
|
|
LoadUnlockHuntingImage();
|
|
break;
|
|
case TitleCanvasState.LoadScene:
|
|
StartCoroutine(coroGoToNextScene());
|
|
break;
|
|
}
|
|
}
|
|
|
|
private void NextState()
|
|
{
|
|
switch (state)
|
|
{
|
|
case TitleCanvasState.CheckInternet:
|
|
state = TitleCanvasState.CheckVersion;
|
|
break;
|
|
case TitleCanvasState.CheckVersion:
|
|
state = TitleCanvasState.DownloadData;
|
|
break;
|
|
case TitleCanvasState.DownloadData:
|
|
state = TitleCanvasState.LoadUnlockHuntingImage;
|
|
break;
|
|
case TitleCanvasState.LoadUnlockHuntingImage:
|
|
state = TitleCanvasState.LoadScene;
|
|
break;
|
|
}
|
|
}
|
|
|
|
private IEnumerator CheckInternet()
|
|
{
|
|
yield return null;
|
|
progressbarText.text = "네트워크 확인 하는 중";
|
|
|
|
yield return new WaitForSecondsRealtime(0.5f);
|
|
|
|
if (GameManager.Network.IsOnline)
|
|
{
|
|
NextState();
|
|
StartCurrentState();
|
|
}
|
|
else
|
|
{
|
|
if (GameManager.DB.ExistSaveData())
|
|
{
|
|
state = TitleCanvasState.LoadUnlockHuntingImage;
|
|
StartCurrentState();
|
|
}
|
|
else
|
|
{
|
|
OnNetworkOnline(true);
|
|
}
|
|
}
|
|
}
|
|
|
|
private void CheckVersion()
|
|
{
|
|
progressbarText.text = "버전 확인 하는 중...";
|
|
if (Application.version == "9.9.9")
|
|
{
|
|
NextState();
|
|
StartCurrentState();
|
|
}
|
|
else
|
|
StartCoroutine(LoadVersiontData("https://filgoodbanditshomepage.web.app/RandomGFGoStop.txt"));
|
|
}
|
|
|
|
private void DownloadData()
|
|
{
|
|
progressbarText.text = "다운로드 하는 중...";
|
|
GameManager.Addressable.DownloadData();
|
|
|
|
//if (DownloadDataCoroutine == null)
|
|
//{
|
|
// DownloadDataCoroutine = StartCoroutine(UpdateDownloadData());
|
|
//}
|
|
StartCoroutine(UpdateDownloadData());
|
|
}
|
|
|
|
private void LoadUnlockHuntingImage()
|
|
{
|
|
// 튜토리얼 기능을 위해 main씬에서 세이브 초기화로 결정
|
|
// 임시적으로 세이브기능을 이곳에 나중에 다운로드 완료 후에 세이브하도록 수정
|
|
//GameManager.DB.SaveDatas();
|
|
|
|
progressbarText.text = "이미지 로드 하는 중...";
|
|
GameManager.BGDatabase.InitDataBase();
|
|
|
|
GameManager.BGDatabase.OnCompleteLoadHuntingImage += OnSucceedLoadUnlockHuntingImage;
|
|
|
|
//if (LoadUnlockHuntingImageCoroutine == null)
|
|
//{
|
|
// LoadUnlockHuntingImageCoroutine = StartCoroutine(UpdateLoadUnlockHuntingImage());
|
|
//}
|
|
StartCoroutine(UpdateLoadUnlockHuntingImage());
|
|
}
|
|
|
|
IEnumerator Check_GameManager()
|
|
{
|
|
while (true)
|
|
{
|
|
yield return null;
|
|
if (GameManager.Instance == null) continue;
|
|
if (GameManager.Resource == null) continue;
|
|
if (GameManager.DB == null) continue;
|
|
if (GameManager.UI == null) continue;
|
|
if (GameManager.Scene == null) continue;
|
|
if (GameManager.Sound == null) continue;
|
|
if (GameManager.Event == null) continue;
|
|
if (GameManager.Time == null) continue;
|
|
if (GameManager.BGDatabase == null) continue;
|
|
if (GameManager.Network == null) continue;
|
|
if (GameManager.Addressable == null) continue;
|
|
if (GameManager.Account == null) continue;
|
|
if (GameManager.Timer == null) continue;
|
|
if (GameManager.ADS == null) continue;
|
|
if (GameManager.IAP == null) continue;
|
|
|
|
break;
|
|
}
|
|
}
|
|
|
|
private IEnumerator coroGoToNextScene()
|
|
{
|
|
progressbarText.text = "로비로 진입중입니다.";
|
|
yield return StartCoroutine(Check_GameManager());
|
|
|
|
//float cnt = 0;
|
|
//while (cnt < 2)
|
|
//{
|
|
// cnt += Time.deltaTime;
|
|
// MaskableBar.FillAmount = cnt / 2;
|
|
// yield return null;
|
|
//}
|
|
|
|
GameManager.Scene.LoadScene(ESceneType.Main);
|
|
}
|
|
|
|
private IEnumerator LoadVersiontData(string url)
|
|
{
|
|
using (UnityWebRequest www = UnityWebRequest.Get(url))
|
|
{
|
|
yield return www.SendWebRequest();
|
|
|
|
string updateVersion = www.downloadHandler.text;
|
|
string currentVersion = Application.version;
|
|
|
|
updateVersion = updateVersion.Replace(".", "");
|
|
currentVersion = currentVersion.Replace(".", "");
|
|
|
|
if (int.Parse(updateVersion) > int.Parse(currentVersion))
|
|
{
|
|
WarrnigDifferentVersion();
|
|
}
|
|
else
|
|
{
|
|
NextState();
|
|
StartCurrentState();
|
|
}
|
|
|
|
yield break;
|
|
}
|
|
}
|
|
|
|
private void OnSucceedLoadUnlockHuntingImage(bool isSucceed)
|
|
{
|
|
if (!isSucceed)
|
|
{
|
|
//Logging.LogError("LoadOutGameImage is Fail");
|
|
}
|
|
else
|
|
{
|
|
//if (LoadUnlockHuntingImageCoroutine != null)
|
|
//{
|
|
// StopCoroutine(LoadUnlockHuntingImageCoroutine);
|
|
//}
|
|
|
|
NextState();
|
|
StartCurrentState();
|
|
}
|
|
}
|
|
|
|
private void OnNetworkOnline(bool isOnline)
|
|
{
|
|
if (isOnline == true)
|
|
{
|
|
NextState();
|
|
StartCurrentState();
|
|
}
|
|
}
|
|
|
|
private void WarrnigDifferentVersion()
|
|
{
|
|
GameManager.UI.ShowNStackPopup(EPopupType.NotMinimumVersionPopup);
|
|
|
|
}
|
|
|
|
private void WarrnigFailDownload()
|
|
{
|
|
Debug.LogWarning("base: WarrnigFailDownload");
|
|
//ReturnFirstState();
|
|
}
|
|
|
|
private void ReturnFirstState()
|
|
{
|
|
state = TitleCanvasState.CheckInternet;
|
|
|
|
StartCurrentState();
|
|
}
|
|
|
|
private void OnCatalogUpdated(bool isUpdateCataglog)
|
|
{
|
|
if (isUpdateCataglog == true)
|
|
{
|
|
|
|
}
|
|
else
|
|
{
|
|
|
|
}
|
|
}
|
|
|
|
private void OnSizeDownloaded(long size)
|
|
{
|
|
|
|
}
|
|
|
|
private void OnDownloadFinished(bool completed)
|
|
{
|
|
//if (DownloadDataCoroutine != null)
|
|
//{
|
|
// StopCoroutine(DownloadDataCoroutine);
|
|
//}
|
|
|
|
if (completed == true)
|
|
{
|
|
NextState();
|
|
StartCurrentState();
|
|
}
|
|
else
|
|
{
|
|
WarrnigFailDownload();
|
|
}
|
|
}
|
|
|
|
private IEnumerator UpdateDownloadData()
|
|
{
|
|
MaskableBar.FillAmount = 0.0f;
|
|
|
|
while (true)
|
|
{
|
|
yield return null;
|
|
|
|
float percent = GameManager.Addressable.GetDownloadDataPercent();
|
|
if (percent <= 0.8f)
|
|
{
|
|
percent = (percent / 0.8f) * 0.2f;
|
|
}
|
|
else
|
|
{
|
|
percent = 0.2f + ((percent - 0.8f) / 0.2f) * 0.8f;
|
|
}
|
|
|
|
MaskableBar.FillAmount = percent;
|
|
}
|
|
}
|
|
|
|
private IEnumerator UpdateLoadUnlockHuntingImage()
|
|
{
|
|
MaskableBar.FillAmount = 0.0f;
|
|
|
|
yield return new WaitForSeconds(1.0f);
|
|
|
|
GameManager.BGDatabase.LoadHuntingUnlockImage();
|
|
|
|
while (true)
|
|
{
|
|
yield return null;
|
|
|
|
MaskableBar.FillAmount = GameManager.BGDatabase.LoadPercent;
|
|
}
|
|
}
|
|
|
|
private IEnumerator EndAgeIndication()
|
|
{
|
|
if (ageIndication != null)
|
|
{
|
|
yield return new WaitForSecondsRealtime(2.5f);
|
|
}
|
|
OnCompleteAgeIndicationHide();
|
|
}
|
|
|
|
private void OnCompleteAgeIndicationHide()
|
|
{
|
|
Debug.Log("OnCompleteAgeIndicationHide");
|
|
|
|
Destroy(ageIndication.gameObject);
|
|
|
|
GameManager.Addressable.NotifiyCatalogUpdated += OnCatalogUpdated;
|
|
GameManager.Addressable.NotifiySizeDownloaded += OnSizeDownloaded;
|
|
GameManager.Addressable.NotifiyDownloadFinished += OnDownloadFinished;
|
|
|
|
if (GameManager.DB.CompleteDataLoad == false)
|
|
{
|
|
GameManager.OnCompleteCreatemanager += OnCompleteCreatemanager;
|
|
}
|
|
else
|
|
{
|
|
OnCompleteCreatemanager();
|
|
}
|
|
}
|
|
}
|