powerfun-unity/Assets/Scripts/UI/Prefab/Panel/NewRouteOverviewController.cs

264 lines
8.4 KiB
C#
Raw Normal View History

2021-12-10 09:53:49 +08:00
using Assets.Scripts;
2021-12-14 18:10:58 +08:00
using DG.Tweening;
using System;
2021-12-10 09:53:49 +08:00
using System.Collections;
2021-12-07 14:37:08 +08:00
using System.Collections.Generic;
using UnityEngine;
2021-12-14 18:10:58 +08:00
using UnityEngine.EventSystems;
2021-12-07 14:37:08 +08:00
using UnityEngine.UI;
public class NewRouteOverviewController: PFUIPanel
{
// Start is called before the first frame update
Transform tmpGroup;
Transform tmpItem;
2021-12-14 18:10:58 +08:00
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>();
2022-01-11 11:18:09 +08:00
#if !UNITY_STANDALONE_WIN
2021-12-28 11:25:09 +08:00
scroll.onValueChanged.RemoveAllListeners();
scroll.onValueChanged.AddListener(p=>
{
var rect = transform.Find("Container").GetComponent<RectTransform>();
//Debug.Log($"{rect.offsetMin} {rect.offsetMax}");
2021-12-28 11:25:09 +08:00
if (p.y < 0.9)
{
DOTween.To(() => rect.offsetMax, x => rect.offsetMax = x, new Vector2(rect.offsetMax.x, -10), 0.5f);
}
else
{
DOTween.To(() => rect.offsetMax, x => rect.offsetMax = x, new Vector2(rect.offsetMax.x, -68), 0.5f);
}
});
2022-01-11 11:18:09 +08:00
#endif
2021-12-14 18:10:58 +08:00
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");
}
2021-12-07 14:37:08 +08:00
void Start()
{
2021-12-14 18:10:58 +08:00
#if !(UNITY_ANDROID || UNITY_IOS)
2021-12-07 14:37:08 +08:00
tmpGroup = Resources.Load<Transform>("UI/Prefab/NewRoute/RouteGroup");
tmpItem = Resources.Load<Transform>("UI/Prefab/NewRoute/RouteItem");
2021-12-14 18:10:58 +08:00
#else
2021-12-28 11:25:09 +08:00
var nav = transform.Find("Tmp/MainNav-mobile").GetComponent<NewMainNav>();
2022-07-06 17:48:55 +08:00
nav.SetButtonActive(new List<int> { 2, 3, 6, 7 }, 2,
new NewMainNav.CustomButton(Resources.Load<Sprite>("Images/map_mode"),()=>
{
UIManager.PopStack();
//UIManager.ShowBigMapPanel();
UIManager.ShowEarthPanel(App.latitude, App.longitude);
}));
2021-12-29 14:23:37 +08:00
newNav = nav;
2021-12-14 18:10:58 +08:00
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);
});
2021-12-14 18:10:58 +08:00
collectionContent = transform.Find("Container/Right/Scroll View/Viewport/Content")
2021-12-07 14:37:08 +08:00
.GetComponent<RectTransform>();
2021-12-14 18:10:58 +08:00
Refresh();
2021-12-10 09:53:49 +08:00
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");
});
2021-12-29 14:23:37 +08:00
UIManager.AddEvent(transform.Find("Container/BtnSearch").gameObject, EventTriggerType.PointerClick, b =>
{
GoSearch();
});
2021-12-15 18:18:12 +08:00
BindHeadImage();
2021-12-15 11:08:18 +08:00
//banner暂时注释
2021-12-15 18:18:12 +08:00
//#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
2021-12-14 18:10:58 +08:00
}
int pageIndex = 0, pageSize = 5;
2021-12-14 18:10:58 +08:00
bool isEnd = false,isLock = false;
private void Refresh()
{
pageIndex = 0;
isEnd = false;
scroll.content.DestroyChildren();
GetList();
2021-12-07 14:37:08 +08:00
}
2021-12-14 18:10:58 +08:00
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;
2022-05-25 18:40:47 +08:00
//获取数据后需要重绘
LayoutRebuilder.ForceRebuildLayoutImmediate(collectionContent);
2021-12-14 18:10:58 +08:00
}
//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;
//}
2022-05-25 18:40:47 +08:00
2021-12-14 18:10:58 +08:00
}
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
}
2021-12-15 18:18:12 +08:00
/// <summary>
2021-12-29 14:23:37 +08:00
///
2021-12-15 18:18:12 +08:00
/// </summary>
2021-12-10 09:53:49 +08:00
void ToList(string type)
{
2022-07-15 13:07:23 +08:00
App.CurrentRouteType = type;
2021-12-10 09:53:49 +08:00
UIManager.ShowMapListPanel();
}
2021-12-29 14:23:37 +08:00
void GoSearch()
{
App.CurrentRouteType = "All Route";// "";
UIManager.ShowMapListPanel(panel=>
{
panel.OpenFilter();
});
}
2021-12-10 09:53:49 +08:00
public override void Show()
{
base.Show();
Debug.Log("触发59");
transform.MyDOFade();
}
2021-12-07 14:37:08 +08:00
// Update is called once per frame
2021-12-14 18:10:58 +08:00
float time = 10;
bool startMouse = false;
2021-12-07 14:37:08 +08:00
void Update()
{
2021-12-14 18:10:58 +08:00
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);
}
}
2021-12-07 14:37:08 +08:00
}
}