River Jiang
2020-10-27 1f5eda1c9d22a3676298751c7282a5874f13bed0
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
using System.Collections;
using System.Collections.Generic;
using TMPro;
using UnityEngine;
using UnityEngine.SceneManagement;
using UnityEngine.UIElements;
using KTGMGemClient;
 
public class LoadingScene : MonoBehaviour
{
    public TextMeshProUGUI loadingTxt;
 
    private AsyncOperation async = null;
 
    protected string dynamicTxt = "";
    protected static float UPDATE_TIME = 0.5f;
    protected float curTime = 0.0f;
    protected float totalTime = 0.0f;
    protected bool bLoadScene = false;
    // Start is called before the first frame update
    void Start()
    {
        loadingTxt.text = "LOADING";
        curTime = UPDATE_TIME;
    }
 
 
    IEnumerator LoadScene()
    {
        async = SceneManager.LoadSceneAsync(GameConfig.NextSceneName);
        async.allowSceneActivation = true;
        /*while (!async.isDone)
        {
            
            if (async.progress < 0.9f)
                progressValue = async.progress;
            else
                progressValue = 1.0f;
            slider.value = progressValue;
            progress.text = (int)(slider.value * 100) + " %";
            
            if (async.progress >= 0.89)
            {
                Debug.Log("进展时间分别是:" + async.progress + "," + totalTime);
                if( totalTime >= 3.0f )
                    async.allowSceneActivation = true;
                
                progress.text = "按任意键继续";
                if (Input.anyKeyDown)
                {
                    async.allowSceneActivation = true;
                }
 
            }
 
            //yield return null;
        }*/
        yield return null;
    }
 
 
 
    // Update is called once per frame
    void Update()
    {
        float tf = Time.deltaTime;
        curTime -= tf;
        if (curTime <= 0)
        {
            totalTime += 0.8f;
            curTime = UPDATE_TIME + curTime;
            // 更新文字.
            dynamicTxt += ".";
            if (dynamicTxt.Length > 6)
                dynamicTxt = "";
            loadingTxt.text = "LOADING" + dynamicTxt;
            if ((dynamicTxt.Length >= 1) && (!bLoadScene) )
            {
                bLoadScene = true;
                StartCoroutine("LoadScene");
            }
        }
    }
}