wangguan
2020-12-03 ad376c4760e5e0c2183c51d21d044fd4d03f9721
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
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
using System.Collections.Generic;
using System.Collections;
using UnityEngine.UI;
using UnityEngine;
using EnhancedUI;
using EnhancedUI.EnhancedScroller;
using TMPro;
using UnityEngine.SceneManagement;
using KTGMGemClient;
using DG.Tweening;
using System;
 
public class FinalPanel : MonoBehaviour, IEnhancedScrollerDelegate
{
    private EnhancedScroller scroller;
 
    private SmallList<FinalPanelItemData> _data;
    //private List<FinalPanelItemData> _data;
    public EnhancedScrollerCellView cellViewPrefab;
    [SerializeField]
    private Sprite rank_di_0, rank_di_1, rank_di_2, rank_di_03;
    [SerializeField]
    private Sprite rank_icon_0, rank_icon_1, rank_icon_2;
 
    private string endlessGameScene = "Endless2D";
 
    private string loadingScene = "LoadingScene";
    Button closeBtn;
    // Start is called before the first frame update
    void Start()
    {
        closeBtn = transform.Find("BackGround").GetComponent<Button>();
        closeBtn.onClick.AddListener(() =>
        {
            gameObject.SetActive(false);
            GameConfig.NextSceneName = endlessGameScene;
            SceneManager.LoadScene(loadingScene);
        });
        closeBtn.interactable = false;
    }
    Text waveText;
    GameObject image_HScore;
    Text scoreText;
    GameObject image_NewRecord;
    bool isNewH = false;
    int hScore;
    CanvasGroup scrollerCanvasGroup;
 
    Action playEffectAC = null;
 
    /// <summary>
    /// 设置播放胜利特效
    /// </summary>
    /// <param name="ac"></param>
    public void SetPlayEffectAC(Action ac)
    {
        playEffectAC = ac;
    }
 
    /// <summary>
    /// 入口函数
    /// </summary>
    /// <param name="waveInfo">成绩 25关 3波</param>
    /// <param name="myScore">789220</param>
    public void SetData(string waveInfo, int myScore)
    {
        hScore = PlayerPrefs.GetInt("GemBattleHScore");
        //scrollerCanvasGroup = transform.Find("Scroll View").GetComponent<CanvasGroup>();
        scrollerCanvasGroup = transform.Find("Scroller").GetComponent<CanvasGroup>();
        if (myScore > hScore)
        {
            PlayerPrefs.SetInt("GemBattleHScore", myScore);
            hScore = myScore;
            isNewH = true;
        }
 
        transform.Find("Image_HScore/Text_HScore").GetComponent<TextMeshProUGUI>().text = hScore.ToString();
        image_HScore = transform.Find("Image_HScore").gameObject;
        image_HScore.SetActive(false);
 
        waveText = transform.Find("Text_Wave").GetComponent<Text>();
        scoreText = transform.Find("Text_Score").GetComponent<Text>();
        scoreText.text = "";
        waveText.text = "";
        waveText.gameObject.SetActive(false);
        scoreText.gameObject.SetActive(false);
 
        image_NewRecord = transform.Find("Image_NewRecord").gameObject;
        image_NewRecord.SetActive(false);
        LoadLargeData(hScore);
 
        Transform ts = transform.Find("Images");
 
        Sequence agentTweenSeq = DOTween.Sequence();
        //先出现
        Image tsTiele = transform.Find("Image_Tiele").GetComponent<Image>();
        agentTweenSeq.Append(tsTiele.transform.DOScale(Vector3.one, 0.2f));//变化图片大小
        agentTweenSeq.Join(tsTiele.DOFade(1, 0.3f));
 
        Image Image1 = transform.Find("Image1").GetComponent<Image>();
        agentTweenSeq.Append(Image1.transform.DOScale(Vector3.one, 0.2f));//变化图片大小
        agentTweenSeq.Join(Image1.DOFade(1, 0.2f));
        agentTweenSeq.Join(waveText.DOText(waveInfo, 0.2f));
 
        Image Image2 = transform.Find("Image2").GetComponent<Image>();
        agentTweenSeq.Append(Image2.transform.DOScale(Vector3.one, 0.2f));//变化图片大小
        agentTweenSeq.Join(Image2.DOFade(1, 0.2f));
 
        agentTweenSeq.AppendCallback(StartLoadLargeData);
 
        Image Image3 = transform.Find("Image3").GetComponent<Image>();
        agentTweenSeq.Append(Image3.transform.DOScale(Vector3.one, 0.2f));//变化图片大小
        agentTweenSeq.Join(Image3.DOFade(1, 0.2f));
        agentTweenSeq.Join(DOTween.To(delegate (float value)
        {
            var temp = Math.Floor(value);
            scoreText.text = temp + "";
        }, 0, myScore, 1.0f));
 
        tsLight = transform.Find("ImageLight");
        Image ImageLight = tsLight.GetComponent<Image>();
        agentTweenSeq.Join(ImageLight.transform.DOScale(Vector3.one, 0.2f));//变化图片大小
        agentTweenSeq.Join(ImageLight.DOFade(1, 0.2f).OnComplete(RotateLight));
        //agentTweenSeq.AppendCallback(RotateLight);
 
        agentTweenSeq.AppendCallback(TextDoTweenFinish);
    }
 
    bool isRotate = false;
    float offect = 0;
    /// <summary>
    /// LateUpdate is called every frame, if the Behaviour is enabled.
    /// It is called after all Update functions have been called.
    /// </summary>
    void LateUpdate()
    {
        if (isRotate)
        {
            offect += Time.deltaTime;
            tsLight.localRotation = Quaternion.Euler(0, 0, offect * 30);
        }
    }
 
    /// <summary>
    /// 开始展示排行榜
    /// </summary>
    protected void StartLoadLargeData()
    {
        scoreText.gameObject.SetActive(true);
        scrollerCanvasGroup.alpha = 1;
 
        //StartCoroutine(PlayerItemDoTween());
    }
 
    /// <summary>
    /// 播放排行榜动效
    /// </summary>
    /// <returns></returns>
    IEnumerator PlayerItemDoTween()
    {
        //yield return 1f;
        // FinalPanelItem[] allItems = transform.Find("Scroller/Container").GetComponentsInChildren<FinalPanelItem>();
        // for (int i = 0; i < allItems.Length; i++)
        // {
        //     allItems[i].SetPos();
        // }
 
        yield return new WaitForEndOfFrame();
        scrollerCanvasGroup.alpha = 1;
        // for (int i = 0; i < allItems.Length; i++)
        // {
        //     allItems[i].PlayDoTween(0.1f);
        //     yield return new WaitForSeconds(0.1f);
        // }
        for (int i = 0; i < 8; i++)
        {
            allItemLis[i].PlayDoTween(0.1f);
            yield return new WaitForSeconds(0.07f);
        }
        image_HScore.SetActive(true);
 
        yield break;
    }
 
    /// <summary>
    /// 文字显示结束,显示波次和是否最高记录
    /// </summary>
    protected void TextDoTweenFinish()
    {
        waveText.gameObject.SetActive(true);
        if (isNewH)
        {
            image_NewRecord.SetActive(true);
        }
 
        if (playEffectAC != null)
        {
            playEffectAC();
        }
 
        closeBtn.interactable = true;
    }
 
    Transform tsLight;
    /// <summary>
    /// 光出现后开始旋转
    /// </summary>
    protected void RotateLight()
    {
        isRotate = true;
        offect = 0;
        //Transform ImageLight = transform.Find("ImageLight");
        //ImageLight.DORotate(new Vector3(0, 180, 0), 1.0f).SetLoops(-1,LoopType.Incremental);
    }
 
    List<FinalPanelItem> allItemLis;//新生成的排行榜
    /// <summary>
    /// 生成假排行榜
    /// </summary>
    /// <param name="hScore">自身分数</param>
    private void LoadLargeData(int hScore)
    {
        scroller = transform.Find("Scroller").GetComponent<EnhancedScroller>();
        scroller.Delegate = this;
        _data = new SmallList<FinalPanelItemData>();
 
        //Transform content = transform.Find("Scroll View/Viewport/Content");
        //_data = new List<FinalPanelItemData>();
        FinalPanelItemData data;
        int score = 101;
        //GameObject go;
        //FinalPanelItem tmpData;
        //allItemLis = new List<FinalPanelItem>();
        for (var i = 0; i < 100; i++)
        {
            //go = Instantiate(cellViewPrefab.gameObject, content);
            //tmpData = go.GetComponent<FinalPanelItem>();
            //allItemLis.Add(tmpData);
            data = new FinalPanelItemData();
            data.score = score - i;
            data.index = i + 1;
            data.playerName = "游客" + i.ToString();
            data.spriteIcon = null;
            data.spriteBackGround = rank_di_03;
            _data.Add(data);
        }
 
        _data[0].playerName = "自己";
        _data[0].score = hScore;
        _data[0].spriteIcon = rank_icon_0;
        _data[0].spriteBackGround = rank_di_0;
 
        _data[1].spriteIcon = rank_icon_1;
        _data[1].spriteBackGround = rank_di_1;
 
        _data[2].spriteIcon = rank_icon_2;
        _data[2].spriteBackGround = rank_di_2;
 
        // tell the scroller to reload now that we have the data
        scroller.ReloadData();
        // for (int i = 0; i < allItemLis.Count; i++)
        // {
        //     allItemLis[i].SetData(_data[i]);
        // }
 
        // for (int i = 0; i < 8; i++)
        // {
        //     allItemLis[i].SetPos();
        // }
 
    }
 
    #region EnhancedScroller Handlers
 
 
    /// <summary>
    /// 个数
    /// </summary>
    /// <param name="scroller"></param>
    /// <returns></returns>
    public int GetNumberOfCells(EnhancedScroller scroller)
    {
        return _data.Count;
    }
 
 
    /// <summary>
    /// 控制item的大小
    /// </summary>
    /// <param name="scroller"></param>
    /// <param name="dataIndex"></param>
    /// <returns></returns>
    public float GetCellViewSize(EnhancedScroller scroller, int dataIndex)
    {
        return 70f;
        //return (dataIndex % 2 == 0 ? 30f : 100f);
    }
 
    /// <summary>
    /// 渲染
    /// </summary>
    /// <param name="scroller"></param>
    /// <param name="dataIndex"></param>
    /// <param name="cellIndex"></param>
    /// <returns></returns>
    public EnhancedScrollerCellView GetCellView(EnhancedScroller scroller, int dataIndex, int cellIndex)
    {
        FinalPanelItem cellView = scroller.GetCellView(cellViewPrefab) as FinalPanelItem;
        cellView.SetData(_data[dataIndex]);
        return cellView;
    }
 
    #endregion
 
}
 
public class FinalPanelItemData
{
    public string playerName;
    public int score;
    public int index;
 
    public Sprite spriteIcon;
    public Sprite spriteBackGround;
 
}