weixudong
2020-11-12 52fb8c663b1e74b2a36b79bc70a452ca73db6341
Assets/Scripts/UI/FinalPanel/FinalPanel.cs
@@ -1,10 +1,13 @@
using UnityEngine.UI;
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
{
@@ -17,7 +20,6 @@
    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;
    public string endlessGameScene = "Endless";
@@ -33,6 +35,24 @@
            SceneManager.LoadScene(loadingScene);
        });
    }
    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>
    /// 入口函数
@@ -41,26 +61,108 @@
    /// <param name="myScore">789220</param>
    public void SetData(string waveInfo, int myScore)
    {
        transform.Find("Text_Wave").GetComponent<Text>().text = waveInfo;
        int hScore = PlayerPrefs.GetInt("GemBattleHScore");
        hScore = PlayerPrefs.GetInt("GemBattleHScore");
        scrollerCanvasGroup = transform.Find("Scroller").GetComponent<CanvasGroup>();
        if (myScore > hScore)
        {
            PlayerPrefs.SetInt("GemBattleHScore", myScore);
            hScore = myScore;
            isNewH = true;
        }
        transform.Find("Text_Score").GetComponent<Text>().text = myScore.ToString();
        transform.Find("Text_HScore").GetComponent<TextMeshProUGUI>().text = hScore.ToString();
        transform.Find("Image_HScore/Text_HScore").GetComponent<TextMeshProUGUI>().text = hScore.ToString();
        image_HScore = transform.Find("Image_HScore").gameObject;
        image_HScore.SetActive(false);
        scroller = transform.Find("Scroller").GetComponent<EnhancedScroller>();
        waveText = transform.Find("Text_Wave").GetComponent<Text>();
        scoreText = transform.Find("Text_Score").GetComponent<Text>();
        waveText.gameObject.SetActive(false);
        scoreText.gameObject.SetActive(false);
        scroller.Delegate = this;
        image_NewRecord = transform.Find("Image_NewRecord").gameObject;
        image_NewRecord.SetActive(false);
        LoadLargeData(hScore);
        Transform ts = transform.Find("Images");
        Sequence agentTweenSeq = DOTween.Sequence();
        agentTweenSeq.Append(ts.DOScale(Vector3.one, 0.2f));//变化图片大小
        agentTweenSeq.Append(ts.DOScale(new Vector3(1.7f, 1.7f, 1.7f), 0.2f));//变化图片大小
        agentTweenSeq.Append(ts.DOScale(Vector3.one, 0.2f));//变化图片大小
        agentTweenSeq.Append(ts.DOScale(new Vector3(1.2f, 1.2f, 1.2f), 0.2f));//变化图片大小
        agentTweenSeq.Append(ts.DOScale(Vector3.one, 0.2f));//变化图片大小
        agentTweenSeq.AppendCallback(StartLoadLargeData);
        agentTweenSeq.Append(DOTween.To(delegate (float value)
        {
            var temp = Math.Floor(value);
            scoreText.text = temp + "";
        }, 0, myScore, 3.0f));
        agentTweenSeq.AppendCallback(TextDoTweenFinish);
        agentTweenSeq.Append(waveText.DOText(waveInfo, 0.2f));
    }
    /// <summary>
    /// 开始展示排行榜
    /// </summary>
    protected void StartLoadLargeData()
    {
        scoreText.gameObject.SetActive(true);
        LoadLargeData(hScore);
        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);
        }
        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();
        }
    }
    /// <summary>
    /// 生成假排行榜
    /// </summary>
    /// <param name="hScore">自身分数</param>
    private void LoadLargeData(int hScore)
    {
        scroller = transform.Find("Scroller").GetComponent<EnhancedScroller>();
        scroller.Delegate = this;
        _data = new SmallList<FinalPanelItemData>();
        FinalPanelItemData data;
        int score = 101;