少年修仙传客户端代码仓库
client_Wu Xijin
2018-10-26 82931aabaaa3e479bc04e11630a77cd9c9dd5fe3
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
//--------------------------------------------------------
//    [Author]:           第二世界
//    [  Date ]:           Tuesday, September 05, 2017
//--------------------------------------------------------
 
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using TableConfig;
 
namespace Snxxz.UI
{
 
    public class LaunchWin : Window
    {
        [SerializeField] UIAlphaTween m_AlphaTween;
        [SerializeField] Image m_BackGround;
        [SerializeField] RectTransform m_AndroidProgressContainer;
        [SerializeField] SmoothSlider m_ProgressSlider;
        [SerializeField] Text m_Progress;
        [SerializeField] RectTransform m_IosProgressContainer;
        [SerializeField] Text m_IosProgressTip;
        [SerializeField] Text m_BuildTime;
        [SerializeField] Text m_Version;
        [SerializeField] Button m_UserHelp;
 
        bool assetBuildTimeShowed = false;
 
        string stepDescription = string.Empty;
 
        float refProgress = 0f;
        float behaviourProgress = 0f;
        float trueProgress = 0f;
 
        float timer = 0.1f;
        float interval = 0.1f;
 
        #region Built-in
        protected override void BindController()
        {
            var sprite = BuiltInLoader.LoadSprite("Launch");
            m_BackGround.overrideSprite = sprite;
        }
 
        protected override void AddListeners()
        {
            if (m_UserHelp)
            {
                m_UserHelp.SetListener(OpenUserHelp);
            }
        }
 
        protected override void OnPreOpen()
        {
            refProgress = 0f;
            behaviourProgress = 0f;
            trueProgress = 0f;
            m_ProgressSlider.ResetValue(0f);
            m_AlphaTween.SetStartState();
 
            m_Version.text = StringUtility.Contact(VersionConfig.Get().version, "_", VersionConfig.Get().buildIndex);
            m_BuildTime.text = VersionConfig.Get().debugVersion ? VersionConfig.Get().buildTime : "";
 
            if (m_UserHelp)
            {
                var appId = VersionConfig.Get().appId;
                var branch = VersionConfig.Get().branch;
                m_UserHelp.gameObject.SetActive(ContactConfig.GetConfig(appId, branch) != null);
            }
 
            if (Application.platform == RuntimePlatform.IPhonePlayer)
            {
                m_AndroidProgressContainer.gameObject.SetActive(false);
                m_IosProgressContainer.gameObject.SetActive(true);
                m_IosProgressTip.text = Language.GetFromLocal(30);
            }
            else
            {
                m_AndroidProgressContainer.gameObject.SetActive(true);
                m_IosProgressContainer.gameObject.SetActive(false);
                m_Progress.text = VersionUtility.Instance.IsShangGu() ? "" : StringUtility.Contact(0, "%");
                UpdateLoadingProgress(Launch.currentStage, Launch.progress);
                Launch.progressEvent += UpdateLoadingProgress;
            }
        }
 
        protected override void OnAfterOpen()
        {
        }
 
        protected override void OnPreClose()
        {
            Launch.progressEvent -= UpdateLoadingProgress;
        }
 
        protected override void OnAfterClose()
        {
        }
        #endregion
 
        public void FadeOut()
        {
            m_AlphaTween.Play();
        }
 
        void UpdateLoadingProgress(Launch.LaunchStage _stage, float _progress)
        {
            trueProgress = Mathf.Max(_progress, behaviourProgress);
            switch (_stage)
            {
                case Launch.LaunchStage.AssetCopy:
                    stepDescription = Language.GetFromLocal(14);
                    break;
                case Launch.LaunchStage.ClientVersion:
                    stepDescription = Language.GetFromLocal(15);
                    break;
                case Launch.LaunchStage.DownLoad:
                    stepDescription = Language.GetFromLocal(16);
                    break;
                case Launch.LaunchStage.ConfigLoad:
                    stepDescription = Language.GetFromLocal(17);
                    break;
            }
 
        }
 
        protected override void LateUpdate()
        {
            base.LateUpdate();
 
            if (Application.platform == RuntimePlatform.IPhonePlayer)
            {
                m_IosProgressContainer.gameObject.SetActive(Launch.currentStage != Launch.LaunchStage.DownLoad);
                var remainder = ((int)Time.time) % 3;
                var dot = remainder == 0 ? "." : remainder == 1 ? ".." : "...";
                m_IosProgressTip.text = StringUtility.Contact(Language.GetFromLocal(30), dot);
            }
            else
            {
                if (trueProgress > 0.9599f)
                {
                    behaviourProgress = Mathf.Clamp01(behaviourProgress + Time.deltaTime * 0.2f);
                }
                else
                {
                    behaviourProgress = Mathf.SmoothDamp(behaviourProgress, trueProgress, ref refProgress, 0.2f);
                }
 
                m_ProgressSlider.value = behaviourProgress;
                m_Progress.text = VersionUtility.Instance.IsShangGu() ? stepDescription :
                    StringUtility.Contact(stepDescription, Mathf.RoundToInt(behaviourProgress * 100), "%");
 
                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 OpenUserHelp()
        {
            WindowCenter.Instance.OpenFromLocal<UserHelpWin>();
        }
 
    }
}