This commit is contained in:
lishuo committed 2022-05-13 09:28:58 +08:00
1 parent 509c309252
commit 11b131b24a
60 files changed
+2505 -632

No files matched your search

@@ -0,0 +1,28 @@
using System;
using UnityEngine;
using UnityEngine.UI;
namespace Assets.Scripts.UI.Control
{
public class PFUIPageButton : PFUIComponentBase
{
public Text pageIndexText;
public GameObject clickImage;
public int PageIndex { get; set; }
public void SetPageIndex(int pageIndex)
{
PageIndex = pageIndex;
pageIndexText.text = $"{pageIndex + 1}";//pageIndex 从0开始
}
public void ShowLight()
{
clickImage.SetActive(true);
}
public void ShowShadow()
{
clickImage.SetActive(false);
}
}
}
@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: c49931be379e5a448a6f107bb2bf94f3
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
+94 -10
View File
@@ -8,36 +8,105 @@ namespace Assets.Scripts.UI.Control
public class PFUIPageHelper : PFUIComponentBase
{
public Transform content;
public GameObject preBtn;
public GameObject nextBtn;
public GameObject moreBtnPrefab;
public GameObject preBtnPrefab;
public GameObject nextBtnPrefab;
public GameObject btnPrefab;
public int PageIndex { get; set; }
public int PageSize { get; set; } = 6;
public int Total { get; set; }
public int _pageMaxTotal = 9;
public int _pageSpace = 4;
private Action<int> CallBack { get; set; }
public void Register(Action<int> refresh)
{
CallBack = refresh;
}
public void Build()
{
Utils.DestroyChildren(content);
UIManager.AddEvent(preBtn, UnityEngine.EventSystems.EventTriggerType.PointerClick, (e) =>
RenderPreviousButton();
for (int i = 0; i < Total; i++)
{
Previous();
if (PageIndex - 0 >= 4 && i < PageIndex)
{
if (i == 0 || PageIndex -1 == i || PageIndex -2 == i)
{
RenderPageButton(i);
}
if (i == 1)
{
RenderMoreButton();
}
continue;
}
if (Total -PageIndex-1 >= 4 && i >= PageIndex)
{
if (i == Total-1 || PageIndex == i || PageIndex + 1 == i || PageIndex + 2 == i)
{
RenderPageButton(i);
}
if (i == Total - 2)
{
RenderMoreButton();
}
continue;
}
RenderPageButton(i);
}
RenderNextButton();
}
private void RenderMoreButton()
{
var moreBtn = Instantiate(moreBtnPrefab, content);
moreBtn.SetActive(true);
}
private void RenderPageButton(int pageIndex)
{
var btn = Instantiate(btnPrefab, content);
var script = btn.GetComponent<PFUIPageButton>();
script.SetPageIndex(pageIndex);
if (pageIndex == PageIndex)
{
script.ShowLight();
}
else
{
script.ShowShadow();
}
UIManager.AddEvent(btn, UnityEngine.EventSystems.EventTriggerType.PointerClick, (e) =>
{
Redirect(pageIndex);
});
}
private void RenderNextButton()
{
var nextBtn = Instantiate(nextBtnPrefab, content);
nextBtn.SetActive(true);
UIManager.AddEvent(nextBtn, UnityEngine.EventSystems.EventTriggerType.PointerClick, (e) =>
{
Next();
});
}
public void Build()
private void RenderPreviousButton()
{
Utils.DestroyChildren(content);
for (int i = 1; i <= Total; i++)
var preBtn = Instantiate(preBtnPrefab, content);
preBtn.SetActive(true);
UIManager.AddEvent(preBtn, UnityEngine.EventSystems.EventTriggerType.PointerClick, (e) =>
{
var g = Instantiate(btnPrefab, content);
g.transform.Find("Text").GetComponent<Text>().text = i.ToString();
}
Previous();
});
}
//上一页
private void Previous()
@@ -48,6 +117,7 @@ namespace Assets.Scripts.UI.Control
{
PageIndex = index;
CallBack?.Invoke(PageIndex);
Build();
}
}
//下一页
@@ -59,13 +129,27 @@ namespace Assets.Scripts.UI.Control
{
PageIndex = index;
CallBack?.Invoke(PageIndex);
Build();
}
}
//指定到第几页
private void Redirect(int index)
{
var list = FindObjectsOfType<PFUIPageButton>();
foreach (var item in list)
{
if (item.PageIndex == index)
{
item.ShowLight();
}
else
{
item.ShowShadow();
}
}
PageIndex = index;
CallBack?.Invoke(PageIndex);
Build();
}
}
}