using asap.core; using game; using GameCore; using System; using System.Collections.Generic; using UnityEngine; using UnityEngine.UI; using UniRx; public class SocialLeadboard : MonoBehaviour { LeadboardData _leadboardData; List toggleList = new List(); List selected_tab = new List(); public GameObject item; public PanelScroll scrollRect; float itemHigh; public int curSelfRank; SocialLeadboardItem selfItem; IDisposable disposable; private void Awake() { _leadboardData = GContext.container.Resolve(); scrollRect = transform.Find("rank/ScrollView").GetComponent(); item = transform.Find("rank/ScrollView/Viewport/Content/Item").gameObject; selfItem = transform.Find("rank/ScrollView/Viewport/Item").GetComponent(); for (int i = 1; i <= 2; i++) { toggleList.Add(transform.Find($"tab/text_tab{i}").GetComponent()); selected_tab.Add(transform.Find($"tab/selected_tab{i}").gameObject); } itemHigh = item.GetComponent().sizeDelta.y; toggleList[0].isOn = true; toggleList[1].isOn = false; scrollRect.loop = false; } private void Start() { toggleList[0].onValueChanged.AddListener(Global); toggleList[1].onValueChanged.AddListener(Locals); //SetScroll(); } private void OnEnable() { disposable = GContext.OnEvent().Subscribe((data) => { if (!data.isLocal && toggleList[0].isOn) { SetScroll(); } else if (data.isLocal && toggleList[1].isOn) { SetLocalScroll(); } }); selected_tab[0].SetActive(toggleList[0].isOn); selected_tab[1].SetActive(toggleList[1].isOn); if (toggleList[0].isOn) { Global(true); } else { Locals(true); } } //void OnClickItem(SocialLeadboardItem item) //{ //} void SetScroll() { curSelfRank = -1; for (int i = 0; i < _leadboardData.LeadboardDataList.Count; i++) { if (_leadboardData.LeadboardDataList[i].playFabId == GContext.container.Resolve().UserId) { curSelfRank = i; selfItem.data = _leadboardData.LeadboardDataList[i]; break; } } scrollRect.Init(itemHigh, item, null, _leadboardData.LeadboardDataList); SetSelfItem(); } void SetSelfItem() { if (curSelfRank >= 0) { float selfPos = itemHigh * curSelfRank - scrollRect.viewport.rect.height + itemHigh; selfItem.gameObject.SetActive(scrollRect.content.anchoredPosition.y < selfPos); selfItem.OnInit(); scrollRect.onValueChanged.AddListener((Vector2 v2) => { selfItem.gameObject.SetActive(scrollRect.content.anchoredPosition.y < selfPos); }); } else { selfItem.gameObject.SetActive(false); } } void Global(bool isOn) { selected_tab[0].SetActive(isOn); if (isOn) { SetScroll(); } } void Locals(bool isOn) { selected_tab[1].SetActive(isOn); if (isOn) { SetLocalScroll(); } } void SetLocalScroll() { curSelfRank = -1; for (int i = 0; i < _leadboardData.LeadboardContinentDataList.Count; i++) { if (_leadboardData.LeadboardContinentDataList[i].playFabId == GContext.container.Resolve().UserId) { curSelfRank = i; selfItem.data = _leadboardData.LeadboardContinentDataList[i]; break; } } scrollRect.Init(itemHigh, item, null, _leadboardData.LeadboardContinentDataList); SetSelfItem(); } private void OnDisable() { disposable?.Dispose(); disposable = null; } }