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
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
//--------------------------------------------------------
//    [Author]:           第二世界
//    [  Date ]:           Tuesday, September 05, 2017
//--------------------------------------------------------
 
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
 
 
 
    public class LaunchWin : UIBase
    {
        // [SerializeField] UIAlphaTween m_AlphaTween;
        [SerializeField] Image m_BackGround;
        [SerializeField] RectTransform m_AndroidProgressContainer;
        [SerializeField] RectTransform m_NetworkContainer;
        [SerializeField] SmoothSlider m_PartProgressSlider;
        [SerializeField] SmoothSlider m_TotalProgressSlider;
        [SerializeField] Text m_StageDescription;
        [SerializeField] RectTransform m_IosProgressContainer;
        [SerializeField] Text m_IosProgressTip;
        [SerializeField] Text m_BuildTime;
        [SerializeField] Text m_Version;
        [SerializeField] Button m_UserHelp;
 
        bool assetBuildTimeShowed = false;
 
        LaunchStage showStage = LaunchStage.None;
        int showStep = 0;
        string stepDescription = string.Empty;
 
        float backGroundTimer = 0f;
        int backGroundIndex = 0;
        List<Sprite> backGrounds = new List<Sprite>();
 
        int AllTimes = 0;
        int WaitSeconds = 0;
        bool ShowCircleView = false;
        float TempCheck = 0;
        protected override void InitComponent()
        {
            base.InitComponent();
            m_BackGround.preserveAspect = true;
            if (Application.isEditor)
            {
                var sprite = BuiltInLoader.LoadSprite("Launch_1");
                m_BackGround.overrideSprite = sprite;
            }
            else
            {
                for (var i = 0; i < 3; i++)
                {
                    var sprite = BuiltInLoader.LoadSprite(StringUtility.Contact("Launch_", i + 1));
                    if (sprite != null)
                    {
                        backGrounds.Add(sprite);
                    }
                }
 
                m_BackGround.overrideSprite = backGrounds[0];
            }
 
 
            // AddListener
            if (m_UserHelp)
            {
                m_UserHelp.SetListener(OpenUserHelp);
            }
        }
 
        protected override void OnPreOpen()
        {
            base.OnPreOpen();
            backGroundTimer = 0f;
            backGroundIndex = 0;
            if (m_TotalProgressSlider != null)
            {
                m_TotalProgressSlider.ResetValue(0f);
            }
 
            // m_AlphaTween.SetStartState();
 
            m_BuildTime.text = VersionConfig.Get().debugVersion ? VersionConfig.Get().buildTime : "";
 
            if (m_UserHelp)
            {
                var appId = VersionConfig.Get().appId;
                var branch = VersionConfig.Get().branch;
                //m_UserHelp.SetActive(ContactConfig.GetConfig(appId, branch) != null);
                m_UserHelp.SetActive(false);
            }
            if (m_NetworkContainer != null)
            {
                m_NetworkContainer.SetActive(false);
            } 
 
            var AppleCheck   = InitialFunctionConfig.Get("CheckTime").Numerical1;
            var AndroidCheck = InitialFunctionConfig.Get("CheckTime").Numerical2;
            var CheckAll = InitialFunctionConfig.Get("NetworkCheck").Numerical1;
            AllTimes = int.Parse(CheckAll);
            var CheckTime = InitialFunctionConfig.Get("NetworkCheck").Numerical2;
            WaitSeconds = int.Parse(CheckTime);
            ShowCircleView = false;
            if (Application.platform == RuntimePlatform.IPhonePlayer && AppleCheck == "1")
                ShowCircleView = true;
            if (Application.platform == RuntimePlatform.Android && AndroidCheck == "1")
                ShowCircleView = true;
 
            if (ShowCircleView)
            {
                m_AndroidProgressContainer.SetActive(false);
                m_IosProgressContainer.SetActive(true);
                m_Version.text = string.Empty;
            }
            else
            {
                m_AndroidProgressContainer.SetActive(true);
                m_IosProgressContainer.SetActive(false);
                //打包版本 + 功能版本 + 语言ID
                m_Version.text = LoginManager.Instance.GetVersionStr();
            }
 
            if (m_StageDescription != null)
            {
                m_StageDescription.text = GetLaunchStageDescription(showStage, showStep);
            }
 
            UpdateProgress();
 
            if (m_TotalProgressSlider == null)
            {
                m_TotalProgressSlider = this.GetComponentInChildren<SmoothSlider>(true);
            }
        }
 
        protected override void OnOpen()
        {
            base.OnOpen();
        }
 
        protected override void OnPreClose()
        {
            base.OnPreClose();
        }
 
        protected override void OnClose()
        {
            base.OnClose();
        }
 
        public void FadeOut()
        {
            // m_AlphaTween.Play();
            CloseWindow();
        }
 
        string GetLaunchStageDescription(LaunchStage _stage, int step)
        {
            switch (_stage)
            {
                case LaunchStage.SDKInit:
                    return Language.GetFromLocal(36);
                case LaunchStage.AssetCopy:
                    return StringUtility.Contact(Language.GetFromLocal(37), "(", step, ")");
                case LaunchStage.AssetDecompress:
                    return StringUtility.Contact(Language.GetFromLocal(38), "(", step, ")");
                case LaunchStage.ClientVersion:
                    return Language.GetFromLocal(39);
                case LaunchStage.CheckAsset:
                    return Language.GetFromLocal(40);
                case LaunchStage.DownLoad:
                    return Language.GetFromLocal(41);
                case LaunchStage.AssetBundleInit:
                    return Language.GetFromLocal(42);
                case LaunchStage.ConfigInit:
                    return StringUtility.Contact(Language.GetFromLocal(43), "(", step, ")");
                case LaunchStage.Complete:
                    return Language.GetFromLocal(44);
                default:
                    return "";
            }
        }
 
        protected void LateUpdate()
        {
            UpdateProgress();
 
            backGroundTimer += Time.deltaTime;
            if (backGroundTimer >= 3f)
            {
                backGroundTimer = 0f;
                if (backGrounds.Count > 1)
                {
                    m_BackGround.overrideSprite = backGrounds[(++backGroundIndex) % backGrounds.Count];
                }
            }
 
            if (HttpBehaviour.ConnectAllTimes >= AllTimes && m_NetworkContainer != null)
            {
                TempCheck += Time.deltaTime;
                m_NetworkContainer.SetActive(true);
                if (TempCheck >= WaitSeconds)
                {
                    TempCheck = 0;
                    m_NetworkContainer.SetActive(false);
                    HttpBehaviour.ConnectAllTimes = 0;
                }
            }
        }
 
        private void OpenUserHelp()
        {
            // TODO YYL
            // UIManager.Instance.OpenWindow<UserHelpWin>();
        }
        
        private void UpdateProgress()
        {
            //if (Application.platform == RuntimePlatform.IPhonePlayer)
            if(ShowCircleView)
            {
                m_IosProgressContainer.SetActive(LaunchInHot.progressInfo.stage != LaunchStage.DownLoad);
                var remainder = ((int)Time.time) % 3;
                var dot = remainder == 0 ? "." : remainder == 1 ? ".." : "...";
                m_IosProgressTip.text = StringUtility.Contact(Language.GetFromLocal(30), dot);
            }
            else
            {
                var progressInfo = LaunchInHot.progressInfo;
 
                if (progressInfo.stage == LaunchStage.DownLoad)
                {
                    if (m_PartProgressSlider != null && m_PartProgressSlider.gameObject.activeInHierarchy)
                    {
                        m_PartProgressSlider.SetActive(false);
                    }
 
                    if (m_TotalProgressSlider != null && m_TotalProgressSlider.gameObject.activeInHierarchy)
                    {
                        m_TotalProgressSlider.SetActive(false);
                    }
                }
                else
                {
                    if (m_PartProgressSlider != null && !m_PartProgressSlider.gameObject.activeInHierarchy)
                    {
                        m_PartProgressSlider.SetActive(true);
                    }
 
                    if (m_TotalProgressSlider != null && !m_TotalProgressSlider.gameObject.activeInHierarchy)
                    {
                        m_TotalProgressSlider.SetActive(true);
                    }
 
                    if (m_TotalProgressSlider != null)
                    {
                        m_TotalProgressSlider.value = progressInfo.totalProgress;
                    }
 
                    if (m_PartProgressSlider != null)
                    {
                        m_PartProgressSlider.value = progressInfo.partProgress;
                    }
                }
 
                DisplayStageDescription(progressInfo.stage, progressInfo.step);
 
                //if (!assetBuildTimeShowed && AssetVersionUtility.assetsBuildTime != DateTime.MinValue)
                //{
                //    assetBuildTimeShowed = true;
                //    var totalMinute = (int)(AssetVersionUtility.assetsBuildTime - new DateTime(2018, 1, 1)).TotalMinutes;
                //    m_Version.text = StringUtility.Contact(VersionConfig.Get().version, "_", VersionConfig.Get().buildIndex, "_", totalMinute.ToString());
                //}
            }
 
        }
 
        private void DisplayStageDescription(LaunchStage stage, int step)
        {
            if (showStage != stage || showStep != step)
            {
                showStage = stage;
                showStep = step;
                if (m_StageDescription != null)
                {
                    m_StageDescription.text = GetLaunchStageDescription(stage, step);
                }
            }
        }
 
        public LaunchWinData GetData()
        {
            return new LaunchWinData(){
                backGroundTimer = backGroundTimer,
                backGroundIndex = backGroundIndex,
                sprite = m_BackGround.overrideSprite,
                sprites = backGrounds,
            };
        }
 
    }