using Assets.Cyp.Common; using Assets.Scripts; using Assets.Scripts.Apis.Models; using System; using System.Collections; using System.Collections.Generic; using System.Linq; using UnityEditor; using UnityEngine; using UnityEngine.EventSystems; using UnityEngine.SceneManagement; using UnityEngine.UI; public class MapListController : MonoBehaviour { // Start is called before the first frame update [SerializeField] GameObject map; [SerializeField] GameObject content; [SerializeField] GameObject scroll; [HideInInspector] public int pageIndex = 0; [HideInInspector] public int pageSize = 20; [HideInInspector] public string hard = "全部"; public GameObject Content { get { return content; } } private bool isEnd = false; void Start() { //if (hardSelector != null) //{ // hardSelector.onValueChanged.AddListener(ChangeHard); //} if (content!=null) { //var transform = content.transform.GetComponent(); //var layout = content.GetComponent(); //if (layout != null) //{ // var width = transform.rect.width; // layout.cellSize = new Vector2((width - 120) / 5, (width - 120) / 5); //} } GetList(); if (scroll != null) { UIManager.AddEvent(scroll, UnityEngine.EventSystems.EventTriggerType.EndDrag, OnEndDrag); } //UIManager.AddEvent(transform.Find("Panel").Find("Panel")) //var obj = Instantiate(Resources.Load("Canvas")); //obj.transform.parent = transform.parent; } private void OnEndDrag(BaseEventData arg0) { var scrollrect = scroll.GetComponent(); if (scrollrect.verticalNormalizedPosition <= 0) { Debug.Log(scrollrect.verticalNormalizedPosition); pageIndex++; GetList(); } if (scrollrect.verticalNormalizedPosition >= 1) { Refresh(); } } private void ChangeHard(int index) { //var text = hardSelector.options[index].text; //if (text == "全部难度") //{ //} } public void GetList() { if (isEnd) return; var res = Global.mapApi.GetList(pageIndex, pageSize, ""); if (res.result) { if (res.data.Count == 0) { isEnd = true; } else { DisplayMaps(res.data); } } } void DisplayMaps(List list) { if (map != null) { foreach (var item in list) { var obj = Instantiate(map); obj.GetComponent().Initial(item); //obj.SendMessage("Initial", ); obj.transform.parent = content.transform; obj.transform.localScale = new Vector3(1, 1, 1); } } } public void Refresh() { content.transform.DestroyChildren(); pageIndex = 0; GetList(); } // Update is called once per frame void Update() { } }