_list.SetVirtual(); 将列表虚拟化,(不会为每一条数据都实例化,根据视口大小创建最小量的显示对象)必须通过_list.itemRenderer回调函数,设置列表数据。
在滑动列表的时候,可以用一下这段代码来实现,距离的把控,显示最近的。
void DoSpecialEffect()
{
//change the scale according to the distance to middle
float midX = _list.scrollPane.posX + _list.viewWidth / 2;
int cnt = _list.numChildren;
for (int i = 0; i < cnt; i++)
{
GObject obj = _list.GetChildAt(i);
float dist = Mathf.Abs(midX - obj.x - obj.width / 2);
if (dist > obj.width) //no intersection
obj.SetScale(1, 1);
else
{
float ss = 1 + (1 - dist / obj.width) * 0.24f;
obj.SetScale(ss, ss);
}
}
//当前的页面数
_mainView.GetChild("n3").text = "" + ((_list.GetFirstChildInView() + 1) % _list.numItems);
}
//导入一个prefab,然后显现出来
Object prefab = Resources.Load("Role/npc");
GameObject go = (GameObject)Object.Instantiate(prefab);
go.transform.localPosition = new Vector3(61, -89, 1000); //set z to far from UICamera is important!
go.transform.localScale = new Vector3(180, 180, 180);
go.transform.localEulerAngles = new Vector3(0, 100, 0);
_mainView.GetChild("holder").asGraph.SetNativeObject(new GoWrapper(go));
设置新手指导
_guideLayer = UIPackage.CreateObject("Guide", "GuideLayer").asCom;
_guideLayer.SetSize(GRoot.inst.width, GRoot.inst.height);
_guideLayer.AddRelation(GRoot.inst, RelationType.Size);
GObject bagBtn = _mainView.GetChild("bagBtn");
bagBtn.onClick.Add(() =>
{
_guideLayer.RemoveFromParent();
});
_mainView.GetChild("n2").onClick.Add(() =>
{
GRoot.inst.AddChild(_guideLayer); //!!Before using TransformRect(or GlobalToLocal), the object must be added first
Rect rect = bagBtn.TransformRect(new Rect(0, 0, bagBtn.width, bagBtn.height), _guideLayer);
GObject window = _guideLayer.GetChild("window");
window.size = new Vector2((int)rect.size.x, (int)rect.size.y);
window.TweenMove(new Vector2((int)rect.position.x, (int)rect.position.y), 0.5f);
});