wangguan
2020-12-24 c5679cb58551843e74d31a839de649f16885fa8b
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
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();
        EventCenter.Ins.Add((int)KTGMGemClient.EventType.ChangeScene, ChangeScene);
 
        progressSlider = transform.Find("BGPanel/Progress").GetComponent<Slider>();
        progressSlider.value = 0;
        progressSlider.gameObject.SetActive(false);
 
 
    }
 
    private void ChangeScene()
    {
        StartLoadingScene();
    }
    public void StartLoadingScene()
    {
        if (GameConfig.isFirstStart)
        {
            GameConfig.isFirstStart = false;
        }
        else
        {
            TDAA_SDKManager.Ins.OnClickRestartBtn();//重玩
        }
        progressSlider.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()
    {
 
    }
}