首页 新闻 会员 周边

NGUI UIScrollView SetDragAmount 函数分析

0
[已关闭问题] 关闭于 2019-05-19 00:13

public virtual void SetDragAmount (float x, float y, bool updateScrollbars)
{
if (mPanel == null) mPanel = GetComponent<UIPanel>();

    DisableSpring();

    Bounds b = bounds;
    if (b.min.x == b.max.x || b.min.y == b.max.y) return;

    Vector4 clip = mPanel.finalClipRegion;

    float hx = clip.z * 0.5f;
    float hy = clip.w * 0.5f;
    float left = b.min.x + hx;
    float right = b.max.x - hx;
    float bottom = b.min.y + hy;
    float top = b.max.y - hy;

    if (mPanel.clipping == UIDrawCall.Clipping.SoftClip)
    {
        left -= mPanel.clipSoftness.x;
        right += mPanel.clipSoftness.x;
        bottom -= mPanel.clipSoftness.y;
        top += mPanel.clipSoftness.y;
    }

    // Calculate the offset based on the scroll value
    float ox = Mathf.Lerp(left, right, x);
    float oy = Mathf.Lerp(top, bottom, y);

    // Update the position
    if (!updateScrollbars)
    {
        Vector3 pos = mTrans.localPosition;
        if (canMoveHorizontally) pos.x += clip.x - ox;
        if (canMoveVertically) pos.y += clip.y - oy;
        mTrans.localPosition = pos;
    }

    if (canMoveHorizontally) clip.x = ox;
    if (canMoveVertically) clip.y = oy;
     
    // Update the clipping offset
    Vector4 cr = mPanel.baseClipRegion;
    mPanel.clipOffset = new Vector2(clip.x - cr.x, clip.y - cr.y);

    // Update the scrollbars, reflecting this change
    if (updateScrollbars) UpdateScrollbars(mDragID == -10);
}
小·龙云的主页 小·龙云 | 初学一级 | 园豆:159
提问于:2019-05-19 00:05
< >
分享
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册