加链接,文件位置
This commit is contained in:
1 parent
ae3f9d2101
commit
b93fbd2f2e
14 files changed
+7
-1
No files matched your search
@@ -0,0 +1,227 @@
|
||||
using Assets.Scripts;
|
||||
using Assets.Scripts.Apis.Models;
|
||||
using Assets.Scripts.UI.Prefab.Race;
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.Threading.Tasks;
|
||||
using UnityEngine;
|
||||
using UnityEngine.EventSystems;
|
||||
using UnityEngine.UI;
|
||||
|
||||
public class RaceListScript : RaceScript
|
||||
{
|
||||
// Start is called before the first frame update
|
||||
private GameObject scroll;
|
||||
private Transform content,statusOptionContainer, reserveContainer,dirContainer, searchInput,btnReturn,avatar;
|
||||
private bool startMouse = false,isEnd = false;
|
||||
private int pageIndex = 0, pageSize = 24;
|
||||
private string raceName = "";
|
||||
//筛选条件
|
||||
private List<string> statusOptions = new List<string>();
|
||||
bool isReserve = false;
|
||||
int order = 1;
|
||||
//筛选条件
|
||||
async void Start()
|
||||
{
|
||||
#if UNITY_EDITOR
|
||||
if (App.CurrentUser == null) //App.CurrentUser == null
|
||||
{
|
||||
await Login();
|
||||
}
|
||||
#endif
|
||||
scroll = transform.Find("ListContainer/List").gameObject;
|
||||
if (scroll != null)
|
||||
{
|
||||
content = scroll.GetComponent<ScrollRect>().content;
|
||||
UIManager.AddEvent(scroll, UnityEngine.EventSystems.EventTriggerType.EndDrag, OnEndDrag);
|
||||
}
|
||||
statusOptionContainer = transform.Find("ListContainer/Conditions/StatusContainer");
|
||||
if (statusOptionContainer != null)
|
||||
{
|
||||
foreach (Transform t in statusOptionContainer)
|
||||
{
|
||||
var button = t.GetComponent<Button>();
|
||||
var image = t.GetComponent<Image>();
|
||||
var text = t.Find("Text").GetComponent<Text>();
|
||||
UIManager.AddEvent(button.gameObject, EventTriggerType.PointerClick, (b) =>
|
||||
{
|
||||
Color c1 = Utils.HexToColorHtml("#23232D");
|
||||
if (image.color.r == c1.r && image.color.g == c1.g && image.color.b == c1.b)
|
||||
{
|
||||
image.color = Utils.HexToColorHtml("#F93086");
|
||||
text.color = new Color(1, 1, 1, 1);
|
||||
statusOptions.Add(RaceFilterOptions.statusDict[text.text]);
|
||||
}
|
||||
else
|
||||
{
|
||||
image.color = c1;
|
||||
text.color = new Color(1, 1, 1, 1);
|
||||
statusOptions.Remove(RaceFilterOptions.statusDict[text.text]);
|
||||
}
|
||||
scroll.GetComponent<ScrollRect>().verticalNormalizedPosition = 1;
|
||||
Refresh();
|
||||
});
|
||||
}
|
||||
}
|
||||
reserveContainer = transform.Find("ListContainer/Conditions/ReserveContainer");
|
||||
if (reserveContainer != null)
|
||||
{
|
||||
UIManager.AddEvent(reserveContainer.gameObject, UnityEngine.EventSystems.EventTriggerType.PointerClick, b=>
|
||||
{
|
||||
var gou = reserveContainer.Find("Gou").gameObject;
|
||||
bool v = !gou.activeSelf;
|
||||
gou.SetActive(v);
|
||||
isReserve = v;
|
||||
Refresh();
|
||||
});
|
||||
}
|
||||
dirContainer = transform.Find("ListContainer/Conditions/Dir");
|
||||
if (dirContainer != null)
|
||||
{
|
||||
var image = dirContainer.Find("Image").GetComponent<Image>();
|
||||
UIManager.AddEvent(dirContainer.gameObject, EventTriggerType.PointerClick, (b) =>
|
||||
{
|
||||
if (image.sprite.name == "DOWN")
|
||||
{
|
||||
image.sprite = Resources.Load<Sprite>("Images/UP");
|
||||
order = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
image.sprite = Resources.Load<Sprite>("Images/DOWN");
|
||||
order = 1;
|
||||
}
|
||||
Refresh();
|
||||
});
|
||||
}
|
||||
searchInput = transform.Find("ListContainer/Conditions/SearchInput");
|
||||
if (searchInput != null)
|
||||
{
|
||||
UIManager.AddEvent(searchInput.Find("Button").gameObject, EventTriggerType.PointerClick, (b) =>
|
||||
{
|
||||
onEndEdit();
|
||||
});
|
||||
}
|
||||
btnReturn = transform.Find("BtnReturn");
|
||||
if (btnReturn != null)
|
||||
{
|
||||
UIManager.AddEvent(btnReturn.gameObject, EventTriggerType.PointerClick, (b) =>
|
||||
{
|
||||
UIManager.ShowRaceHomePanel(true);
|
||||
});
|
||||
}
|
||||
avatar = transform.Find("Avatar");
|
||||
if (avatar != null)
|
||||
{
|
||||
Utils.DisplayImage(avatar.GetComponent<RawImage>(), App.CurrentUser.WxHeadImg, true);
|
||||
UIManager.AddEvent(avatar.gameObject, UnityEngine.EventSystems.EventTriggerType.PointerClick, b =>
|
||||
{
|
||||
UIManager.ShowUserInfoPanel();
|
||||
});
|
||||
}
|
||||
Refresh();
|
||||
}
|
||||
|
||||
private async Task Login()
|
||||
{
|
||||
var result = await ConfigHelper.userApi.Login("13115011550", "laozhong", "");
|
||||
App.CurrentUser = result.data;
|
||||
}
|
||||
|
||||
// Update is called once per frame
|
||||
void Update()
|
||||
{
|
||||
if (Input.GetAxis("Mouse ScrollWheel") != 0)
|
||||
{
|
||||
Debug.Log(scroll.GetComponent<ScrollRect>().verticalNormalizedPosition);
|
||||
if (scroll.GetComponent<ScrollRect>().verticalNormalizedPosition <= 0 ||
|
||||
scroll.GetComponent<ScrollRect>().verticalNormalizedPosition >= (pageIndex == 0 ? 1.2 : 1))
|
||||
{
|
||||
startMouse = true;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (startMouse)
|
||||
{
|
||||
startMouse = false;
|
||||
OnEndDrag(null);
|
||||
}
|
||||
}
|
||||
if (Input.GetKeyDown(KeyCode.KeypadEnter) || Input.GetKeyDown(KeyCode.Return))
|
||||
{
|
||||
onEndEdit();
|
||||
}
|
||||
}
|
||||
|
||||
private void OnEndDrag(BaseEventData arg0)
|
||||
{
|
||||
var scrollrect = scroll.GetComponent<ScrollRect>();
|
||||
Debug.Log(scrollrect.verticalNormalizedPosition);
|
||||
if (scrollrect.verticalNormalizedPosition <= 0)
|
||||
{
|
||||
pageIndex++;
|
||||
GetList();
|
||||
}
|
||||
if (scrollrect.verticalNormalizedPosition >= (pageIndex == 0 ? 1.2 : 1))
|
||||
{
|
||||
Refresh();
|
||||
}
|
||||
}
|
||||
|
||||
private void Refresh()
|
||||
{
|
||||
content.transform.DestroyChildren();
|
||||
pageIndex = 0;
|
||||
isEnd = false;
|
||||
GetList();
|
||||
}
|
||||
|
||||
private async void GetList()
|
||||
{
|
||||
if (isEnd) return;
|
||||
var res = await ConfigHelper.mapCompetitionApi.GetCompetitionListV2(raceName, pageIndex,pageSize,
|
||||
status:string.Join(",", statusOptions),self:isReserve,order:order);
|
||||
if (res.result)
|
||||
{
|
||||
if (res.data.Count == 0)
|
||||
{
|
||||
if (pageIndex != 0)
|
||||
{
|
||||
isEnd = true;
|
||||
scroll.transform.Find("Error").gameObject.SetActive(false);
|
||||
}
|
||||
else
|
||||
{
|
||||
Debug.Log("当前没查到内容");
|
||||
scroll.transform.Find("Error").gameObject.SetActive(true);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
isEnd = false;
|
||||
DisplayMaps(res.data);
|
||||
scroll.transform.Find("Error").gameObject.SetActive(false);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void DisplayMaps(List<MapCompetition> list)
|
||||
{
|
||||
GameObject smallGame = Resources.Load<GameObject>("UI/Prefab/Race/ItemSmall");
|
||||
foreach (var map in list)
|
||||
{
|
||||
var game = Instantiate<GameObject>(smallGame);
|
||||
game.GetComponent<RaceItemScript>().Initial(map, transform);
|
||||
game.transform.SetParent(scroll.GetComponent<ScrollRect>().content);
|
||||
game.transform.localScale = Vector3.one;
|
||||
}
|
||||
}
|
||||
void onEndEdit()
|
||||
{
|
||||
var t = searchInput.GetComponent<InputField>().text;
|
||||
raceName = t;
|
||||
Refresh();
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user