NGUI笔记(一)

来源:互联网 发布:淘宝零食店铺哪里进货 编辑:程序博客网 时间:2024/05/16 02:01

1.UIScrollView

①重要成员函数:

设置位置

/// <summary>
/// Changes the drag amount of the scroll view to the specified 0-1 range values.
/// (0, 0) is the top-left corner, (1, 1) is the bottom-right.
/// </summary>

      public virtual void SetDragAmount (float x, float y, bool updateScrollbars)

②用于和Table 或Grid结合做一些动态刷新模板,及模板复用。

例如,游戏里的排行榜我们常常做法,是先创建10个玩家排行信息模板,而不是根据排行数量全部创建,这样DrawCall会非常的高。

当拖动到最上或者最下会调用下面类似代码

void OnPressChild(GameObject go, bool pressed)
    {
        if (!pressed)
        {
            Bounds b = scrollview.bounds;
            Vector3 constraint = scrollview.panel.CalculateConstrainOffset(b.min, b.max);
           // float offsetY = scrollview.transform.localPosition.y;
            if (constraint.y > 20f)
            {
               //请求上一页信息
            }
            if (constraint.y < -20f)
            {
                //请求下一页信息
            }
        }
    }

原创粉丝点击