少年修仙传客户端代码仓库
client_Wu Xijin
2019-06-13 033958214c0b16d7e7b93cc821b018c295251867
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
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
//--------------------------------------------------------
//    [Author]:           第二世界
//    [  Date ]:           Wednesday, March 28, 2018
//--------------------------------------------------------
 
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using System.IO;
 
namespace Snxxz.UI
{
 
    public class VersionUpdateWin : Window
    {
        [SerializeField] RectTransform m_ContainerHint;
        [SerializeField] RichText m_HintDescription;
        [SerializeField] RectTransform m_UpdateContentContainer;
        [SerializeField] RichText m_UpdateCotent;
        [SerializeField] Button m_Confirm;
 
        [SerializeField] Transform m_ContainerProgress;
        [SerializeField] SmoothSlider m_ProgressSlider;
        [SerializeField] Text m_Progress;
        [SerializeField] Text m_DownLoadSpeed;
 
        float timer = 1f;
 
        #region Built-in
 
        protected override void BindController()
        {
            m_Confirm.AddListener(Confirm);
        }
 
        protected override void AddListeners()
        {
        }
 
        protected override void OnPreOpen()
        {
            OnDownLoadStepChange(VersionUtility.Instance.step);
        }
 
        protected override void OnAfterOpen()
        {
            VersionUtility.Instance.downLoadStepChangeEvent += OnDownLoadStepChange;
        }
 
        protected override void OnPreClose()
        {
            VersionUtility.Instance.downLoadStepChangeEvent -= OnDownLoadStepChange;
        }
 
        protected override void OnAfterClose()
        {
        }
 
        #endregion
 
        private void OnDownLoadStepChange(VersionUtility.Step _step)
        {
            switch (_step)
            {
                case VersionUtility.Step.None:
                    break;
                case VersionUtility.Step.ApkExist:
                    m_ContainerHint.gameObject.SetActive(true);
                    m_ContainerProgress.gameObject.SetActive(false);
                    DisplayHintContent();
                    break;
                case VersionUtility.Step.DownLoadPrepared:
                case VersionUtility.Step.DownLoadFailed:
                    m_ContainerHint.gameObject.SetActive(true);
                    m_ContainerProgress.gameObject.SetActive(false);
                    DisplayHintContent();
                    break;
                case VersionUtility.Step.DownLoad:
                    m_ContainerHint.gameObject.SetActive(false);
                    m_ContainerProgress.gameObject.SetActive(true);
                    DisplayHintContent();
                    break;
            }
        }
 
        protected override void LateUpdate()
        {
            base.LateUpdate();
 
            var step = VersionUtility.Instance.step;
            if (step == VersionUtility.Step.DownLoad)
            {
                timer += Time.deltaTime;
                if (timer > 1f)
                {
                    timer -= 1f;
 
                    m_ProgressSlider.value = VersionUtility.Instance.progress;
 
                    var totalSizeString = ((float)VersionUtility.Instance.GetApkSize() * 1024 / DownLoadAndDiscompressTask.BYTE_PER_MILLIONBYTE).ToString("f1");
                    var downLoadedSize = Mathf.Clamp(RemoteFile.TotalDownloadedSize, 0, VersionUtility.Instance.GetApkSize() * 1024);
                    var downLoadedSizeString = ((float)downLoadedSize / DownLoadAndDiscompressTask.BYTE_PER_MILLIONBYTE).ToString("f1");
 
                    m_Progress.text = Language.GetFromLocal(13, StringUtility.Contact(downLoadedSizeString, "M", "/", totalSizeString, "M"));
                }
 
                if (Time.frameCount % 2 == 0)
                {
                    if (RemoteFile.TotalDownloadedSize >= VersionUtility.Instance.GetApkSize() * 1024)
                    {
                        m_DownLoadSpeed.text = StringUtility.Contact(UnityEngine.Random.Range(5, 10), "KB/S");
                    }
                    else
                    {
                        m_DownLoadSpeed.text = RemoteFile.DownloadSpeed;
                    }
                }
            }
        }
 
        private void DisplayHintContent()
        {
            var step = VersionUtility.Instance.step;
            switch (step)
            {
                case VersionUtility.Step.None:
                    m_HintDescription.text = Language.GetFromLocal(4);
                    break;
                case VersionUtility.Step.ApkExist:
                    m_HintDescription.text = Language.GetFromLocal(5);
                    break;
                case VersionUtility.Step.DownLoadPrepared:
                    if (Application.platform == RuntimePlatform.Android)
                    {
                        var totalSize = VersionUtility.Instance.GetApkSize();
                        var sizeDescription = ((float)totalSize / DownLoadAndDiscompressTask.BYTE_PER_KILOBYTE).ToString("f1");
                        switch (Application.internetReachability)
                        {
                            case NetworkReachability.NotReachable:
                                m_HintDescription.text = Language.GetFromLocal(6, sizeDescription);
                                break;
                            case NetworkReachability.ReachableViaCarrierDataNetwork:
                                m_HintDescription.text = Language.GetFromLocal(7, sizeDescription);
                                break;
                            case NetworkReachability.ReachableViaLocalAreaNetwork:
                                m_HintDescription.text = Language.GetFromLocal(8, sizeDescription);
                                break;
                        }
                    }
                    else if (Application.platform == RuntimePlatform.IPhonePlayer)
                    {
                        m_HintDescription.text = Language.GetFromLocal(9);
                    }
                    break;
                case VersionUtility.Step.DownLoad:
                    m_HintDescription.text = Language.GetFromLocal(3);
                    break;
                case VersionUtility.Step.DownLoadFailed:
                    m_HintDescription.text = Language.GetFromLocal(10);
                    break;
            }
 
            switch (step)
            {
                case VersionUtility.Step.ApkExist:
                case VersionUtility.Step.DownLoadPrepared:
                    var updateContent = VersionUtility.Instance.GetUpdateContent();
                    if (string.IsNullOrEmpty(updateContent))
                    {
                        m_UpdateContentContainer.gameObject.SetActive(false);
                    }
                    else
                    {
                        m_UpdateContentContainer.gameObject.SetActive(true);
                        m_UpdateCotent.text = updateContent;
                    }
                    break;
                default:
                    m_UpdateContentContainer.gameObject.SetActive(false);
                    break;
            }
 
        }
 
        private void Confirm()
        {
            timer = 1f;
            var step = VersionUtility.Instance.step;
 
            switch (step)
            {
                case VersionUtility.Step.None:
                    VersionUtility.Instance.RequestVersionCheck();
                    break;
                case VersionUtility.Step.ApkExist:
                    SDKUtility.Instance.InstallAPK(VersionUtility.Instance.GetApkLocalUrl());
                    break;
                case VersionUtility.Step.DownLoadPrepared:
                    switch (Application.platform)
                    {
                        case RuntimePlatform.Android:
                            VersionUtility.Instance.StartDownLoad();
                            break;
                        case RuntimePlatform.IPhonePlayer:
                            Application.OpenURL(VersionUtility.Instance.GetApkRemoteUrl());
                            //打开应用商店链接
                            break;
                        case RuntimePlatform.WindowsPlayer:
                            //打开下载链接
                            Application.OpenURL(VersionUtility.Instance.GetApkRemoteUrl());
                            break;
                    }
                    break;
                case VersionUtility.Step.DownLoadFailed:
                    VersionUtility.Instance.StartDownLoad();
                    break;
            }
        }
 
    }
 
}