143 lines
3.9 KiB
C#
143 lines
3.9 KiB
C#
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 : PFUIPanel
|
|
{
|
|
// 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 = "全部";
|
|
|
|
private Button returnBtn;
|
|
GameObject btnMapMode;
|
|
public GameObject Content {
|
|
get
|
|
{
|
|
return content;
|
|
}
|
|
}
|
|
private bool isEnd = false;
|
|
protected override void Start()
|
|
{
|
|
//if (hardSelector != null)
|
|
//{
|
|
// hardSelector.onValueChanged.AddListener(ChangeHard);
|
|
//}
|
|
btnMapMode = this.transform.Find("BtnMapMode").gameObject;
|
|
UIManager.AddEvent(btnMapMode, EventTriggerType.PointerClick, (e) =>
|
|
{
|
|
UIManager.ShowBigMapPanel();
|
|
});
|
|
if (content!=null)
|
|
{
|
|
//var transform = content.transform.GetComponent<RectTransform>();
|
|
//var layout = content.GetComponent<GridLayoutGroup>();
|
|
//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<GameObject>("Canvas"));
|
|
//obj.transform.parent = transform.parent;
|
|
|
|
var btnQuit = this.transform.Find("BtnQuit");
|
|
if(btnQuit != null)
|
|
{
|
|
returnBtn = btnQuit.GetComponent<Button>();
|
|
UIManager.AddEvent(returnBtn.gameObject, EventTriggerType.PointerClick, (e) =>
|
|
{
|
|
UIManager.ShowHomePanel();
|
|
});
|
|
}
|
|
}
|
|
|
|
private void OnEndDrag(BaseEventData arg0)
|
|
{
|
|
var scrollrect = scroll.GetComponent<ScrollRect>();
|
|
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<MapRoute> list)
|
|
{
|
|
if (map != null)
|
|
{
|
|
foreach (var item in list)
|
|
{
|
|
var obj = Instantiate(map);
|
|
obj.GetComponent<MapItem>().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()
|
|
{
|
|
|
|
}
|
|
}
|