少年修仙传客户端代码仓库
client_Hale
2018-12-08 65fb6364670f86e21adfab1ae0b42a7be8dc07f4
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
//--------------------------------------------------------
//    [Author]:           第二世界
//    [  Date ]:           Monday, September 04, 2017
//--------------------------------------------------------
 
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using TableConfig;
using LitJson;
using System.Text.RegularExpressions;
 
namespace Snxxz.UI
{
 
    public class LoadingWin : Window
    {
        public static int targetMapResId = 0;
 
        [SerializeField] Image m_BackGround;
        [SerializeField] RectTransform m_ContainerFunctions;
        [SerializeField] LoadingFunctionShow[] m_FunctionShows;
        [SerializeField] RectTransform m_ContainerProgress;
        [SerializeField] SmoothSlider m_ProgressSlider;
        [SerializeField] Transform m_EffectPoint;
        [SerializeField] RectTransform m_ContainerMapName;
        [SerializeField] Image m_MapName;
        [SerializeField] RectTransform m_ContainerMapDescription;
        [SerializeField] Image m_MapDescription;
 
        float refProgress = 0f;
        float expectDuration = 5f;
 
        #region Built-in
        protected override void BindController()
        {
        }
 
        protected override void AddListeners()
        {
        }
 
        protected override void OnPreOpen()
        {
            var useDefautBackGround = false;
            if (!AssetSource.uiFromEditor)
            {
                var assetVersion = AssetVersionUtility.GetAssetVersion("ui/sprite/loadingbg");
                if (assetVersion == null || !assetVersion.localValid)
                {
                    useDefautBackGround = true;
                }
            }
 
            if (useDefautBackGround)
            {
                var sprite = BuiltInLoader.LoadSprite("Launch_1");
                m_BackGround.overrideSprite = sprite;
                m_ContainerMapName.gameObject.SetActive(false);
                m_ContainerMapDescription.gameObject.SetActive(false);
                m_ContainerFunctions.gameObject.SetActive(false);
            }
            else
            {
                var playerLevel = PlayerDatas.Instance.baseData.LV == 0 ? PlayerDatas.Instance.loginInfo.LV : PlayerDatas.Instance.baseData.LV;
                var mapResConfig = Config.Instance.Get<MapResourcesConfig>(targetMapResId);
                if (mapResConfig != null)
                {
                    var loadingBackGroudConfig = LoadingBackGroundConfig.Get(mapResConfig.DataID, mapResConfig.LineID);
                    if (loadingBackGroudConfig != null && loadingBackGroudConfig.icons.Length > 0)
                    {
                        var icons = new List<string>();
                        var json = JsonMapper.ToObject(loadingBackGroudConfig.levelLimit);
 
                        for (var i = 0; i < loadingBackGroudConfig.icons.Length; i++)
                        {
                            var icon = loadingBackGroudConfig.icons[i];
                            if (json.Keys.Contains(icon))
                            {
                                var min = 0;
                                var max = int.MaxValue;
                                var levelLimit = json[icon].ToString();
                                var levelsMatch = Regex.Matches(levelLimit, "\\d+");
                                if (levelsMatch.Count > 0)
                                {
                                    min = int.Parse(levelsMatch[0].Value);
                                }
 
                                if (levelsMatch.Count > 1)
                                {
                                    max = int.Parse(levelsMatch[1].Value);
                                }
 
                                if (playerLevel > min && playerLevel < max)
                                {
                                    icons.Add(icon);
                                }
                            }
                            else
                            {
                                icons.Add(icon);
                            }
                        }
 
                        var randomIndex = UnityEngine.Random.Range(0, loadingBackGroudConfig.icons.Length > 1 ? icons.Count + 1 : 1);
                        if (randomIndex == icons.Count)
                        {
                            m_BackGround.SetSprite(GeneralDefine.LoadLV);
                            m_ContainerFunctions.gameObject.SetActive(true);
                            var functions = GetShowFunctions(playerLevel);
                            for (int i = 0; i < m_FunctionShows.Length; i++)
                            {
                                var show = m_FunctionShows[i];
                                show.Display(functions[i]);
                            }
                        }
                        else
                        {
                            m_BackGround.SetSprite(icons[randomIndex]);
                            m_ContainerFunctions.gameObject.SetActive(false);
                        }
 
                        if (loadingBackGroudConfig != null && !string.IsNullOrEmpty(loadingBackGroudConfig.name))
                        {
                            m_ContainerMapName.gameObject.SetActive(true);
                            m_MapName.SetSprite(loadingBackGroudConfig.name);
                        }
                        else
                        {
                            m_ContainerMapName.gameObject.SetActive(false);
                        }
 
                        if (loadingBackGroudConfig != null && !string.IsNullOrEmpty(loadingBackGroudConfig.description))
                        {
                            m_ContainerMapDescription.gameObject.SetActive(true);
                            m_MapDescription.SetSprite(loadingBackGroudConfig.description);
                        }
                        else
                        {
                            m_ContainerMapDescription.gameObject.SetActive(false);
                        }
 
                    }
                }
            }
 
            if (Application.platform == RuntimePlatform.IPhonePlayer)
            {
                m_ContainerProgress.gameObject.SetActive(false);
            }
            else
            {
                m_ContainerProgress.gameObject.SetActive(true);
                m_ProgressSlider.value = refProgress = 0f;
                StageManager.Instance.loadingProgressEvent += UpdateLoadingProgress;
            }
        }
 
        protected override void OnAfterOpen()
        {
        }
 
        protected override void OnPreClose()
        {
            StageManager.Instance.loadingProgressEvent -= UpdateLoadingProgress;
 
            if (!AssetSource.uiFromEditor)
            {
                AssetBundleUtility.Instance.UnloadAssetBundle("ui/sprite/loading", true, false);
                AssetBundleUtility.Instance.UnloadAssetBundle("ui/sprite/loadingbg", true, false);
            }
        }
 
        protected override void OnAfterClose()
        {
        }
        #endregion
 
 
        protected override void LateUpdate()
        {
            base.LateUpdate();
 
            refProgress = Mathf.Clamp01(refProgress + Time.deltaTime / expectDuration);
            m_ProgressSlider.value = refProgress;
        }
 
        void UpdateLoadingProgress(float _progress)
        {
            m_ProgressSlider.value = refProgress = Mathf.Max(_progress, refProgress);
        }
 
        private List<int> GetShowFunctions(int _level)
        {
            var configs = Config.Instance.GetAllValues<LoadingFunctionConfig>();
            var functions = new List<int>() { configs[0].ID, configs[1].ID, configs[2].ID, configs[3].ID };
            for (int i = 4; i < configs.Count; i++)
            {
                var config = Config.Instance.Get<LoadingFunctionConfig>(functions[2]);
                if (_level >= config.Level)
                {
                    functions.RemoveAt(0);
                    functions.Add(configs[i].ID);
                }
            }
 
            return functions;
        }
 
    }
 
}