首次提交

This commit is contained in:
Bob.Song
2026-03-05 18:07:55 +08:00
commit e125bb869e
4534 changed files with 563920 additions and 0 deletions

View File

@@ -0,0 +1,98 @@
using UnityEngine;
using FairyGUI;
public class PullToRefreshMain : MonoBehaviour
{
GComponent _mainView;
GList _list1;
GList _list2;
void Awake()
{
Application.targetFrameRate = 60;
Stage.inst.onKeyDown.Add(OnKeyDown);
UIObjectFactory.SetPackageItemExtension("ui://PullToRefresh/Header", typeof(ScrollPaneHeader));
}
void Start()
{
_mainView = this.GetComponent<UIPanel>().ui;
_list1 = _mainView.GetChild("list1").asList;
_list1.itemRenderer = RenderListItem1;
_list1.SetVirtual();
_list1.numItems = 1;
_list1.scrollPane.onPullDownRelease.Add(OnPullDownToRefresh);
_list2 = _mainView.GetChild("list2").asList;
_list2.itemRenderer = RenderListItem2;
_list2.SetVirtual();
_list2.numItems = 1;
_list2.scrollPane.onPullUpRelease.Add(OnPullUpToRefresh);
}
void RenderListItem1(int index, GObject obj)
{
GButton item = obj.asButton;
item.title = "Item " + (_list1.numItems - index - 1);
}
void RenderListItem2(int index, GObject obj)
{
GButton item = obj.asButton;
item.title = "Item " + index;
}
void OnPullDownToRefresh()
{
ScrollPaneHeader header = (ScrollPaneHeader)_list1.scrollPane.header;
if (header.ReadyToRefresh)
{
header.SetRefreshStatus(2);
_list1.scrollPane.LockHeader(header.sourceHeight);
//Simulate a async resquest
Timers.inst.Add(2, 1, (object param) =>
{
_list1.numItems += 5;
//Refresh completed
header.SetRefreshStatus(3);
_list1.scrollPane.LockHeader(35);
Timers.inst.Add(2, 1, (object param2) =>
{
header.SetRefreshStatus(0);
_list1.scrollPane.LockHeader(0);
});
});
}
}
void OnPullUpToRefresh()
{
GComponent footer = (GComponent)_list2.scrollPane.footer;
footer.GetController("c1").selectedIndex = 1;
_list2.scrollPane.LockFooter(footer.sourceHeight);
//Simulate a async resquest
Timers.inst.Add(2, 1, (object param) =>
{
_list2.numItems += 5;
//Refresh completed
footer.GetController("c1").selectedIndex = 0;
_list2.scrollPane.LockFooter(0);
});
}
void OnKeyDown(EventContext context)
{
if (context.inputEvent.keyCode == KeyCode.Escape)
{
Application.Quit();
}
}
}

View File

@@ -0,0 +1,12 @@
fileFormatVersion: 2
guid: cc11ef8b3e553814d83688351418d0cf
timeCreated: 1497251849
licenseType: Pro
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,37 @@
using FairyGUI;
using UnityEngine;
public class ScrollPaneHeader : GComponent
{
Controller _c1;
public override void ConstructFromXML(FairyGUI.Utils.XML xml)
{
base.ConstructFromXML(xml);
_c1 = this.GetController("c1");
this.onSizeChanged.Add(OnSizeChanged);
}
void OnSizeChanged()
{
if (_c1.selectedIndex == 2 || _c1.selectedIndex == 3)
return;
if (this.height > this.sourceHeight)
_c1.selectedIndex = 1;
else
_c1.selectedIndex = 0;
}
public bool ReadyToRefresh
{
get { return _c1.selectedIndex == 1; }
}
public void SetRefreshStatus(int value)
{
_c1.selectedIndex = value;
}
}

View File

@@ -0,0 +1,12 @@
fileFormatVersion: 2
guid: 30c3bcfb5d9414e4d8f75eedcfddea9c
timeCreated: 1497253470
licenseType: Pro
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant: