227 lines
7.0 KiB
C#
227 lines
7.0 KiB
C#
using Assets.Scripts;
|
|
using DG.Tweening;
|
|
using System;
|
|
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
using UnityEngine.EventSystems;
|
|
using UnityEngine.UI;
|
|
|
|
public class NewRouteOverviewController: PFUIPanel
|
|
{
|
|
// Start is called before the first frame update
|
|
Transform tmpGroup;
|
|
Transform tmpItem;
|
|
int bannerIndex = 0;
|
|
float? startPos = null;
|
|
RectTransform bannerContent,collectionContent;
|
|
Dictionary<string, Texture> caches = null;
|
|
ScrollRect scroll;
|
|
protected override void Awake()
|
|
{
|
|
caches = new Dictionary<string, Texture>();
|
|
scroll = transform.Find("Container/Right/Scroll View").GetComponent<ScrollRect>();
|
|
UIManager.AddEvent(scroll.gameObject, UnityEngine.EventSystems.EventTriggerType.EndDrag, OnEndDrag);
|
|
}
|
|
|
|
private void OnEndDrag(BaseEventData arg0)
|
|
{
|
|
if (scroll.verticalNormalizedPosition <= 0 && !isEnd)
|
|
{
|
|
pageIndex++;
|
|
GetList();
|
|
}
|
|
if (scroll.verticalNormalizedPosition >= 1.1)
|
|
{
|
|
Refresh();
|
|
}
|
|
}
|
|
|
|
protected override void OnDestroy()
|
|
{
|
|
caches = null;
|
|
Resources.UnloadUnusedAssets();
|
|
GC.Collect();
|
|
Debug.Log("list empty");
|
|
}
|
|
void Start()
|
|
{
|
|
#if !(UNITY_ANDROID || UNITY_IOS)
|
|
tmpGroup = Resources.Load<Transform>("UI/Prefab/NewRoute/RouteGroup");
|
|
tmpItem = Resources.Load<Transform>("UI/Prefab/NewRoute/RouteItem");
|
|
#else
|
|
var rect = transform.GetComponent<RectTransform>();
|
|
rect.offsetMax = new Vector2(rect.offsetMax.x, 0);
|
|
rect.offsetMin = new Vector2(rect.offsetMin.x, 0);
|
|
tmpGroup = Resources.Load<Transform>("UI/Prefab/NewRoute/Mobile/RouteGroup");
|
|
tmpItem = Resources.Load<Transform>("UI/Prefab/NewRoute/Mobile/RouteItem");
|
|
#endif
|
|
|
|
var btnMapMode = this.transform.Find("SwitchMode").gameObject;
|
|
SetRounded(btnMapMode.transform, 64);
|
|
UIManager.AddEvent(btnMapMode.transform.Find("GoList").gameObject, EventTriggerType.PointerClick, (e) =>
|
|
{
|
|
UIManager.PopStack();
|
|
//UIManager.ShowBigMapPanel();
|
|
UIManager.ShowEarthPanel(App.latitude, App.longitude);
|
|
});
|
|
|
|
collectionContent = transform.Find("Container/Right/Scroll View/Viewport/Content")
|
|
.GetComponent<RectTransform>();
|
|
Refresh();
|
|
|
|
|
|
var left = transform.Find("Container/Left");
|
|
UIManager.AddEvent(left.Find("MyUpload").gameObject, UnityEngine.EventSystems.EventTriggerType.PointerClick, b =>
|
|
{
|
|
ToList("My Upload");
|
|
});
|
|
UIManager.AddEvent(left.Find("MyCollection").gameObject, UnityEngine.EventSystems.EventTriggerType.PointerClick, b =>
|
|
{
|
|
ToList("My Collection");
|
|
});
|
|
UIManager.AddEvent(left.Find("RecentRoute").gameObject, UnityEngine.EventSystems.EventTriggerType.PointerClick, b =>
|
|
{
|
|
ToList("Recent Routes");
|
|
});
|
|
UIManager.AddEvent(left.Find("AllRoutes").gameObject, UnityEngine.EventSystems.EventTriggerType.PointerClick, b =>
|
|
{
|
|
ToList("All Route");
|
|
});
|
|
BindHeadImage();
|
|
//banner暂时注释
|
|
//#if !(UNITY_ANDROID || UNITY_IOS)
|
|
// var banner = collectionContent.Find("Banner");
|
|
// bannerContent = banner.Find("Viewport/Content").GetComponent<RectTransform>();
|
|
// var btnLeft = banner.Find("Left");
|
|
// var btnRight = banner.Find("Right");
|
|
// UIManager.AddEvent(btnLeft.gameObject, UnityEngine.EventSystems.EventTriggerType.PointerClick, b =>
|
|
// {
|
|
// MoveBanner(false);
|
|
// });
|
|
// UIManager.AddEvent(btnRight.gameObject, UnityEngine.EventSystems.EventTriggerType.PointerClick, b =>
|
|
// {
|
|
// MoveBanner(true);
|
|
// });
|
|
//#endif
|
|
}
|
|
int pageIndex = 0, pageSize = 10;
|
|
bool isEnd = false,isLock = false;
|
|
private void Refresh()
|
|
{
|
|
pageIndex = 0;
|
|
isEnd = false;
|
|
scroll.content.DestroyChildren();
|
|
GetList();
|
|
}
|
|
|
|
async void GetList()
|
|
{
|
|
if (isLock) return;
|
|
isLock = true;
|
|
var res = await ConfigHelper.mapApi.GetMapRouteAreaList(pageIndex, pageSize);
|
|
isLock = false;
|
|
if (!res.result)
|
|
{
|
|
return;
|
|
}
|
|
if (res.data.Count == 0)
|
|
{
|
|
isEnd = true;
|
|
}
|
|
foreach (var groupItem in res.data)
|
|
{
|
|
var group = Instantiate<Transform>(tmpGroup);
|
|
group.GetComponent<NewRouteGroupController>().Initial(groupItem);
|
|
foreach (var area in groupItem.areas)
|
|
{
|
|
var item = Instantiate<Transform>(tmpItem);
|
|
item.GetComponent<NewRouteItemController>().Initial(area, caches);
|
|
item.SetParent(group.Find("Content"));
|
|
}
|
|
group.SetParent(collectionContent);
|
|
group.localScale = Vector3.one;
|
|
}
|
|
//for (int i = 0; i < 10; i++)
|
|
//{
|
|
// var group = Instantiate<Transform>(tmpGroup);
|
|
// for (int j = 0; j < 10; j++)
|
|
// {
|
|
// var item = Instantiate<Transform>(tmpItem);
|
|
// item.SetParent(group.Find("Content"));
|
|
// }
|
|
// group.SetParent(collectionContent);
|
|
// group.localScale = Vector3.one;
|
|
//}
|
|
//获取数据后需要重绘
|
|
LayoutRebuilder.ForceRebuildLayoutImmediate(collectionContent);
|
|
}
|
|
void MoveBanner(bool right)
|
|
{
|
|
#if !(UNITY_ANDROID || UNITY_IOS)
|
|
if (bannerContent == null) return;
|
|
if (!startPos.HasValue)
|
|
{
|
|
startPos = bannerContent.localPosition.x;
|
|
Debug.Log(startPos);
|
|
}
|
|
var k = right ? -1 : 1;
|
|
bannerIndex += k;
|
|
if (bannerIndex > 0)
|
|
{
|
|
bannerIndex = -3;
|
|
}
|
|
else if (bannerIndex < -3)
|
|
{
|
|
bannerIndex = 0;
|
|
}
|
|
bannerContent.DOLocalMoveX(startPos.Value + bannerIndex * 1171, 0.5f);
|
|
#endif
|
|
}
|
|
|
|
/// <summary>
|
|
/// 绑定头像
|
|
/// </summary>
|
|
|
|
|
|
void ToList(string type)
|
|
{
|
|
App.CurrentRouteType = type;// "";
|
|
UIManager.ShowMapListPanel();
|
|
}
|
|
public override void Show()
|
|
{
|
|
base.Show();
|
|
Debug.Log("触发59");
|
|
transform.MyDOFade();
|
|
}
|
|
// Update is called once per frame
|
|
float time = 10;
|
|
bool startMouse = false;
|
|
void Update()
|
|
{
|
|
time -= Time.deltaTime;
|
|
if (time <= 0)
|
|
{
|
|
MoveBanner(true);
|
|
time += 10;
|
|
}
|
|
|
|
if (Input.GetAxis("Mouse ScrollWheel") != 0)
|
|
{
|
|
if (scroll.verticalNormalizedPosition <= 0 || scroll.verticalNormalizedPosition>=1.1)
|
|
{
|
|
startMouse = true;
|
|
}
|
|
}
|
|
else
|
|
{
|
|
if (startMouse)
|
|
{
|
|
startMouse = false;
|
|
OnEndDrag(null);
|
|
}
|
|
}
|
|
}
|
|
}
|