| | |
| | | using KTGMGemClient; |
| | | using DG.Tweening; |
| | | using System; |
| | | using System.Linq; |
| | | |
| | | 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.interactable = false; |
| | | } |
| | | Button closeBtn; |
| | | Text waveText; |
| | | GameObject image_HScore; |
| | | Text scoreText; |
| | |
| | | bool isNewH = false; |
| | | int hScore; |
| | | CanvasGroup scrollerCanvasGroup; |
| | | CanvasGroup itemCanvasGroup; |
| | | |
| | | Action playEffectAC = null; |
| | | |
| | | |
| | | /// <summary> |
| | | /// 设置播放胜利特效 |
| | |
| | | playEffectAC = ac; |
| | | } |
| | | |
| | | 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; |
| | | /// <summary> |
| | | /// 入口函数 |
| | | /// </summary> |
| | |
| | | /// <param name="myScore">789220</param> |
| | | public void SetData(string waveInfo, int myScore) |
| | | { |
| | | _waveInfo = waveInfo; |
| | | _myScore = myScore; |
| | | |
| | | hScore = PlayerPrefs.GetInt("GemBattleHScore"); |
| | | //scrollerCanvasGroup = transform.Find("Scroll View").GetComponent<CanvasGroup>(); |
| | | 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); |
| | |
| | | isNewH = true; |
| | | } |
| | | |
| | | 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>(); |
| | | |
| | | |
| | | 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>(); |
| | |
| | | |
| | | image_NewRecord = transform.Find("Image_NewRecord").gameObject; |
| | | image_NewRecord.SetActive(false); |
| | | LoadLargeData(hScore); |
| | | |
| | | Transform ts = transform.Find("Images"); |
| | | finalHttp = GetComponent<FinalHttp>(); |
| | | _limit = 100; |
| | | _limitUp = 100; |
| | | finalHttp.Init(GetHttpData, _limit);//重置状态,设置回调和拉取的所有数据 |
| | | |
| | | itemFirst = transform.Find("ItemPanel/FinalPanelItemFirst").GetComponent<FinalPanelItem>(); |
| | | itemSecond = transform.Find("ItemPanel/FinalPanelItemSecond").GetComponent<FinalPanelItem>(); |
| | | itemThird = transform.Find("ItemPanel/FinalPanelItemThird").GetComponent<FinalPanelItem>(); |
| | | |
| | | //PlayerPrefs.DeleteKey("GemBattlePlayerNickName"); |
| | | |
| | | playerNickName = PlayerPrefs.GetString("GemBattlePlayerNickName"); |
| | | if (playerNickName == "") |
| | | { |
| | | GameObject go = Instantiate(Resources.Load<GameObject>("UI/Final/InputNamePanel"), transform); |
| | | go.GetComponent<InputNamePanel>().Init(LoadName); |
| | | } |
| | | else |
| | | { |
| | | StartHttp(); |
| | | } |
| | | |
| | | } |
| | | |
| | | private void LoadName(string nickName) |
| | | { |
| | | playerNickName = nickName; |
| | | PlayerPrefs.SetString("GemBattlePlayerNickName", playerNickName); |
| | | StartHttp(); |
| | | } |
| | | |
| | | private void StartHttp() |
| | | { |
| | | finalHttp.SendPost(playerNickName, _myScore, 1, _waveInfo); |
| | | } |
| | | |
| | | private void GetHttpData(List<HttpGetInfo> allHttpGetInfoLis, int myrank) |
| | | { |
| | | scroller = transform.Find("Scroller").GetComponent<EnhancedScroller>(); |
| | | scroller.Delegate = this; |
| | | |
| | | RefreshHttpData(allHttpGetInfoLis, myrank); |
| | | |
| | | txt_Name.text = playerNickName; |
| | | txt_HScore.text = _myScore.ToString(); |
| | | txt_Wave.text = _waveInfo; |
| | | if (myrank > 3000) |
| | | { |
| | | txt_Index.text = "3000+"; |
| | | } |
| | | else |
| | | { |
| | | txt_Index.text = myrank.ToString(); |
| | | } |
| | | |
| | | PlayDoTween(); |
| | | } |
| | | |
| | | private void PlayDoTween() |
| | | { |
| | | Sequence agentTweenSeq = DOTween.Sequence(); |
| | | //先出现 |
| | | Image tsTiele = transform.Find("Image_Tiele").GetComponent<Image>(); |
| | |
| | | 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)); |
| | | agentTweenSeq.Join(waveText.DOText(_waveInfo, 0.2f)); |
| | | |
| | | Image Image2 = transform.Find("Image2").GetComponent<Image>(); |
| | | agentTweenSeq.Append(Image2.transform.DOScale(Vector3.one, 0.2f));//变化图片大小 |
| | |
| | | { |
| | | var temp = Math.Floor(value); |
| | | scoreText.text = temp + ""; |
| | | }, 0, myScore, 1.0f)); |
| | | }, 0, _myScore, 1.0f)); |
| | | |
| | | tsLight = transform.Find("ImageLight"); |
| | | Image ImageLight = tsLight.GetComponent<Image>(); |
| | |
| | | protected void StartLoadLargeData() |
| | | { |
| | | scoreText.gameObject.SetActive(true); |
| | | scrollerCanvasGroup.alpha = 1; |
| | | |
| | | //StartCoroutine(PlayerItemDoTween()); |
| | | StartCoroutine(PlayerItemDoTween()); |
| | | } |
| | | |
| | | /// <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); |
| | | } |
| | | itemCanvasGroup.alpha = 1; |
| | | |
| | | image_HScore.SetActive(true); |
| | | |
| | | yield break; |
| | |
| | | { |
| | | 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 |
| | |
| | | { |
| | | FinalPanelItem cellView = scroller.GetCellView(cellViewPrefab) as FinalPanelItem; |
| | | cellView.SetData(_data[dataIndex]); |
| | | |
| | | if (dataIndex == _data.Count - 2) |
| | | { |
| | | Debug.Log("是否可以刷新新列表了"); |
| | | |
| | | if (_limit >= 3000) |
| | | { |
| | | Debug.Log("数据下载量最大3000"); |
| | | } |
| | | else if (_limit >= _data.Count) |
| | | { |
| | | Debug.Log("当前服务器没有那么多数据"); |
| | | } |
| | | else |
| | | { |
| | | _limit += _limitUp; |
| | | Debug.Log("刷新新列表了,下载了 " + _limit + " 个数据:"); |
| | | finalHttp.Init(RefreshHttpData, _limit);//重置状态,设置回调和拉取的所有数据 |
| | | } |
| | | } |
| | | return cellView; |
| | | } |
| | | |
| | | private void RefreshHttpData(List<HttpGetInfo> allHttpGetInfoLis, int myrank) |
| | | { |
| | | _data = new SmallList<FinalPanelItemData>(); |
| | | FinalPanelItemData data; |
| | | |
| | | if (allHttpGetInfoLis.Count > 0) |
| | | { |
| | | if (allHttpGetInfoLis.Count >= 1) |
| | | { |
| | | data = new FinalPanelItemData(); |
| | | data.httpInfo = allHttpGetInfoLis[0]; |
| | | data.index = 1; |
| | | itemFirst.gameObject.SetActive(true); |
| | | itemFirst.SetData(data); |
| | | } |
| | | 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); |
| | | } |
| | | 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); |
| | | } |
| | | else |
| | | { |
| | | itemThird.gameObject.SetActive(false); |
| | | return; |
| | | } |
| | | if (allHttpGetInfoLis.Count > 3) |
| | | { |
| | | for (int i = 3; i < allHttpGetInfoLis.Count; i++) |
| | | { |
| | | data = new FinalPanelItemData(); |
| | | data.httpInfo = allHttpGetInfoLis[i]; |
| | | data.index = i + 1; |
| | | _data.Add(data); |
| | | } |
| | | scroller.ReloadData(); |
| | | } |
| | | } |
| | | } |
| | | |
| | | |
| | | #endregion |
| | | |
| | |
| | | |
| | | public class FinalPanelItemData |
| | | { |
| | | public string playerName; |
| | | public int score; |
| | | public HttpGetInfo httpInfo; |
| | | public int index; |
| | | |
| | | public Sprite spriteIcon; |
| | | public Sprite spriteBackGround; |
| | | |
| | | } |
| | | |