少年修仙传客户端代码仓库
hch
2025-06-12 204ef05a831c9484e2abc561d27ecbff7c797453
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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
//--------------------------------------------------------
//    [Author]:           第二世界
//    [  Date ]:           Tuesday, January 09, 2018
//--------------------------------------------------------
 
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
 
namespace vnxbqy.UI
{
 
    public class DownLoadWin : Window
    {
        [SerializeField] RectTransform m_ContainerHint;
        [SerializeField] RichText m_Content;
        [SerializeField] Button m_Confirm;
        [SerializeField] Button m_Cancel;
 
        [SerializeField] Transform m_ContainerProgress;
        [SerializeField] SmoothSlider m_ProgressSlider;
        [SerializeField] Text m_Progress;
        [SerializeField] Text m_DownLoadSpeed;
        [SerializeField] Transform awardObj;
 
        float timer = 1f;
        #region Built-in
        protected override void BindController()
        {
        }
 
        protected override void AddListeners()
        {
            m_Confirm.AddListener(Confirm);
            m_Cancel.AddListener(Cancel);
        }
 
        protected override void OnPreOpen()
        {
            timer = 1f;
            if (Application.internetReachability == NetworkReachability.ReachableViaLocalAreaNetwork)
            {
                DownLoadAndDiscompressTask.Instance.StartDownLoad();
            }
 
            OnDownLoadStepChange(DownLoadAndDiscompressTask.Instance.step);
 
            awardObj.SetActive(InGameDownLoad.Instance.IsShowDownloadAward());
        }
 
        protected override void OnAfterOpen()
        {
            DownLoadAndDiscompressTask.Instance.downLoadStepChangeEvent += OnDownLoadStepChange;
        }
 
        protected override void OnPreClose()
        {
            DownLoadAndDiscompressTask.Instance.downLoadStepChangeEvent -= OnDownLoadStepChange;
        }
 
        protected override void OnAfterClose()
        {
        }
        #endregion
 
        private void OnDownLoadStepChange(DownLoadAndDiscompressTask.Step _step)
        {
            switch (_step)
            {
                case DownLoadAndDiscompressTask.Step.DownLoadPrepared:
                    m_ContainerHint.SetActive(true);
                    m_ContainerProgress.SetActive(false);
                    DisplayHintContent();
                    break;
                case DownLoadAndDiscompressTask.Step.DownLoad:
                    m_ContainerHint.SetActive(false);
                    m_ContainerProgress.SetActive(true);
                    DisplayHintContent();
                    break;
            }
        }
 
        protected override void LateUpdate()
        {
            base.LateUpdate();
 
            var step = DownLoadAndDiscompressTask.Instance.step;
            if (step == DownLoadAndDiscompressTask.Step.DownLoad)
            {
                timer += Time.deltaTime;
                if (timer > 1f)
                {
                    timer -= 1f;
                    m_ProgressSlider.value = DownLoadAndDiscompressTask.Instance.progress;
                    var totalSizeString = ((float)DownLoadAndDiscompressTask.Instance.totalSize / DownLoadAndDiscompressTask.BYTE_PER_MILLIONBYTE).ToString("f1");
                    var downLoadedSize = Mathf.Clamp(DownloadMgr.Instance.DownloadedBytes, 0, DownLoadAndDiscompressTask.Instance.totalSize - 1);
                    var downLoadedSizeString = ((float)downLoadedSize / DownLoadAndDiscompressTask.BYTE_PER_MILLIONBYTE).ToString("f1");
 
                    m_Progress.text = Language.GetFromLocal(13, StringUtility.Contact(downLoadedSizeString, "M", "/", totalSizeString, "M"));
 
                    if (downLoadedSize >= DownLoadAndDiscompressTask.Instance.totalSize)
                    {
                        m_DownLoadSpeed.text = StringUtility.Contact(UnityEngine.Random.Range(5, 10), "KB/S");
                    }
                    else
                    {
                        m_DownLoadSpeed.text = DownloadMgr.Instance.SpeedFormat;
                    }
                }
            }
        }
 
        private void DisplayHintContent()
        {
            var step = DownLoadAndDiscompressTask.Instance.step;
 
            switch (step)
            {
                case DownLoadAndDiscompressTask.Step.DownLoadPrepared:
                    var totalCount = DownLoadAndDiscompressTask.Instance.totalCount;
                    var totalSize = DownLoadAndDiscompressTask.Instance.totalSize;
 
                    if (totalSize > DownLoadAndDiscompressTask.BYTE_PER_MILLIONBYTE)
                    {
                        var sizeDescription = ((float)totalSize / DownLoadAndDiscompressTask.BYTE_PER_MILLIONBYTE).ToString("f1");
                        m_Content.text = Language.GetFromLocal(DownLoadAndDiscompressTask.Instance.restartApp ? 1 : 2, totalCount, sizeDescription);
                    }
                    else
                    {
                        var sizeDescription = ((float)totalSize / DownLoadAndDiscompressTask.BYTE_PER_KILOBYTE).ToString("f1");
                        m_Content.text = Language.GetFromLocal(DownLoadAndDiscompressTask.Instance.restartApp ? 11 : 12, totalCount, sizeDescription);
                    }
                    break;
                case DownLoadAndDiscompressTask.Step.DownLoad:
                    m_Content.text = Language.GetFromLocal(3);
                    break;
            }
        }
 
        private void Confirm()
        {
            timer = 1f;
            var step = DownLoadAndDiscompressTask.Instance.step;
 
            switch (step)
            {
                case DownLoadAndDiscompressTask.Step.DownLoadPrepared:
                    DownLoadAndDiscompressTask.Instance.StartDownLoad();
                    break;
            }
        }
 
        private void Cancel()
        {
            Application.Quit();
        }
 
    }
 
}