using System.Collections;
|
using System.Collections.Generic;
|
using DG.Tweening;
|
using KTGMGemClient;
|
using UnityEngine;
|
using UnityEngine.SceneManagement;
|
using UnityEngine.UI;
|
|
public class Loading : MonoBehaviour
|
{
|
private Slider progressSlider;//进度条
|
private GameObject bg;
|
bool isLogining;
|
|
// Start is called before the first frame update
|
void Start()
|
{
|
AudioSourceManager.Ins.Play(AudioEnum.BGM1);
|
EventCenter.Ins.RemoveAllListener();
|
TDAA_SDKManager.Ins.AddListener();
|
|
progressSlider = transform.Find("BGPanel/Progress").GetComponent<Slider>();
|
progressSlider.value = 0;
|
//progressSlider.gameObject.SetActive(false);
|
|
bg = transform.Find("BGPanel").gameObject;
|
bg.SetActive(false);
|
}
|
|
public void StartLoadingScene()
|
{
|
if (GameConfig.isFirstStart)
|
{
|
GameConfig.isFirstStart = false;
|
}
|
else
|
{
|
TDAA_SDKManager.Ins.OnClickRestartBtn();//重玩
|
}
|
bg.gameObject.SetActive(true);
|
AudioSourceManager.Ins.Play(AudioEnum.UI);
|
StartCoroutine(loginMy());
|
}
|
|
IEnumerator loginMy()
|
{
|
progressSlider.value = 0.0f;
|
System.GC.Collect();
|
DOTween.Clear();
|
Debug.Log("开始清理GC,清理DOTween");
|
yield return new WaitForSeconds(0.2f);
|
int displayProgress = 0;
|
int toProgress = 0;
|
AsyncOperation op = SceneManager.LoadSceneAsync("Endless2D");
|
// AsyncOperation op = SceneManager.LoadSceneAsync(GameConfig.NextSceneName);
|
op.allowSceneActivation = false;
|
while (op.progress < 0.9f) //此处如果是 <= 0.9f 则会出现死循环所以必须小0.9
|
{
|
toProgress = (int)(op.progress * 100);
|
while (displayProgress < toProgress)
|
{
|
++displayProgress;
|
progressSlider.value = displayProgress * 0.01f;
|
yield return new WaitForEndOfFrame();//ui渲染完成之后
|
}
|
}
|
toProgress = 100;
|
while (displayProgress < toProgress)
|
{
|
++displayProgress;
|
progressSlider.value = displayProgress * 0.01f;
|
|
yield return new WaitForEndOfFrame();
|
}
|
op.allowSceneActivation = true;
|
yield break;
|
|
}
|
|
|
// Update is called once per frame
|
void Update()
|
{
|
|
}
|
}
|