Unity FairyGUI(八)
一.滚动条
官方文档
- 滚动条不能单独在舞台上进行创建,需要配合滚动视图一起使用
二.滚动视图
public class Lesson31 : MonoBehaviour
{
private void Start()
{
GRoot.inst.SetContentScaleFactor(1365, 768,
UIContentScaler.ScreenMatchMode.MatchHeight);
var pack = UIPackage.AddPackage("Package1");
foreach (var item in pack.dependencies)
UIPackage.AddPackage(item["name"]);
var com = UIPackage.CreateObject("Package1", "LearnFGUI3").asCom;
GRoot.inst.AddChild(com);
var c1 = com.GetChild("n0").asCom;
var scrollView = c1.scrollPane;
scrollView.posY = 100;
scrollView.SetPercY(0.5f,true);
print(scrollView.viewWidth);
print(scrollView.viewHeight);
print(scrollView.contentWidth);
print(scrollView.contentHeight);
scrollView.touchEffect = true;
scrollView.onScroll.Add(() =>
{
});
scrollView.onScrollEnd.Add(() =>
{
Debug.Log("END");
});
scrollView.onPullUpRelease.Add(() =>
{
Debug.Log("上拉刷新!");
});
scrollView.onPullDownRelease.Add(() =>
{
Debug.Log("下拉刷新!");
});
}
}
var c1 = com.GetChild("n0").asCom;
var scrollView = c1.scrollPane;
for (int i = 0; i < 100; i++)
{
var go = UIPackage.CreateObject("Package1", "bk");
c1.AddChild(go);
go.SetSize(98, 98);
go.SetPosition(18 + (i % 5) * (98 + 18),18+(i/5)*(98+18),0);
}
三.列表
官方文档
- 非常强大的功能
- 底层有缓存池,可以设置为虚拟列表和滚动列表,对性能有非常大的优化
- 循环列表必须要是单行单列的列表
public class Lesson32 : MonoBehaviour
{
private void Start()
{
GRoot.inst.SetContentScaleFactor(1365, 768,
UIContentScaler.ScreenMatchMode.MatchHeight);
var pack = UIPackage.AddPackage("Package1");
foreach (var item in pack.dependencies)
UIPackage.AddPackage(item["name"]);
var com = UIPackage.CreateObject("Package1", "LearnFGUI3").asCom;
GRoot.inst.AddChild(com);
var lst = com.GetChild("n2").asList;
var go1 = lst.AddChild(UIPackage.CreateObject("Package1","quanlity_1"));
var go2 = lst.AddChild(UIPackage.CreateObject("Package1","quanlity_1"));
lst.RemoveChild(go1);
go1.Dispose();
var go = lst.AddItemFromPool();
go.text = "zzs";
lst.RemoveChildToPool(go);
lst.AddItemFromPool();
lst.RemoveChildToPoolAt(0);
lst.RemoveChildrenToPool(0,50);
lst.RemoveChildrenToPool();
lst.itemRenderer = (index, item) =>
{
item.text = index.ToString();
};
lst.onClickItem.Add((conetext) =>
{
Debug.Log((conetext.data as GObject).text);
});
lst.SetVirtualAndLoop();
lst.numItems = 10;
lst.Dispose();
}
}
四.下拉框
官方文档
public class Lesson34 : MonoBehaviour
{
void Start()
{
GRoot.inst.SetContentScaleFactor(1365, 768,
UIContentScaler.ScreenMatchMode.MatchHeight);
var pack = UIPackage.AddPackage("Package1");
foreach (var item in pack.dependencies)
UIPackage.AddPackage(item["name"]);
var com = UIPackage.CreateObject("Package1", "LearnFGUI4").asCom;
GRoot.inst.AddChild(com);
var comboBox = com.GetChild("n0").asComboBox;
comboBox.items = new string[]{"zzs","pnb","lzq","wy","ywj"};
comboBox.values = new string[]{"一","二","三","四","五"};
comboBox.visibleItemCount = 3;
comboBox.selectedIndex = 4;
comboBox.value = "二";
GRoot.inst.HidePopup();
comboBox.onChanged.Add(() =>
{
Debug.Log(comboBox.items[comboBox.selectedIndex]);
});
}
}
|