少年修仙传客户端代码仓库
client_Wu Xijin
2018-09-04 d9e6e5aac14261fad5bd18053b600bd513b45509
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
//--------------------------------------------------------
//    [Author]:           第二世界
//    [  Date ]:           Monday, September 04, 2017
//--------------------------------------------------------
 
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using TableConfig;
 
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] 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 mapResConfig = Config.Instance.Get<MapResourcesConfig>(targetMapResId);
            if (mapResConfig != null && mapResConfig.LoadingBG.Length > 0)
            {
                var randomIndex = UnityEngine.Random.Range(0, mapResConfig.LoadingBG.Length > 1 ? mapResConfig.LoadingBG.Length + 1 : 1);
                if (randomIndex == mapResConfig.LoadingBG.Length)
                {
                    m_BackGround.SetSprite(GeneralConfig.Instance.LoadLV);
                    m_ContainerFunctions.gameObject.SetActive(true);
                    var functions = GetShowFunctions(PlayerDatas.Instance.baseData.LV == 0 ? PlayerDatas.Instance.loginInfo.LV : PlayerDatas.Instance.baseData.LV);
                    for (int i = 0; i < m_FunctionShows.Length; i++)
                    {
                        var show = m_FunctionShows[i];
                        show.Display(functions[i]);
                    }
                }
                else
                {
                    m_BackGround.SetSprite(mapResConfig.LoadingBG[randomIndex]);
                    m_ContainerFunctions.gameObject.SetActive(false);
                }
            }
 
            if (mapResConfig != null && !string.IsNullOrEmpty(mapResConfig.LoadName))
            {
                m_ContainerMapName.gameObject.SetActive(true);
                m_MapName.SetSprite(mapResConfig.LoadName);
            }
            else
            {
                m_ContainerMapName.gameObject.SetActive(false);
            }
 
            if (mapResConfig != null && !string.IsNullOrEmpty(mapResConfig.LoadDescription))
            {
                m_ContainerMapDescription.gameObject.SetActive(true);
                m_MapDescription.SetSprite(mapResConfig.LoadDescription);
            }
            else
            {
                m_ContainerMapDescription.gameObject.SetActive(false);
            }
 
            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;
        }
 
    }
 
}