| | |
| | | using UnityEngine.UI; |
| | | 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 EnhancedScroller scroller; |
| | | |
| | | private SmallList<FinalPanelItemData> _data; |
| | | |
| | | //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() |
| | | { |
| | | |
| | | transform.Find("BackGround").GetComponent<Button>().onClick.AddListener(() => |
| | | closeBtn = transform.Find("BackGround").GetComponent<Button>(); |
| | | closeBtn.onClick.AddListener(() => |
| | | { |
| | | gameObject.SetActive(false); |
| | | GameConfig.NextSceneName = endlessGameScene; |
| | | SceneManager.LoadScene(loadingScene); |
| | | }); |
| | | SetData("成绩 5关 2波", 777777); |
| | | 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> |
| | |
| | | /// <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("Scroll View").GetComponent<CanvasGroup>(); |
| | | //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>(); |
| | | scoreText.text = ""; |
| | | waveText.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(); |
| | | //先出现 |
| | | 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); |
| | | 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) |
| | | { |
| | | _data = new SmallList<FinalPanelItemData>(); |
| | | //scroller = transform.Find("Scroller").GetComponent<EnhancedScroller>(); |
| | | Transform content = transform.Find("Scroll View/Viewport/Content"); |
| | | |
| | | //scroller.Delegate = this; |
| | | _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[2].spriteIcon = rank_icon_2; |
| | | _data[2].spriteBackGround = rank_di_2; |
| | | |
| | | // tell the scroller to reload now that we have the data |
| | | scroller.ReloadData(); |
| | | //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 |