| | |
| | | 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; |
| | | using System.Linq; |
| | | |
| | | public class FinalPanel : MonoBehaviour, IEnhancedScrollerDelegate |
| | | { |
| | | //无限滚动相关 |
| | | private EnhancedScroller scroller; |
| | | |
| | | private SmallList<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"; |
| | | // 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(() => |
| | | { |
| | | goonText.DOKill(); |
| | | gameObject.SetActive(false); |
| | | GameConfig.NextSceneName = endlessGameScene; |
| | | SceneManager.LoadScene(loadingScene); |
| | | }); |
| | | SetData("成绩 5关 2波", 777777); |
| | | closeBtn.interactable = false; |
| | | } |
| | | Button closeBtn; |
| | | Text waveText; |
| | | GameObject image_HScore; |
| | | Text scoreText; |
| | | GameObject image_NewRecord; |
| | | bool isNewH = false; |
| | | int hScore;//最高分 |
| | | int tmpRank;//当前排名 |
| | | int tmpRankUp;//排名上升了多少 |
| | | //string hwaveInfo; |
| | | |
| | | CanvasGroup scrollerCanvasGroup; |
| | | CanvasGroup itemCanvasGroup; |
| | | |
| | | ParticleSystem endPs;//最终特效 |
| | | |
| | | string playerPrefs_HScore = "GemBattleHScore"; |
| | | //string playerPrefs_HWaveInfo = "GemBattleHWaveInfo"; |
| | | string playerPrefs_HRank = "GemBattleHRank"; |
| | | |
| | | string playerPrefs_NickName = "GemBattlePlayerNickName"; |
| | | |
| | | string _waveInfo; |
| | | int _myScore;//本次 |
| | | FinalHttp finalHttp; |
| | | string playerNickName; |
| | | int _limit; |
| | | int _limitUp; |
| | | |
| | | FinalPanelItem itemFirst;//第一 |
| | | FinalPanelItem itemSecond;//第二 |
| | | FinalPanelItem itemThird;//第三 |
| | | Text txt_Name, txt_Wave; |
| | | TextMeshProUGUI txt_HScore, txt_Index; |
| | | |
| | | TextMeshProUGUI rankUpbj; |
| | | GameObject newPlayerImage;//新用户提示 |
| | | GameObject httpCountDownPanel; |
| | | Text goonText; |
| | | |
| | | /// <summary> |
| | | /// 入口函数 |
| | | /// </summary> |
| | | /// <param name="waveInfo">成绩 25关 3波</param> |
| | | /// <param name="waveInfo">25关 3波</param> |
| | | /// <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"); |
| | | if (myScore > hScore) |
| | | AudioSourceManager.Ins.StopBGAudio();//进来后停止播放BGM |
| | | |
| | | _waveInfo = waveInfo; |
| | | _myScore = myScore; |
| | | isFirstStart = true;//首次启动下载到数据执行动效 |
| | | _data = new SmallList<FinalPanelItemData>(); |
| | | Debug.Log($"_myScore:{_myScore} _waveInfo:{_waveInfo}"); |
| | | |
| | | hScore = PlayerPrefs.GetInt(playerPrefs_HScore); |
| | | tmpRank = PlayerPrefs.GetInt(playerPrefs_HRank); |
| | | tmpRankUp = 0; |
| | | //hwaveInfo = PlayerPrefs.GetString(playerPrefs_HWaveInfo); |
| | | scrollerCanvasGroup = transform.Find("Scroller").GetComponent<CanvasGroup>(); |
| | | scrollerCanvasGroup.alpha = 0; |
| | | itemCanvasGroup = transform.Find("ItemPanel").GetComponent<CanvasGroup>(); |
| | | itemCanvasGroup.alpha = 0; |
| | | |
| | | if (myScore > hScore)//得分比记录的高 |
| | | { |
| | | PlayerPrefs.SetInt("GemBattleHScore", myScore); |
| | | PlayerPrefs.SetInt(playerPrefs_HScore, myScore); |
| | | //PlayerPrefs.SetString(playerPrefs_HWaveInfo, waveInfo); |
| | | hScore = myScore; |
| | | //hwaveInfo = waveInfo; |
| | | isNewH = true; |
| | | } |
| | | |
| | | transform.Find("Text_Score").GetComponent<Text>().text = myScore.ToString(); |
| | | transform.Find("Text_HScore").GetComponent<TextMeshProUGUI>().text = hScore.ToString(); |
| | | txt_Name = transform.Find("Image_HScore/Text_Name").GetComponent<Text>(); |
| | | txt_Wave = transform.Find("Image_HScore/Text_Wave").GetComponent<Text>(); |
| | | txt_HScore = transform.Find("Image_HScore/Text_HScore").GetComponent<TextMeshProUGUI>(); |
| | | txt_Index = transform.Find("Image_HScore/Text_Index").GetComponent<TextMeshProUGUI>(); |
| | | |
| | | scroller = transform.Find("Scroller").GetComponent<EnhancedScroller>(); |
| | | |
| | | scroller.Delegate = this; |
| | | transform.Find("Image_HScore/Text_HScore").GetComponent<TextMeshProUGUI>().text = hScore.ToString(); |
| | | image_HScore = transform.Find("Image_HScore").gameObject; |
| | | image_HScore.SetActive(false); |
| | | |
| | | LoadLargeData(hScore); |
| | | |
| | | 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); |
| | | |
| | | finalHttp = GetComponent<FinalHttp>(); |
| | | _limit = 100; |
| | | _limitUp = 100; |
| | | finalHttp.Init(GetHttpData, _limit);//重置状态,设置回调和拉取的所有数据 |
| | | |
| | | itemFirst = transform.Find("ItemPanel/ItemMask/FinalPanelItemFirst").GetComponent<FinalPanelItem>(); |
| | | itemSecond = transform.Find("ItemPanel/ItemMask/FinalPanelItemSecond").GetComponent<FinalPanelItem>(); |
| | | itemThird = transform.Find("ItemPanel/ItemMask/FinalPanelItemThird").GetComponent<FinalPanelItem>(); |
| | | |
| | | httpCountDownPanel = transform.Find("HttpCountDownPanel").gameObject; |
| | | httpCountDownPanel.SetActive(false); |
| | | |
| | | rankUpbj = transform.Find("Image_HScore/RankUp").GetComponent<TextMeshProUGUI>(); |
| | | newPlayerImage = transform.Find("Image_HScore/NewPlayer").gameObject; |
| | | rankUpbj.gameObject.SetActive(false); |
| | | |
| | | |
| | | endPs = transform.Find("Effect_UI_JieSuanShengLi/03").GetComponent<ParticleSystem>(); |
| | | |
| | | goonText = transform.Find("Image_HScore/GoOnText").GetComponent<Text>(); |
| | | //PlayerPrefs.DeleteKey("GemBattlePlayerNickName"); |
| | | |
| | | playerNickName = PlayerPrefs.GetString(playerPrefs_NickName); |
| | | if (playerNickName == "") |
| | | { |
| | | GameObject go = Instantiate(Resources.Load<GameObject>("UI/Final/InputNamePanel"), transform); |
| | | go.GetComponent<InputNamePanel>().Init(LoadName); |
| | | } |
| | | else |
| | | { |
| | | newPlayerImage.SetActive(false); |
| | | StartHttp(); |
| | | } |
| | | |
| | | } |
| | | |
| | | private void LoadLargeData(int hScore) |
| | | private void LoadName(string nickName) |
| | | { |
| | | _data = new SmallList<FinalPanelItemData>(); |
| | | FinalPanelItemData data; |
| | | int score = 101; |
| | | for (var i = 0; i < 100; i++) |
| | | playerNickName = nickName; |
| | | PlayerPrefs.SetString(playerPrefs_NickName, playerNickName); |
| | | |
| | | if (Application.platform == RuntimePlatform.WindowsEditor || Application.platform == RuntimePlatform.WindowsPlayer) |
| | | { |
| | | 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); |
| | | //为了方便测试 |
| | | GameConfig.Imei = playerNickName; |
| | | Debug.Log("这里是电脑版,直接设置Imei为昵称" + playerNickName); |
| | | } |
| | | |
| | | _data[0].playerName = "自己"; |
| | | _data[0].score = hScore; |
| | | _data[0].spriteIcon = rank_icon_0; |
| | | _data[0].spriteBackGround = rank_di_0; |
| | | StartHttp(); |
| | | } |
| | | |
| | | _data[1].spriteIcon = rank_icon_1; |
| | | _data[1].spriteBackGround = rank_di_1; |
| | | private void StartHttp() |
| | | { |
| | | Debug.Log($"_myScore:{_myScore} _waveInfo:{_waveInfo}"); |
| | | finalHttp.SendPost(playerNickName, _myScore, 1, _waveInfo); |
| | | } |
| | | |
| | | _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(); |
| | | private void GetHttpData(List<HttpGetInfo> allHttpGetInfoLis, int myrank, HttpGetInfo mydataHttpInfo) |
| | | { |
| | | scroller = transform.Find("Scroller").GetComponent<EnhancedScroller>(); |
| | | scroller.Delegate = this; |
| | | playPSItem = new List<FinalPanelItem>(); |
| | | RefreshHttpData(allHttpGetInfoLis, myrank, mydataHttpInfo); |
| | | |
| | | if (allHttpGetInfoLis != null) |
| | | { |
| | | txt_Name.text = mydataHttpInfo.nickname; |
| | | txt_HScore.text = mydataHttpInfo.score.ToString(); |
| | | txt_Wave.text = mydataHttpInfo.waveInfo; |
| | | } |
| | | |
| | | PlayDoTween(); |
| | | isFirstStart = false; |
| | | } |
| | | |
| | | private void PlayDoTween() |
| | | { |
| | | AudioSourceManager.Ins.Play(AudioEnum.End); |
| | | |
| | | 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>(); |
| | | float imageTime = 0.3f; |
| | | agentTweenSeq.Append(Image1.transform.DOScale(Vector3.one, imageTime).SetEase(Ease.InOutBack));//变化图片大小 |
| | | agentTweenSeq.Join(Image1.DOFade(1, imageTime)); |
| | | agentTweenSeq.Join(waveText.DOText(_waveInfo, 0.2f)); |
| | | |
| | | Image Image2 = transform.Find("Image2").GetComponent<Image>(); |
| | | agentTweenSeq.Append(Image2.transform.DOScale(Vector3.one, imageTime).SetEase(Ease.InOutBack));//变化图片大小 |
| | | agentTweenSeq.Join(Image2.DOFade(1, imageTime)); |
| | | |
| | | Image Image3 = transform.Find("Image3").GetComponent<Image>(); |
| | | |
| | | agentTweenSeq.Append(Image3.transform.DOScale(Vector3.one, imageTime).SetEase(Ease.InOutBack));//变化图片大小 |
| | | agentTweenSeq.Join(Image3.DOFade(1, imageTime)); |
| | | agentTweenSeq.AppendCallback(() => |
| | | { |
| | | Debug.Log("开始播放声音"); |
| | | AudioSourceManager.Ins.Play(AudioEnum.FinalScore); |
| | | }); |
| | | agentTweenSeq.Join(DOTween.To(delegate (float value) |
| | | { |
| | | var temp = Math.Floor(value); |
| | | scoreText.text = temp + ""; |
| | | }, 0, _myScore, 1.4f)); |
| | | agentTweenSeq.AppendCallback(StartLoadLargeData); |
| | | |
| | | 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() |
| | | { |
| | | StartCoroutine(PlayerItemDoTween()); |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 播放排行榜动效 |
| | | /// </summary> |
| | | /// <returns></returns> |
| | | IEnumerator PlayerItemDoTween() |
| | | { |
| | | yield return new WaitForEndOfFrame(); |
| | | if (_data.Count > 0) |
| | | { |
| | | scrollerCanvasGroup.alpha = 1; |
| | | Debug.Log("开始展示排行榜"); |
| | | } |
| | | |
| | | if (playPSItem.Count > 0) |
| | | { |
| | | itemCanvasGroup.alpha = 1; |
| | | float duration = 0.1f; |
| | | for (int i = 0; i < playPSItem.Count; i++) |
| | | { |
| | | playPSItem[i].PlayDoTween(duration); |
| | | yield return new WaitForSeconds(duration); |
| | | } |
| | | image_HScore.SetActive(true); |
| | | goonFade = true; |
| | | ShowGoOnText(); |
| | | } |
| | | |
| | | yield break; |
| | | } |
| | | |
| | | bool goonFade; |
| | | private void ShowGoOnText() |
| | | { |
| | | goonText.DOFade(goonFade ? 0 : 1, 0.8f).SetEase(Ease.InOutQuad).OnComplete(ShowGoOnText); |
| | | goonText.transform.DOScale(goonFade ? 0.9f : 1.1f, 0.8f); |
| | | goonFade = !goonFade; |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 文字显示结束,显示波次和是否最高记录 |
| | | /// </summary> |
| | | protected void TextDoTweenFinish() |
| | | { |
| | | waveText.gameObject.SetActive(true); |
| | | if (_allHttpGetInfoLis == null) |
| | | { |
| | | httpCountDownPanel.SetActive(true); |
| | | } |
| | | if (isNewH) |
| | | { |
| | | image_NewRecord.SetActive(true); |
| | | |
| | | if (tmpRankUp > 0) |
| | | { |
| | | Debug.Log("排名上升了:" + tmpRankUp); |
| | | if (!rankUpbj.gameObject.activeSelf) |
| | | { |
| | | rankUpbj.gameObject.SetActive(true); |
| | | DOTween.To(delegate (float value) |
| | | { |
| | | var temp = Math.Floor(value); |
| | | rankUpbj.text = temp + ""; |
| | | }, 0, tmpRankUp, 0.5f); |
| | | } |
| | | } |
| | | else |
| | | { |
| | | Debug.Log("排名下降了"); |
| | | } |
| | | } |
| | | |
| | | endPs?.Play(); |
| | | |
| | | closeBtn.interactable = true; |
| | | } |
| | | |
| | | Transform tsLight; |
| | | /// <summary> |
| | | /// 光出现后开始旋转 |
| | | /// </summary> |
| | | protected void RotateLight() |
| | | { |
| | | Debug.Log("开始旋转"); |
| | | isRotate = true; |
| | | offect = 0; |
| | | } |
| | | |
| | | #region EnhancedScroller Handlers |
| | |
| | | public EnhancedScrollerCellView GetCellView(EnhancedScroller scroller, int dataIndex, int cellIndex) |
| | | { |
| | | FinalPanelItem cellView = scroller.GetCellView(cellViewPrefab) as FinalPanelItem; |
| | | |
| | | cellView.SetData(_data[dataIndex]); |
| | | //cellView.CheckRank(tmpRankUp); |
| | | if (dataIndex == _data.Count - 2) |
| | | { |
| | | Debug.Log($"是否可以刷新新列表了 _limit:{_limit} _data.Count:{_data.Count}"); |
| | | |
| | | if (_limit >= 3000) |
| | | { |
| | | Debug.Log("数据下载量最大3000"); |
| | | } |
| | | else if (_limit > _data.Count + 3)//从第三名开始无限滚动 |
| | | { |
| | | Debug.Log("当前服务器没有那么多数据"); |
| | | } |
| | | else |
| | | { |
| | | _limit += _limitUp; |
| | | Debug.Log("刷新新列表了,下载了 " + _limit + " 个数据:"); |
| | | finalHttp.Init(RefreshHttpData, _limit);//重置状态,设置回调和拉取的所有数据 |
| | | StartHttp(); |
| | | } |
| | | } |
| | | return cellView; |
| | | } |
| | | |
| | | List<HttpGetInfo> _allHttpGetInfoLis; |
| | | List<FinalPanelItem> playPSItem;//特效list |
| | | bool isFirstStart; |
| | | private void RefreshHttpData(List<HttpGetInfo> allHttpGetInfoLis, int myrank, HttpGetInfo mydataHttpInfo) |
| | | { |
| | | _allHttpGetInfoLis = allHttpGetInfoLis; |
| | | if (allHttpGetInfoLis == null) |
| | | { |
| | | //httpCountDownPanel.SetActive(true); |
| | | return; |
| | | } |
| | | |
| | | FinalPanelItemData data; |
| | | |
| | | if (allHttpGetInfoLis.Count > 0) |
| | | { |
| | | //排名发生了变化 |
| | | if (tmpRank != myrank) |
| | | { |
| | | tmpRankUp = tmpRank - myrank; |
| | | |
| | | tmpRank = myrank; |
| | | PlayerPrefs.SetInt(playerPrefs_HRank, tmpRank); |
| | | } |
| | | else |
| | | { |
| | | |
| | | } |
| | | |
| | | if (myrank > 3000) |
| | | { |
| | | txt_Index.text = "3000+"; |
| | | } |
| | | else |
| | | { |
| | | txt_Index.text = myrank.ToString(); |
| | | } |
| | | |
| | | if (allHttpGetInfoLis.Count >= 1) |
| | | { |
| | | data = new FinalPanelItemData(); |
| | | data.httpInfo = allHttpGetInfoLis[0]; |
| | | data.index = 1; |
| | | itemFirst.gameObject.SetActive(true); |
| | | itemFirst.SetData(data); |
| | | if (isFirstStart) |
| | | { |
| | | itemFirst.SetPos(); |
| | | playPSItem.Add(itemFirst); |
| | | } |
| | | //itemFirst.CheckRank(tmpRankUp); |
| | | } |
| | | else |
| | | { |
| | | itemFirst.gameObject.SetActive(false); |
| | | itemSecond.gameObject.SetActive(false); |
| | | itemThird.gameObject.SetActive(false); |
| | | return; |
| | | } |
| | | if (allHttpGetInfoLis.Count >= 2) |
| | | { |
| | | data = new FinalPanelItemData(); |
| | | data.httpInfo = allHttpGetInfoLis[1]; |
| | | data.index = 2; |
| | | itemSecond.gameObject.SetActive(true); |
| | | itemSecond.SetData(data); |
| | | if (isFirstStart) |
| | | { |
| | | itemSecond.SetPos(); |
| | | playPSItem.Add(itemSecond); |
| | | } |
| | | //itemFirst.CheckRank(tmpRankUp); |
| | | } |
| | | else |
| | | { |
| | | itemSecond.gameObject.SetActive(false); |
| | | itemThird.gameObject.SetActive(false); |
| | | return; |
| | | } |
| | | if (allHttpGetInfoLis.Count > 2) |
| | | { |
| | | data = new FinalPanelItemData(); |
| | | data.httpInfo = allHttpGetInfoLis[2]; |
| | | data.index = 3; |
| | | itemThird.gameObject.SetActive(true); |
| | | itemThird.SetData(data); |
| | | if (isFirstStart) |
| | | { |
| | | itemThird.SetPos(); |
| | | playPSItem.Add(itemThird); |
| | | } |
| | | //itemFirst.CheckRank(tmpRankUp); |
| | | } |
| | | else |
| | | { |
| | | itemThird.gameObject.SetActive(false); |
| | | return; |
| | | } |
| | | if (allHttpGetInfoLis.Count > 3) |
| | | { |
| | | _data.Clear(); |
| | | for (int i = 3; i < allHttpGetInfoLis.Count; i++) |
| | | { |
| | | data = new FinalPanelItemData(); |
| | | data.httpInfo = allHttpGetInfoLis[i]; |
| | | data.index = i + 1; |
| | | _data.Add(data); |
| | | } |
| | | scroller.ReloadData(); |
| | | |
| | | if (isFirstStart) |
| | | { |
| | | Transform container = transform.Find("Scroller/Container"); |
| | | FinalPanelItem[] items = container.GetComponentsInChildren<FinalPanelItem>(); |
| | | for (int i = 0; i < items.Length; i++) |
| | | { |
| | | playPSItem.Add(items[i]); |
| | | items[i].SetPos(); |
| | | } |
| | | } |
| | | |
| | | } |
| | | |
| | | } |
| | | } |
| | | |
| | | |
| | | |
| | | |
| | | #endregion |
| | | |
| | |
| | | |
| | | public class FinalPanelItemData |
| | | { |
| | | public string playerName; |
| | | public int score; |
| | | public HttpGetInfo httpInfo; |
| | | public int index; |
| | | |
| | | public Sprite spriteIcon; |
| | | public Sprite spriteBackGround; |
| | | |
| | | } |
| | | |