public void InitScrollSprites(UXFactory source, UIScrollView scrollView, float scrollPosition, bool isScrollable)
 {
     if (scrollView != null && source != null)
     {
         string text  = "Sprite" + scrollView.name;
         string text2 = text;
         string text3 = text;
         UIScrollView.Movement movement = scrollView.movement;
         if (movement != UIScrollView.Movement.Horizontal)
         {
             if (movement == UIScrollView.Movement.Vertical)
             {
                 text2 += "ScrollUp";
                 text3 += "ScrollDown";
             }
         }
         else
         {
             text2 += "ScrollLeft";
             text3 += "ScrollRight";
         }
         this.scrollBackSprite    = source.GetOptionalElement <UXSprite>(text2);
         this.scrollForwardSprite = source.GetOptionalElement <UXSprite>(text3);
         this.UpdateScrollSprites(scrollView, scrollPosition, isScrollable);
     }
 }
Beispiel #2
0
    /** 初始化 */

    private void initGrid()
    {
        ClearChild();
        itemTrans = new Transform[defaultMaxLine];
        for (int i = 0; i < defaultMaxLine; i++)
        {
            itemTrans[i] = CreatItemTransfrom(i);
        }

        movement = sView.movement;

        sView.onDragStarted   = onDragStarted;
        sView.onDragFinished  = onDragFinished;
        sView.onMomentumMove  = onMomentumMove;
        sView.onStoppedMoving = onStoppedMoving;

        /** 初始化位置 */
        ResetPostion();

        /** 初始化数据 */
        indexStar      = 0;
        indexEnd       = defaultMaxLine - 1;
        indexMax       = 0;
        panelPos       = Vector3.zero;
        lastIndex      = 0;
        showStartIndex = 0;
        if (scrollGridSetItem != null)
        {
            scrollGridSetItem(itemTrans, indexStar, indexEnd);
        }
        SetMessage();
        ResetScrollPanelPosition();
    }
Beispiel #3
0
    private void InitPosAndScroll()
    {
        m_scrollView = transform.parent.GetComponent <UIScrollView>();

        if (m_scrollView == null)
        {
            //Debug.LogException(new Exception("父节点必须有ScrollView这个组件"));
        }
        m_panel = m_scrollView.GetComponent <UIPanel>();

        if (m_panel == null)
        {
            //Debug.LogException(new Exception("父节点必须有UIPanel这个组件"));
        }

        m_panelInitPos = m_scrollView.transform.localPosition;
        m_initOffset   = m_panel.clipOffset;
        m_moveType     = m_scrollView.movement;
        EnableDestory();
        if (m_uiRoot == null)
        {
            if (UIRoot.list.Count <= 0)
            {
                throw new Exception("必须要有一个没被隐藏的UIRoot");
            }
            m_uiRoot = UIRoot.list[0];
        }
        if (itemTemplate != null)
        {
            itemTemplate.SetActive(false);
        }
        m_initiated = true;
    }
Beispiel #4
0
    private void InitPosAndScroll()
    {
        m_scrollView = transform.parent.GetComponent <UIScrollView>();
        if (m_scrollView == null)
        {
            Debug.LogException(new Exception("父节点必须有ScrollView这个组件"));
        }
        m_scrollView.momentumAmount = 100;

        m_panel = m_scrollView.GetComponent <UIPanel>();
        if (m_panel == null)
        {
            Debug.LogException(new Exception("父节点必须有UIPanel这个组件"));
        }

        m_panelInitPos = m_scrollView.transform.localPosition;
        m_initOffset   = m_panel.clipOffset;
        m_moveType     = m_scrollView.movement;
        EnableDestory();

        if (itemTemplate != null)
        {
            itemTemplate.gameObject.SetActive(false);
        }
        m_initiated = true;
    }
        // public void init (WXBeefBallHierarchyContext context) {
        //     // 添加控制父节点
        //     WXBeefBallEntity scrollViewControllerEntity = context.CreateEntity(null);
        //     scrollViewControllerEntity.isExtraEntity = false;
        //     scrollViewControllerEntity.isNguiChild = true;

        //     WXBBTransform2DComponent transformController = new WXBBTransform2DComponent(gameObj.transform);
        //     WXBBUIScrollViewController scrollViewController = new WXBBUIScrollViewController(uiScrollView, gameObj, transformController);
        //     scrollViewControllerEntity.components.Add(context.addComponent(scrollViewController, null));
        //     WXBeefBallTouchInputComponent touchInput = new WXBeefBallTouchInputComponent(gameObj, null);
        //     scrollViewControllerEntity.components.Add(context.addComponent(touchInput, null));
        //     // 蒙版区域
        //     WXBBUIMask mask = new WXBBUIMask();
        //     WXBBUIGraphic graphic = new WXBBUIGraphic(0);
        //     scrollViewControllerEntity.components.Add(context.addComponent(mask, null));
        //     scrollViewControllerEntity.components.Add(context.addComponent(graphic, null));

        //     // 内容区域矫正
        //     UIPanel uiPanel = gameObj.GetComponent(typeof(UIPanel)) as UIPanel;
        //     if ((UnityEngine.Object)uiPanel != (UnityEngine.Object)null)
        //     {
        //         Vector4 offSet = uiPanel.clipOffset;
        //         Vector2 center = uiPanel.baseClipRegion;

        //         transform.size[0] = uiPanel.width;
        //         transform.size[1] = uiPanel.height;

        //         transform.setPosition(-((float)offSet.x + (float)center.x), -((float)offSet.y + (float)center.y));
        //     }

        //     scrollViewControllerEntity.components.Add(context.addComponent(transformController, null));
        //     // 修改父子关系
        //     scrollViewControllerEntity.parent = entity.parent;
        //     entity.parent = scrollViewControllerEntity;


        // }

        protected override JSONObject ToJSON(WXHierarchyContext context)
        {
            entity.components.Add(context.AddComponent(new WXTouchInputComponent(null, gameObject, entity), null));
            entity.components.Add(context.AddComponent(new WXUIMask(), null));
            entity.components.Add(context.AddComponent(new WXUIGraphic(0), null));

            JSONObject json = new JSONObject(JSONObject.Type.OBJECT);

            json.AddField("type", "UIScrollView");

            JSONObject subJSON = new JSONObject(JSONObject.Type.OBJECT);

            UIScrollView.Movement movement = uiScrollView.movement;
            subJSON.AddField("movement", (int)movement);

            bool disableDragIfFits = uiScrollView.disableDragIfFits;

            subJSON.AddField("disableDragIfFits", (bool)disableDragIfFits);

            UIPanel uiPanel = gameObject.GetComponent(typeof(UIPanel)) as UIPanel;

            if ((UnityEngine.Object)uiPanel != (UnityEngine.Object)null)
            {
                Vector4 offSet = uiPanel.clipOffset;
                Vector2 center = uiPanel.baseClipRegion;
                subJSON.AddField("offSetX", (float)offSet.x);
                subJSON.AddField("offSetY", (float)offSet.y);
                subJSON.AddField("centerX", (float)center.x);
                subJSON.AddField("centerY", (float)center.y);
            }

            UIWidget.Pivot contentPivot   = uiScrollView.contentPivot;
            float          cellAlignmentX = (
                contentPivot == UIWidget.Pivot.Left ||
                contentPivot == UIWidget.Pivot.TopLeft ||
                contentPivot == UIWidget.Pivot.BottomLeft
                ) ? 0.0f : ((
                                contentPivot == UIWidget.Pivot.Center ||
                                contentPivot == UIWidget.Pivot.Top ||
                                contentPivot == UIWidget.Pivot.Bottom) ? 0.5f : 1.0f);

            float cellAlignmentY = (
                contentPivot == UIWidget.Pivot.Bottom ||
                contentPivot == UIWidget.Pivot.BottomLeft ||
                contentPivot == UIWidget.Pivot.BottomRight
                ) ? 0.0f : ((
                                contentPivot == UIWidget.Pivot.Left ||
                                contentPivot == UIWidget.Pivot.Center ||
                                contentPivot == UIWidget.Pivot.Right) ? 0.5f : 1.0f);

            subJSON.AddField("cellAlignmentX", cellAlignmentX);
            subJSON.AddField("cellAlignmentY", cellAlignmentY);



            json.AddField("data", subJSON);
            return(json);
        }
Beispiel #6
0
    static private float CalItemDistance(UIScrollView.Movement moveType, Vector3 postion)
    {
        float moveLength = 0;

        if (moveType == UIScrollView.Movement.Horizontal)
        {
            moveLength = Math.Abs(postion.x);
        }
        else
        {
            moveLength = Math.Abs(postion.y);
        }
        return(moveLength);
    }
Beispiel #7
0
    static private void MoveGridItem <T>(
        List <List <T> > scrollItems, UIScrollView.Movement moveType, IList datas, int maxPerLine, ref int minIndex, ref int maxIndex,
        ref int forwardCacheNum, bool isTopToBottom, bool isMoveForward) where T : GridBaseItem
    {
        List <T> items;
        // 判断是否是 上(左)移动到下(右)
        int curIndex;
        int itemIndex;
        int sign;

        if (isTopToBottom)
        {
            curIndex  = maxIndex + 1;
            itemIndex = 0;
            sign      = 1;
        }
        else
        {
            curIndex  = minIndex - 1;
            itemIndex = scrollItems.Count - 1;
            sign      = -1;
        }
        items = scrollItems[itemIndex];

        int targetIndex = itemIndex == 0 ? scrollItems.Count - 1 : 0;

        scrollItems.Remove(items);
        scrollItems.Insert(targetIndex, items);

        for (int i = 0; i < items.Count; i++)
        {
            if (!isMoveForward && curIndex * maxPerLine + i > datas.Count - 1)
            {
                break;
            }
            T item = items[i];
            item.FillItem(datas, curIndex * maxPerLine + i);
        }

        minIndex += sign;
        maxIndex += sign;
        if (isMoveForward)
        {
            forwardCacheNum -= sign;
        }
    }
Beispiel #8
0
    static int get_movement(IntPtr L)
    {
        object o = null;

        try
        {
            o = ToLua.ToObject(L, 1);
            UIScrollView          obj = (UIScrollView)o;
            UIScrollView.Movement ret = obj.movement;
            ToLua.Push(L, ret);
            return(1);
        }
        catch (Exception e)
        {
            return(LuaDLL.toluaL_exception(L, e, o, "attempt to index movement on a nil value"));
        }
    }
Beispiel #9
0
    static int set_movement(IntPtr L)
    {
        object o = null;

        try
        {
            o = ToLua.ToObject(L, 1);
            UIScrollView          obj  = (UIScrollView)o;
            UIScrollView.Movement arg0 = (UIScrollView.Movement)ToLua.CheckObject(L, 2, typeof(UIScrollView.Movement));
            obj.movement = arg0;
            return(0);
        }
        catch (Exception e)
        {
            return(LuaDLL.toluaL_exception(L, e, o, "attempt to index movement on a nil value"));
        }
    }
Beispiel #10
0
    // Use this for initialization
    void Start()
    {
        _swipeState = SwipeState.None;

        _isFirstTouch = true;

        _uiScrollView = GetComponentInChildren <UIScrollView>();

        if (null == _uiScrollView)
        {
            throw new MissingComponentException("TestSwipeScripts.Start - can't get UIScrollView component for _uiScrollView");
        }

        _startingMomentum            = _uiScrollView.momentumAmount;
        _uiScrollView.panel.clipping = UIDrawCall.Clipping.None;

        _panel = _uiScrollView.GetComponent <UIPanel>();

        if (null == _panel)
        {
            throw new MissingComponentException("TestSwipeScripts.Start - can't get UIPanel component for _panel");
        }

        DynamicScrollView2 dynamicScrollView = FindObjectOfType <DynamicScrollView2>();

        if (null == dynamicScrollView)
        {
            throw new NullReferenceException("TestSwipeScripts.Start - can't find DynamicScrollView object");
        }

        _thresholdDistanceToCloseCard         = dynamicScrollView.closeDetailCardThresholdHorizontal;
        _thresholdDistanceVerticalToCloseCard = dynamicScrollView.closeDetailCardThreshold;


        ScrollViewContainer = NGUITools.FindInParents <UIWidget>(_uiScrollView.transform);

        if (null == ScrollViewContainer)
        {
            throw new MissingComponentException("TestSwipeScripts.Start - can't get UIWidget component for _scrollViewContainer");
        }

        _currentScale = Vector3.one;

        _previousMovementState = UIScrollView.Movement.Custom;
    }
    private void InitNeed()
    {
        if (IsSvNull())
        {
            return;
        }
        mPanel = mScrollView.panel;
        Vector3 center    = mScrollView.transform.position;
        Vector3 boundSize = mPanel.GetViewSize();

        mPanelBounds = new Bounds(center, boundSize);
        mMovement    = mScrollView.movement;
        RegisterEvent();

        cellParent      = NGUITools.AddChild(mScrollView.gameObject);
        cellParent.name = "EquidistanceRecycle";
        InitPanelColRow();
    }
Beispiel #12
0
    protected override void Awake()
    {
        base.Awake();
        usw = GetComponent <UIScrollView>();
        um  = usw.movement;
        if (um == UIScrollView.Movement.Horizontal)
        {
            tsartSpanX = finalClipRegion.z / 2 + usw.bounds.min.x - finalClipRegion.x;
        }
        else if (um == UIScrollView.Movement.Vertical)
        {
            tsartSpanY = finalClipRegion.w / 2 - usw.bounds.max.y + finalClipRegion.y;
        }

        lastClipOffset     = clipOffset;
        lastBaseClipRegion = baseClipRegion;
        lastlocalPosition  = transform.localPosition;
    }
Beispiel #13
0
    private static int set_movement(IntPtr L)
    {
        object obj = null;
        int    result;

        try
        {
            obj = ToLua.ToObject(L, 1);
            UIScrollView          uIScrollView = (UIScrollView)obj;
            UIScrollView.Movement movement     = (UIScrollView.Movement)((int)ToLua.CheckObject(L, 2, typeof(UIScrollView.Movement)));
            uIScrollView.movement = movement;
            result = 0;
        }
        catch (Exception ex)
        {
            result = LuaDLL.toluaL_exception(L, ex, (obj != null) ? ex.Message : "attempt to index movement on a nil value");
        }
        return(result);
    }
Beispiel #14
0
    private static int get_movement(IntPtr L)
    {
        object obj = null;
        int    result;

        try
        {
            obj = ToLua.ToObject(L, 1);
            UIScrollView          uIScrollView = (UIScrollView)obj;
            UIScrollView.Movement movement     = uIScrollView.movement;
            ToLua.Push(L, movement);
            result = 1;
        }
        catch (Exception ex)
        {
            result = LuaDLL.toluaL_exception(L, ex, (obj != null) ? ex.Message : "attempt to index movement on a nil value");
        }
        return(result);
    }
Beispiel #15
0
 private void Awake()
 {
     this.mTrans = base.transform;
     this.mPanel = base.GetComponent <UIPanel>();
     if (this.mPanel.clipping == UIDrawCall.Clipping.None)
     {
         this.mPanel.clipping = UIDrawCall.Clipping.ConstrainButDontClip;
     }
     if (this.movement != UIScrollView.Movement.Custom && this.scale.sqrMagnitude > 0.001f)
     {
         if (this.scale.x == 1f && this.scale.y == 0f)
         {
             this.movement = UIScrollView.Movement.Horizontal;
         }
         else
         {
             if (this.scale.x == 0f && this.scale.y == 1f)
             {
                 this.movement = UIScrollView.Movement.Vertical;
             }
             else
             {
                 if (this.scale.x == 1f && this.scale.y == 1f)
                 {
                     this.movement = UIScrollView.Movement.Unrestricted;
                 }
                 else
                 {
                     this.movement         = UIScrollView.Movement.Custom;
                     this.customMovement.x = this.scale.x;
                     this.customMovement.y = this.scale.y;
                 }
             }
         }
         this.scale = Vector3.zero;
     }
     if (this.contentPivot == UIWidget.Pivot.TopLeft && this.relativePositionOnReset != Vector2.zero)
     {
         this.contentPivot            = NGUIMath.GetPivot(new Vector2(this.relativePositionOnReset.x, 1f - this.relativePositionOnReset.y));
         this.relativePositionOnReset = Vector2.zero;
     }
 }
Beispiel #16
0
 void Awake()
 {
     m_Movement = m_ScrollView.movement;
     //只支持Horizontal , Vertical
     if (m_Movement > UIScrollView.Movement.Vertical)
     {
         Debug.LogError("不支持UITable scrolview movment " + m_Movement);
     }
     if (m_Grid != null && m_Table == null)
     {
         m_bGrid = true;
         if (m_Movement == UIScrollView.Movement.Horizontal)
         {
             Debug.LogError("不支持UIGrid scrolview movment " + m_Movement);
         }
     }
     else
     {
         m_bGrid = false;
     }
 }
Beispiel #17
0
    private void InitPosAndScroll()
    {
        m_scrollView = transform.parent.GetComponent <UIScrollView>();
        if (m_scrollView == null)
        {
            Debug.LogException(new Exception("父节点必须有ScrollView这个组件"));
        }
#if UNITY_STANDALONE_WIN
        m_scrollView.momentumAmount = amount / 3;
#else
        m_scrollView.momentumAmount = amount;
#endif
        m_panel = m_scrollView.GetComponent <UIPanel>();
        if (m_panel == null)
        {
            Debug.LogException(new Exception("父节点必须有UIPanel这个组件"));
        }
        m_halfPanelWidth  = m_panel.width / 2;
        m_halfPanelHeight = m_panel.height / 2;

        m_panelInitPos = m_scrollView.transform.localPosition;
        m_initOffset   = m_panel.clipOffset;
        m_moveType     = m_scrollView.movement;
        EnableDisable();
        if (m_drag == null)
        {
            CreateDragBox();
        }
        else
        {
            InitBoxSize();
        }
        if (itemTemplate != null)
        {
            itemTemplate.SetActive(false);
        }
        CreateItemPool(itemTemplate, 0);

        m_initiated = true;
    }
Beispiel #18
0
    private void InitNeed()
    {
        if (IsSvNull())
        {
            return;
        }
        mPanel = mScrollView.panel;
        var sizey = mPanel.baseClipRegion.w;

        mPanel.baseClipRegion = new Vector4(0, 0, cellSize * pageColumnLimit, sizey);
        Vector3 center    = mScrollView.transform.position;
        Vector3 boundSize = mPanel.GetViewSize();

        mPanelBounds = new Bounds(center, boundSize);
        mMovement    = mScrollView.movement;
        mScrollView.DisableSpring();

        RegisterEvent();

        cellParent      = NGUITools.AddChild(mScrollView.gameObject);
        cellParent.name = "EquidistancePageRecycle";

        InitPanelColRow();
    }
Beispiel #19
0
    static private void ReSetCellPostion <T>(T item, UIScrollView.Movement moveType, Vector3 pos, bool isTopToBottom, float cellWidth, float cellHeight, UITable.Direction direction) where T : TableBaseItem
    {
        int sign = 1;

        if (direction == UITable.Direction.Down)
        {
            if (isTopToBottom)
            {
                sign = -1;
            }
            else
            {
                sign = 1;
            }
        }
        else
        {
            if (!isTopToBottom)
            {
                sign = -1;
            }
            else
            {
                sign = 1;
            }
        }

        if (moveType == UIScrollView.Movement.Horizontal)
        {
            item.transform.localPosition = new Vector3(pos.x + sign * cellWidth, pos.y, 0);
        }
        else if (moveType == UIScrollView.Movement.Vertical)
        {
            item.transform.localPosition = new Vector3(pos.x, pos.y + sign * cellHeight, 0);
        }
    }
Beispiel #20
0
    /// <summary>
    /// 绑定需要显示的数据及对应Item显示内容
    /// </summary>
    /// <param name="Count"> 数据总数</param>
    /// <param name="func"> item界面刷新显示</param>
    ///

    public void BindDataSource(int Count, ProcessItemByIndex func, int iStartIndex)
    {
        m_Movement = m_ScrollView.movement;

        if (m_Movement > UIScrollView.Movement.Vertical)
        {
            Debug.LogError("不支持scrolview movment " + m_Movement);
        }
        if (m_Grid != null && m_Table == null)
        {
            m_bGrid = true;
            if (m_Movement == UIScrollView.Movement.Horizontal)
            {
                Debug.LogError("不支持UIGrid scrolview movment " + m_Movement);
            }
        }
        else
        {
            m_bGrid = false;
        }
        _ProcessItemByIndex = func;
        m_nTotalDataCount   = Count;
        InitTableViewImp(iStartIndex);
    }
Beispiel #21
0
    static public void MoveTableItem <T>(
        List <T> scrollItems, UIScrollView.Movement moveType, IList datas, ref int minIndex, ref int maxIndex,
        ref int forwardCacheNum, bool isTopToBottom, bool isMoveForward, UITable.Direction direction, Vector2 padding) where T : TableBaseItem
    {
        T item;
        // 判断是否是 上(左)移动到下(右)
        int curIndex;
        int itemIndex;
        int sign;

        if (isTopToBottom)
        {
            curIndex  = maxIndex + 1;
            itemIndex = 0;
            sign      = 1;
        }
        else
        {
            curIndex  = minIndex - 1;
            itemIndex = scrollItems.Count - 1;
            sign      = -1;
        }
        item = scrollItems[itemIndex];

        int     targetIndex = itemIndex == 0 ? scrollItems.Count - 1 : 0;
        T       targetItem  = scrollItems[targetIndex];
        Vector3 targetPos   = targetItem.transform.localPosition;

        scrollItems.Remove(item);
        scrollItems.Insert(targetIndex, item);

        item.FillItem(datas, curIndex);
        Bounds b;

        if (direction == UITable.Direction.Down)
        {
            if (isTopToBottom)
            {
                b = NGUIMath.CalculateRelativeWidgetBounds(targetItem.transform, false);
            }
            else
            {
                b = NGUIMath.CalculateRelativeWidgetBounds(item.transform, false);
            }
        }
        else
        {
            if (!isTopToBottom)
            {
                b = NGUIMath.CalculateRelativeWidgetBounds(targetItem.transform, false);
            }
            else
            {
                b = NGUIMath.CalculateRelativeWidgetBounds(item.transform, false);
            }
        }

        float cellHeight = b.size.y + padding.y;
        float cellWidth  = b.size.x + padding.x;

        ReSetCellPostion <T>(item, moveType, targetPos, isTopToBottom, cellWidth, cellHeight, direction);


        minIndex += sign;
        maxIndex += sign;
        if (isMoveForward)
        {
            forwardCacheNum -= sign;
        }
    }
    public void Recenter()
    {
        if (this.mScrollView == null)
        {
            this.mScrollView = NGUITools.FindInParents <UIScrollView>(base.gameObject);
            if (this.mScrollView == null)
            {
                global::Debug.LogWarning(string.Concat(new object[]
                {
                    base.GetType(),
                    " requires ",
                    typeof(UIScrollView),
                    " on a parent object in order to work"
                }), this);
                base.enabled = false;
                return;
            }
            if (this.mScrollView)
            {
                this.mScrollView.centerOnChild = this;
                UIScrollView uiscrollView = this.mScrollView;
                uiscrollView.onDragFinished = (UIScrollView.OnDragNotification)Delegate.Combine(uiscrollView.onDragFinished, new UIScrollView.OnDragNotification(this.OnDragFinished));
            }
            if (this.mScrollView.horizontalScrollBar != null)
            {
                UIProgressBar horizontalScrollBar = this.mScrollView.horizontalScrollBar;
                horizontalScrollBar.onDragFinished = (UIProgressBar.OnDragFinished)Delegate.Combine(horizontalScrollBar.onDragFinished, new UIProgressBar.OnDragFinished(this.OnDragFinished));
            }
            if (this.mScrollView.verticalScrollBar != null)
            {
                UIProgressBar verticalScrollBar = this.mScrollView.verticalScrollBar;
                verticalScrollBar.onDragFinished = (UIProgressBar.OnDragFinished)Delegate.Combine(verticalScrollBar.onDragFinished, new UIProgressBar.OnDragFinished(this.OnDragFinished));
            }
        }
        if (this.mScrollView.panel == null)
        {
            return;
        }
        Transform transform = base.transform;

        if (transform.childCount == 0)
        {
            return;
        }
        Vector3[]        worldCorners = this.mScrollView.panel.worldCorners;
        Vector3          vector       = (worldCorners[2] + worldCorners[0]) * 0.5f;
        Vector3          vector2      = this.mScrollView.currentMomentum * this.mScrollView.momentumAmount;
        Vector3          a            = NGUIMath.SpringDampen(ref vector2, 9f, 2f);
        Vector3          b            = vector - a * 0.01f;
        float            num          = float.MaxValue;
        Transform        target       = null;
        int              index        = 0;
        int              num2         = 0;
        UIGrid           component    = base.GetComponent <UIGrid>();
        List <Transform> list         = null;

        if (component != null)
        {
            list = component.GetChildList();
            int i     = 0;
            int count = list.Count;
            int num3  = 0;
            while (i < count)
            {
                Transform transform2 = list[i];
                if (transform2.gameObject.activeInHierarchy)
                {
                    float num4 = Vector3.SqrMagnitude(transform2.position - b);
                    if (num4 < num)
                    {
                        num    = num4;
                        target = transform2;
                        index  = i;
                        num2   = num3;
                    }
                    num3++;
                }
                i++;
            }
        }
        else
        {
            int j          = 0;
            int childCount = transform.childCount;
            int num5       = 0;
            while (j < childCount)
            {
                Transform child = transform.GetChild(j);
                if (child.gameObject.activeInHierarchy)
                {
                    float num6 = Vector3.SqrMagnitude(child.position - b);
                    if (num6 < num)
                    {
                        num    = num6;
                        target = child;
                        index  = j;
                        num2   = num5;
                    }
                    num5++;
                }
                j++;
            }
        }
        if (this.nextPageThreshold > 0f && UICamera.currentTouch != null && this.mCenteredObject != null && this.mCenteredObject.transform == ((list == null) ? transform.GetChild(index) : list[index]))
        {
            Vector3 point = UICamera.currentTouch.totalDelta;
            point = base.transform.rotation * point;
            UIScrollView.Movement movement = this.mScrollView.movement;
            float num7;
            if (movement != UIScrollView.Movement.Horizontal)
            {
                if (movement != UIScrollView.Movement.Vertical)
                {
                    num7 = point.magnitude;
                }
                else
                {
                    num7 = point.y;
                }
            }
            else
            {
                num7 = point.x;
            }
            if (Mathf.Abs(num7) > this.nextPageThreshold)
            {
                if (num7 > this.nextPageThreshold)
                {
                    if (list != null)
                    {
                        if (num2 > 0)
                        {
                            target = list[num2 - 1];
                        }
                        else
                        {
                            target = ((!(base.GetComponent <UIWrapContent>() == null)) ? list[list.Count - 1] : list[0]);
                        }
                    }
                    else if (num2 > 0)
                    {
                        target = transform.GetChild(num2 - 1);
                    }
                    else
                    {
                        target = ((!(base.GetComponent <UIWrapContent>() == null)) ? transform.GetChild(transform.childCount - 1) : transform.GetChild(0));
                    }
                }
                else if (num7 < -this.nextPageThreshold)
                {
                    if (list != null)
                    {
                        if (num2 < list.Count - 1)
                        {
                            target = list[num2 + 1];
                        }
                        else
                        {
                            target = ((!(base.GetComponent <UIWrapContent>() == null)) ? list[0] : list[list.Count - 1]);
                        }
                    }
                    else if (num2 < transform.childCount - 1)
                    {
                        target = transform.GetChild(num2 + 1);
                    }
                    else
                    {
                        target = ((!(base.GetComponent <UIWrapContent>() == null)) ? transform.GetChild(0) : transform.GetChild(transform.childCount - 1));
                    }
                }
            }
        }
        this.CenterOn(target, vector);
    }
Beispiel #23
0
 private void Awake()
 {
     this.mTrans = base.transform;
     this.mPanel = base.GetComponent<UIPanel>();
     if (this.mPanel.clipping == UIDrawCall.Clipping.None)
     {
         this.mPanel.clipping = UIDrawCall.Clipping.ConstrainButDontClip;
     }
     if (this.movement != UIScrollView.Movement.Custom && this.scale.sqrMagnitude > 0.001f)
     {
         if (this.scale.x == 1f && this.scale.y == 0f)
         {
             this.movement = UIScrollView.Movement.Horizontal;
         }
         else if (this.scale.x == 0f && this.scale.y == 1f)
         {
             this.movement = UIScrollView.Movement.Vertical;
         }
         else if (this.scale.x == 1f && this.scale.y == 1f)
         {
             this.movement = UIScrollView.Movement.Unrestricted;
         }
         else
         {
             this.movement = UIScrollView.Movement.Custom;
             this.customMovement.x = this.scale.x;
             this.customMovement.y = this.scale.y;
         }
         this.scale = Vector3.zero;
     }
     if (this.contentPivot == UIWidget.Pivot.TopLeft && this.relativePositionOnReset != Vector2.zero)
     {
         this.contentPivot = NGUIMath.GetPivot(new Vector2(this.relativePositionOnReset.x, 1f - this.relativePositionOnReset.y));
         this.relativePositionOnReset = Vector2.zero;
     }
 }
Beispiel #24
0
    private void UpdateScrollPosition()
    {
        if (null == _uiScrollView)
        {
            return;
        }

        if (_uiScrollView.isDragging)
        {
            if (_isFirstTouch)
            {
                _startTouchPos = _currentPos;
                _isFirstTouch  = false;
            }

            float verticalSwipeDistance   = Mathf.Abs(DeltaTouchPos.y);
            float horizontalSwipeDistance = Mathf.Abs(DeltaTouchPos.x);

            if (_swipeState == SwipeState.None)
            {
                if (verticalSwipeDistance >= TouchDragThreshold)
                {
                    _swipeState = SwipeState.UseVerticalScroll;

                    _uiScrollView.movement    = UIScrollView.Movement.Vertical;
                    _begintScrollContainerPos = _uiScrollView.transform.localPosition;
                }
                else if (horizontalSwipeDistance >= TouchDragThreshold)
                {
                    _swipeState = SwipeState.UseHorizontalSwipe;
                    SetBasicDataBeforeDragging();
                }
            }

            UpdateScrollViewScale();
        }
        else
        {
            if (_uiScrollView.movement != UIScrollView.Movement.Vertical)
            {
                _previousMovementState = _uiScrollView.movement;

                _uiScrollView.customMovement = new Vector2(1, 1);

                _uiScrollView.movement = UIScrollView.Movement.Vertical;

                if (Mathf.Abs(_currentDistance) > _thresholdDistanceToCloseCard)
                {
                    _isNeedResetToDefault = false;
                }
                else
                {
                    _isNeedResetToDefault = true;
                }
            }

            _isFirstTouch = true;

            _swipeState = SwipeState.None;

            ResetScaleToDefault();
        }
    }
    /// <summary>
    /// Whether the scroll view can move horizontally.
    /// </summary>

    public bool CanMoveHorizontally(UIScrollView.Movement movement, float customMovementX)
    {
        return(movement == UIScrollView.Movement.Horizontal ||
               movement == UIScrollView.Movement.Unrestricted ||
               (movement == UIScrollView.Movement.Custom && customMovementX != 0f));
    }
Beispiel #26
0
    static public void MoveTableItem <T>(
        List <T> scrollItems, UIScrollView.Movement moveType, IList datas, ref int minIndex, ref int maxIndex,
        ref int forwardCacheNum, bool isTopToBottom, bool isMoveForward, UITable.Direction direction) where T : TableBaseItem
    {
        T item;
        // 判断是否是 上(左)移动到下(右)
        int curIndex;
        int itemIndex;
        int sign;

        if (isTopToBottom)
        {
            curIndex  = maxIndex + 1;
            itemIndex = 0;
            sign      = 1;
        }
        else
        {
            curIndex  = minIndex - 1;
            itemIndex = scrollItems.Count - 1;
            sign      = -1;
        }
        item = scrollItems[itemIndex];

        int     targetIndex = itemIndex == 0 ? scrollItems.Count - 1 : 0;
        T       targetItem  = scrollItems[targetIndex];
        Vector3 targetPos   = targetItem.transform.localPosition;

        scrollItems.Remove(item);
        scrollItems.Insert(targetIndex, item);

        item.FillItem(datas, curIndex);
        UIWidget tmpWidget;

        if (direction == UITable.Direction.Down)
        {
            if (isTopToBottom)
            {
                tmpWidget = targetItem.GetComponent <UIWidget>();
            }
            else
            {
                tmpWidget = item.GetComponent <UIWidget>();
            }
        }
        else
        {
            if (!isTopToBottom)
            {
                tmpWidget = targetItem.GetComponent <UIWidget>();
            }
            else
            {
                tmpWidget = item.GetComponent <UIWidget>();
            }
        }

        int cellHeight = tmpWidget.GetComponent <UIWidget>().height;
        int cellWidth  = tmpWidget.GetComponent <UIWidget>().width;

        ReSetCellPostion <T>(item, moveType, targetPos, isTopToBottom, cellWidth, cellHeight, direction);


        minIndex += sign;
        maxIndex += sign;
        if (isMoveForward)
        {
            forwardCacheNum -= sign;
        }
    }
Beispiel #27
0
    static public void CreateScrollView <T>(this UIGrid grid, GameObject templateItem, IList datas, GridItemList <T> scrollItemList, UIBase parentUI)
        where T : GridBaseItem
    {
        if (scrollItemList == null)
        {
            scrollItemList = new GridItemList <T>(null, parentUI);
        }
        if (scrollItemList.RefreshGrid())
        {
            return;
        }
        if (scrollItemList.items == null)
        {
            scrollItemList.items = new List <List <T> >();
        }
        List <List <T> > scrollItems = scrollItemList.items;

        scrollItems.Clear();
        // 删除UI项目
        grid.transform.DestroyChildren();
        UIScrollView scrollView = NGUITools.FindInParents <UIScrollView>(grid.gameObject);

        if (scrollItems == null)
        {
            scrollItems = new List <List <T> >();
        }
        else
        {
            scrollItems.Clear();
        }

        int maxPerLine = grid.maxPerLine == 0 ? 1 : grid.maxPerLine;
        int itemCount;        //grid的行(列)数量
        int realItemCount;    //原本grid的行(列)数量

        itemCount     = Mathf.CeilToInt((float)datas.Count / (float)maxPerLine);
        realItemCount = itemCount;

        int     fillCount = 0;    //当前scrollView被填满的格子数
        int     cacheNum  = 3;    //多出来的缓存格子
        Vector3 lastPos   = Vector3.zero;
        UIPanel panel     = scrollView.GetComponent <UIPanel>();

        panel.onClipMove = null;
        UIScrollView.Movement moveType = scrollView.movement;
        if (moveType == UIScrollView.Movement.Vertical)
        {
            fillCount = (int)(panel.height / grid.cellHeight);
        }
        else if (moveType == UIScrollView.Movement.Horizontal)
        {
            fillCount = (int)(panel.width / grid.cellWidth);
        }
        scrollView.onMomentumMove = null;
        // 面板没被占满拖拽回滚
        if (!scrollView.disableDragIfFits)
        {
            if (itemCount <= fillCount)
            {
                lastPos = panel.transform.localPosition;
                scrollView.onMomentumMove = () => {
                    SpringPanel.Begin(panel.gameObject, lastPos, 13f).strength = 8f;
                };
            }
        }

        // 如果item数量大于填满显示面板的数量做优化
        if (itemCount >= fillCount + cacheNum)
        {
            itemCount = fillCount + cacheNum;
            int lastIndex       = 0;       //上次显示出来的第一个格子,在grid数据中的index
            int maxIndex        = itemCount - 1;
            int minIndex        = 0;
            int forwardCacheNum = 0;            //用于缓存向指定方向滑动,预加载的格子数
            // 拖拽刷新面板
            panel.onClipMove = (uiPanel) => {
                Vector3 delata   = lastPos - panel.transform.localPosition;
                float   distance = -1;
                int     index;            //当前显示出来的第一个格子,在grid数据中的index
                distance = delata.y != 0 ? delata.y : delata.x;
                // 满的时候向上滑不管它
                if (distance > 0 && moveType == UIScrollView.Movement.Vertical)
                {
                    return;
                }
                if (distance < 0 && moveType == UIScrollView.Movement.Horizontal)
                {
                    return;
                }

                distance = Mathf.Abs(distance);

                if (moveType == UIScrollView.Movement.Horizontal)
                {
                    index = Mathf.FloorToInt(distance / grid.cellWidth);
                }
                else
                {
                    index = Mathf.FloorToInt(distance / grid.cellHeight);
                }

                // 拖拽不满一个单元格
                if (index == lastIndex)
                {
                    return;
                }

                realItemCount = Mathf.CeilToInt((float)datas.Count / (float)maxPerLine);

                // 拉到底了
                if (index + itemCount > realItemCount)
                {
                    if (lastIndex + itemCount == realItemCount)
                    {
                        return;
                    }
                    else
                    {
                        index = realItemCount - itemCount;
                    }
                }
                // 重刷
                int offset = Math.Abs(index - lastIndex);
                // 判断要把最上(左)的item移动到最下(右),还是相反
                if (lastIndex < index)
                {
                    //如果有上一次的缓存数量,就清掉
                    if (forwardCacheNum > 0)
                    {
                        while (forwardCacheNum > 1)
                        {
                            //上(左)移动到下(右)
                            MoveGridItem <T>(scrollItems, moveType, datas, maxPerLine, ref minIndex, ref maxIndex, ref forwardCacheNum, true, true);
                        }
                    }
                    // 滑到底的时候,把上部缓存的那一个item移动到下部
                    if ((forwardCacheNum > 0 && index + itemCount == realItemCount))
                    {
                        //上(左)移动到下(右)
                        MoveGridItem <T>(scrollItems, moveType, datas, maxPerLine, ref minIndex, ref maxIndex, ref forwardCacheNum, true, true);
                    }

                    for (int i = 1; i <= offset; i++)
                    {
                        //上(左)移动到下(右)
                        MoveGridItem <T>(scrollItems, moveType, datas, maxPerLine, ref minIndex, ref maxIndex, ref forwardCacheNum, true, false);
                    }
                }
                else
                {
                    forwardCacheNum = forwardCacheNum - offset;
                    //缓存数量
                    while ((forwardCacheNum < cacheNum - 1 && index >= cacheNum - 1) ||
                           (forwardCacheNum < 0 && index < cacheNum - 1))
                    {
                        // 下(右)移动到上(左)
                        MoveGridItem <T>(scrollItems, moveType, datas, maxPerLine, ref minIndex, ref maxIndex, ref forwardCacheNum, false, true);
                    }
                }
                lastIndex = index;
            };

            //如果这个函数BUG了,请把下面解开下面代码的封印,强行不BUG

            //scrollView.onMomentumMove = () => { };
            //scrollView.onMomentumMove = () => {
            //	for (int i = lastIndex; i < itemCount + lastIndex; i++) {
            //		for (int j = 0; j < scrollItems[i - lastIndex].Count; j++) {
            //			scrollItems[i - lastIndex][j].FillItem(datas, i * maxPerLine + j);
            //		}
            //	}
            //};
        }

        // 添加能填满UI数量的button
        for (int i = 0; i < itemCount; i++)
        {
            for (int j = 0; j < maxPerLine; j++)
            {
                if (i * maxPerLine + j >= datas.Count)
                {
                    break;
                }
                GameObject go = NGUITools.AddChild(grid.gameObject, templateItem);
                go.SetActive(true);
                T item = go.AddComponent <T>();
                item.grid      = grid;
                item.itemCount = itemCount;
                item.parentUI  = parentUI;
                if (scrollItems.Count - 1 < i)
                {
                    scrollItems.Add(new List <T>());
                }
                scrollItems[i].Add(item);
                item.FindItem();
                item.FillItem(datas, i * maxPerLine + j);
            }
        }

        scrollItemList.itemCount    = (fillCount + cacheNum) * maxPerLine;
        scrollItemList.grid         = grid;
        scrollItemList.itemTemplate = templateItem;
        scrollItemList.datas        = datas;
        scrollItemList.panel        = panel;
        lastPos = panel.transform.localPosition;

        grid.Reposition();
    }
Beispiel #28
0
    static public void CreateScrollView <T>(this UITable table, GameObject templateItem, IList datas, TableItemList <T> scrollItemList, UIBase parentUI)
        where T : TableBaseItem
    {
        if (scrollItemList == null)
        {
            scrollItemList = new TableItemList <T>(null, parentUI);
        }
        if (scrollItemList.items == null)
        {
            scrollItemList.items = new List <T>();
        }
        List <T> scrollItems = scrollItemList.items;

        scrollItems.Clear();
        UIScrollView scrollView = NGUITools.FindInParents <UIScrollView>(table.gameObject);

        UIScrollView.Movement moveType  = table.columns == 0 ? UIScrollView.Movement.Horizontal : UIScrollView.Movement.Vertical;
        UITable.Direction     direction = table.direction;
        int      itemCount  = datas.Count;  //grid的行(列)数量
        UIWidget tmpWidget  = templateItem.GetComponent <UIWidget>();
        int      cellHeight = tmpWidget.GetComponent <UIWidget>().height;
        int      cellWidth  = tmpWidget.GetComponent <UIWidget>().width;
        int      fillCount  = 0;  //当前scrollView被填满的格子数
        int      cacheNum   = 3;  //多出来的缓存格子
        Vector3  lastPos    = Vector3.zero;
        UIPanel  panel      = scrollView.GetComponent <UIPanel>();

        panel.onClipMove = null;
        // 删除UI项目
        table.transform.DestroyChildren();
        if (moveType == UIScrollView.Movement.Vertical)
        {
            fillCount = Mathf.CeilToInt(panel.height / cellHeight);
        }
        else if (moveType == UIScrollView.Movement.Horizontal)
        {
            fillCount = Mathf.CeilToInt(panel.width / cellWidth);
        }

        // 如果item数量大于填满显示面板的数量做优化
        if (itemCount >= fillCount + cacheNum)
        {
            itemCount = fillCount + cacheNum;
            int lastIndex       = 0;       //上次显示出来的第一个格子,在grid数据中的index
            int maxIndex        = itemCount - 1;
            int minIndex        = 0;
            int forwardCacheNum = 0;            //用于缓存向指定方向滑动,预加载的格子数
            // 拖拽刷新面板
            panel.onClipMove = (uiPanel) => {
                Vector3 delata          = lastPos - panel.transform.localPosition;
                float   distance        = -1;
                int     index           = 0;  //当前显示出来的第一个格子,在grid数据中的index
                float   curItemDistance = 0;

                distance = delata.y != 0 ? delata.y : delata.x;

                // 满的时候向上滑不管它
                if (distance > 0 && direction == UITable.Direction.Down)
                {
                    return;
                }
                if (distance < 0 && direction == UITable.Direction.Up)
                {
                    return;
                }
                distance = Mathf.Abs(distance);

                curItemDistance = CalItemDistance(moveType, scrollItems[scrollItems.Count - 1].transform.localPosition);
                if (curItemDistance < distance)
                {
                    index = Mathf.Min(scrollItems[scrollItems.Count - 1].index + 1, datas.Count - 1);
                }
                else
                {
                    for (int i = 0; i < scrollItems.Count; i++)
                    {
                        curItemDistance = CalItemDistance(moveType, scrollItems[i].transform.localPosition);
                        if (curItemDistance >= distance)
                        {
                            index = Mathf.Max(scrollItems[i].index - 1, 0);
                            break;
                        }
                    }
                }
                // 拖拽不满一个单元格
                if (index == lastIndex)
                {
                    return;
                }
                // 拉到底了
                if (index + itemCount > datas.Count)
                {
                    if (lastIndex + itemCount == datas.Count)
                    {
                        return;
                    }
                    else
                    {
                        index = datas.Count - itemCount;
                    }
                }

                // 重刷
                int offset = Math.Abs(index - lastIndex);

                // 判断要把最上(左)的item移动到最下(右),还是相反
                if (lastIndex < index)
                {
                    //如果有上一次的缓存数量,就清掉
                    if (forwardCacheNum > 0)
                    {
                        while (forwardCacheNum > 1)
                        {
                            //上(左)移动到下(右)
                            MoveTableItem <T>(scrollItems, moveType, datas, ref minIndex, ref maxIndex, ref forwardCacheNum, true, true, direction);
                        }
                    }
                    // 滑到底的时候,把上部缓存的那一个item移动到下部
                    if ((forwardCacheNum > 0 && index + itemCount == datas.Count))
                    {
                        //上(左)移动到下(右)
                        MoveTableItem <T>(scrollItems, moveType, datas, ref minIndex, ref maxIndex, ref forwardCacheNum, true, true, direction);
                    }

                    for (int i = 1; i <= offset; i++)
                    {
                        //上(左)移动到下(右)
                        MoveTableItem <T>(scrollItems, moveType, datas, ref minIndex, ref maxIndex, ref forwardCacheNum, true, false, direction);
                    }
                }
                else
                {
                    forwardCacheNum = forwardCacheNum - offset;
                    //缓存数量
                    int targetNum = direction == UITable.Direction.Down ? cacheNum - 1 : cacheNum - 2;
                    while ((forwardCacheNum < targetNum && index >= cacheNum - 1) || (forwardCacheNum < 0 && index < cacheNum - 1))
                    {
                        // 下(右)移动到上(左)
                        MoveTableItem <T>(scrollItems, moveType, datas, ref minIndex, ref maxIndex, ref forwardCacheNum, false, true, direction);
                    }
                }
                lastIndex = index;
            };
        }

        // 添加能填满UI数量的button
        for (int i = 0; i < itemCount; i++)
        {
            GameObject go = NGUITools.AddChild(table.gameObject, templateItem);
            go.SetActive(true);
            T item = go.AddComponent <T>();
            item.table     = table;
            item.itemCount = itemCount;
            item.parentUI  = parentUI;
            scrollItems.Add(item);
            item.FindItem();
            scrollItems[i].FillItem(datas, i);
        }
        scrollItemList.itemCount    = fillCount + cacheNum;
        scrollItemList.table        = table;
        scrollItemList.itemTemplate = templateItem;
        scrollItemList.datas        = datas;
        lastPos = panel.transform.localPosition;

        table.Reposition();
    }
    /// <summary>
    /// Whether the scroll view can move vertically.
    /// </summary>

    public bool CanMoveVertically(UIScrollView.Movement movement, float customMovementY)
    {
        return(movement == UIScrollView.Movement.Vertical ||
               movement == UIScrollView.Movement.Unrestricted ||
               (movement == UIScrollView.Movement.Custom && customMovementY != 0f));
    }
Beispiel #30
0
    public void Recenter()
    {
        if (this.mScrollView == null)
        {
            this.mScrollView = NGUITools.FindInParents <UIScrollView>(base.gameObject);
            if (this.mScrollView == null)
            {
                LogSystem.LogWarning(new object[]
                {
                    base.GetType(),
                    " requires ",
                    typeof(UIScrollView),
                    " on a parent object in order to work",
                    this
                });
                base.enabled = false;
                return;
            }
            this.mScrollView.onDragFinished = new UIScrollView.OnDragFinished(this.OnDragFinished);
            if (this.mScrollView.horizontalScrollBar != null)
            {
                this.mScrollView.horizontalScrollBar.onDragFinished = new UIProgressBar.OnDragFinished(this.OnDragFinished);
            }
            if (this.mScrollView.verticalScrollBar != null)
            {
                this.mScrollView.verticalScrollBar.onDragFinished = new UIProgressBar.OnDragFinished(this.OnDragFinished);
            }
        }
        if (this.mScrollView.panel == null)
        {
            return;
        }
        Vector3[] worldCorners = this.mScrollView.panel.worldCorners;
        Vector3   vector       = (worldCorners[2] + worldCorners[0]) * 0.5f;
        Vector3   b            = vector - this.mScrollView.currentMomentum * (this.mScrollView.momentumAmount * 0.1f);

        this.mScrollView.currentMomentum = Vector3.zero;
        float     num        = 3.40282347E+38f;
        Transform target     = null;
        Transform transform  = base.transform;
        int       num2       = 0;
        int       i          = 0;
        int       childCount = transform.childCount;

        while (i < childCount)
        {
            Transform child = transform.GetChild(i);
            float     num3  = Vector3.SqrMagnitude(child.position - b);
            if (num3 < num)
            {
                num    = num3;
                target = child;
                num2   = i;
            }
            i++;
        }
        if (this.nextPageThreshold > 0f && UICamera.currentTouch != null && this.mCenteredObject != null && this.mCenteredObject.transform == transform.GetChild(num2))
        {
            Vector2 totalDelta             = UICamera.currentTouch.totalDelta;
            UIScrollView.Movement movement = this.mScrollView.movement;
            float num4;
            if (movement != UIScrollView.Movement.Horizontal)
            {
                if (movement != UIScrollView.Movement.Vertical)
                {
                    num4 = totalDelta.magnitude;
                }
                else
                {
                    num4 = totalDelta.y;
                }
            }
            else
            {
                num4 = totalDelta.x;
            }
            if (num4 > this.nextPageThreshold)
            {
                if (num2 > 0)
                {
                    target = transform.GetChild(num2 - 1);
                }
            }
            else if (num4 < -this.nextPageThreshold && num2 < transform.childCount - 1)
            {
                target = transform.GetChild(num2 + 1);
            }
        }
        this.CenterOn(target, vector);
    }
Beispiel #31
0
	// Use this for initialization
	void Start ()
	{
		_swipeState = SwipeState.None;

		_isFirstTouch = true;

		_uiScrollView = GetComponentInChildren<UIScrollView>();

		if (null == _uiScrollView)
		{
			throw new MissingComponentException("TestSwipeScripts.Start - can't get UIScrollView component for _uiScrollView");
		}

		_startingMomentum = _uiScrollView.momentumAmount;
		_uiScrollView.panel.clipping = UIDrawCall.Clipping.None;

		_panel = _uiScrollView.GetComponent<UIPanel>();

		if (null == _panel)
		{
			throw new MissingComponentException("TestSwipeScripts.Start - can't get UIPanel component for _panel");
		}

		DynamicScrollView2 dynamicScrollView = FindObjectOfType<DynamicScrollView2>();

		if (null == dynamicScrollView)
		{
			throw new NullReferenceException("TestSwipeScripts.Start - can't find DynamicScrollView object");
		}

		_thresholdDistanceToCloseCard = dynamicScrollView.closeDetailCardThresholdHorizontal;
		_thresholdDistanceVerticalToCloseCard = dynamicScrollView.closeDetailCardThreshold;


		ScrollViewContainer = NGUITools.FindInParents<UIWidget>(_uiScrollView.transform);

		if (null == ScrollViewContainer)
		{
			throw new MissingComponentException("TestSwipeScripts.Start - can't get UIWidget component for _scrollViewContainer");
		}

		_currentScale = Vector3.one;

		_previousMovementState = UIScrollView.Movement.Custom;

	}
Beispiel #32
0
    /// <summary>
    /// 注意:能不用这个接口,尽量不用这个接口(聊天之类的可能用到,其他的尽量不用)
    /// 支持大量item滑动显示的 table创建,左右 上下箭头有效,有对象池
    /// FillItem的时候要重置item,(注销点击,一些图片显示的重置)
    /// 每一次调用这个函数都会把所有的子节入池,然后出池使用
    /// 获取item使用TableItemList,直接用数据索引scrollItemList[index]可以范围到对应的item,为空说明没被绘制
    /// </summary>
    /// <returns></returns>
    static public void CreateScrollView <T>(this UITable table, GameObject templateItem, IList datas, TableItemList <T> scrollItemList, MonoBehaviour parentUI)
        where T : TableBaseItem, new()
    {
        if (scrollItemList == null)
        {
            scrollItemList = new TableItemList <T>(null, parentUI);
        }

        UIScrollView scrollView = NGUITools.FindInParents <UIScrollView>(table.gameObject);

        //scrollView.StopDragMove();
        UIScrollView.Movement moveType  = table.columns == 0 ? UIScrollView.Movement.Horizontal : UIScrollView.Movement.Vertical;
        UITable.Direction     direction = table.direction;
        int    itemCount = datas.Count;//grid的行(列)数量
        Bounds b         = NGUIMath.CalculateRelativeWidgetBounds(templateItem.transform, true);

        Vector2 padding    = table.padding;
        int     cellHeight = (int)b.size.y + (int)padding.y;
        int     cellWidth  = (int)b.size.x;
        int     fillCount  = 0; //当前scrollView被填满的格子数
        int     cacheNum   = 3; //多出来的缓存格子
        Vector3 lastPos    = Vector3.zero;
        UIPanel panel      = scrollView.GetComponent <UIPanel>();

        panel.onClipMove = null;
        if (moveType == UIScrollView.Movement.Vertical)
        {
            fillCount = Mathf.CeilToInt(panel.height / cellHeight);
        }
        else if (moveType == UIScrollView.Movement.Horizontal)
        {
            fillCount = Mathf.CeilToInt(panel.width / cellWidth);
        }
        scrollItemList.ResetPos();
        scrollItemList.table      = table;
        scrollItemList.panel      = panel;
        scrollItemList.scrollView = scrollView;
        scrollItemList.CreateItemPool(templateItem, fillCount + cacheNum);
        List <T> scrollItems = scrollItemList.items;

        if (scrollItems == null)
        {
            scrollItems          = new List <T>();
            scrollItemList.items = scrollItems;
        }
        else
        {
            scrollItemList.StoreAllItem();
        }

        // 如果item数量大于填满显示面板的数量做优化
        if (itemCount >= fillCount + cacheNum)
        {
            itemCount = fillCount + cacheNum;
            scrollItemList.lastIndex = 0; //上次显示出来的第一个格子,在grid数据中的index
            int maxIndex        = itemCount - 1;
            int minIndex        = 0;
            int forwardCacheNum = 0; //用于缓存向指定方向滑动,预加载的格子数
                                     // 拖拽刷新面板
            panel.onClipMove = (uiPanel) => {
                Vector3 delata          = lastPos - panel.transform.localPosition;
                float   distance        = -1;
                int     index           = 0;//当前显示出来的第一个格子,在grid数据中的index
                float   curItemDistance = 0;

                distance = delata.y != 0 ? delata.y : delata.x;

                // 满的时候向上滑不管它
                if (distance > 0 && direction == UITable.Direction.Down)
                {
                    return;
                }
                if (distance < 0 && direction == UITable.Direction.Up)
                {
                    return;
                }
                distance = Mathf.Abs(distance);

                curItemDistance = CalItemDistance(moveType, scrollItems[scrollItems.Count - 1].transform.localPosition);
                if (curItemDistance < distance)
                {
                    index = Mathf.Min(scrollItems[scrollItems.Count - 1].index + 1, datas.Count - 1);
                }
                else
                {
                    for (int i = 0; i < scrollItems.Count; i++)
                    {
                        Vector3 tmpVec = scrollItems[i].transform.localPosition;
                        curItemDistance = CalItemDistance(moveType, tmpVec);
                        if (curItemDistance >= distance)
                        {
                            index = Mathf.Max(scrollItems[i].index - 1, 0);
                            break;
                        }
                    }
                }
                // 拖拽不满一个单元格
                if (index == scrollItemList.lastIndex)
                {
                    return;
                }
                // 拉到底了
                if (index + itemCount > datas.Count)
                {
                    if (scrollItemList.lastIndex + itemCount == datas.Count)
                    {
                        return;
                    }
                    else
                    {
                        index = datas.Count - itemCount;
                    }
                }

                // 重刷
                int offset = Math.Abs(index - scrollItemList.lastIndex);

                // 判断要把最上(左)的item移动到最下(右),还是相反
                if (scrollItemList.lastIndex < index)
                {
                    //如果有上一次的缓存数量,就清掉
                    if (forwardCacheNum > 0)
                    {
                        while (forwardCacheNum > 1)
                        {
                            //上(左)移动到下(右)
                            MoveTableItem <T>(scrollItems, moveType, datas, ref minIndex, ref maxIndex, ref forwardCacheNum, true, true, direction, padding);
                        }
                    }
                    // 滑到底的时候,把上部缓存的那一个item移动到下部
                    if ((forwardCacheNum > 0 && index + itemCount == datas.Count))
                    {
                        //上(左)移动到下(右)
                        MoveTableItem <T>(scrollItems, moveType, datas, ref minIndex, ref maxIndex, ref forwardCacheNum, true, true, direction, padding);
                    }

                    for (int i = 1; i <= offset; i++)
                    {
                        //上(左)移动到下(右)
                        MoveTableItem <T>(scrollItems, moveType, datas, ref minIndex, ref maxIndex, ref forwardCacheNum, true, false, direction, padding);
                    }
                }
                else
                {
                    forwardCacheNum = forwardCacheNum - offset;
                    //缓存数量
                    int targetNum = direction == UITable.Direction.Down ? cacheNum - 1 : cacheNum - 2;
                    while ((forwardCacheNum < targetNum && index >= targetNum) || (forwardCacheNum < 0 && index < targetNum))
                    {
                        // 下(右)移动到上(左)
                        MoveTableItem <T>(scrollItems, moveType, datas, ref minIndex, ref maxIndex, ref forwardCacheNum, false, true, direction, padding);
                    }
                }
                scrollItemList.lastIndex = index;
            };
        }

        // 添加能填满UI数量的button
        for (int i = 0; i < itemCount; i++)
        {
            T item = scrollItemList.GetGridItem();
            item.transform.parent = table.transform;
            item.gameObject.SetActive(true);
            item.table     = table;
            item.itemCount = itemCount;
            item.parentUI  = parentUI;
            scrollItems.Add(item);
            item.FillItem(datas, i);
        }
        scrollItemList.datas     = datas;
        scrollItemList.itemCount = fillCount + cacheNum;
        lastPos = panel.transform.localPosition;

        if (scrollView != null && !scrollView.disableDragIfFits)
        {
            Bounds tableBound;
            Bounds itemBound;

            moveType = scrollView.movement;
            scrollView.onMomentumMove = null;
            scrollView.onDragFinished = null;
            Vector3 lastPosX = panel.transform.localPosition;
            scrollView.onMomentumMove += () => {
                if (moveType == UIScrollView.Movement.Vertical)
                {
                    tableBound = NGUIMath.CalculateRelativeWidgetBounds(table.transform, false);
                    itemBound  = NGUIMath.CalculateRelativeWidgetBounds(templateItem.transform, false);
                    if (tableBound.size.y + itemBound.size.y * 0.5f < panel.height)
                    {
                        SpringPanel.Begin(panel.gameObject, lastPosX, 13f).strength = 8f;
                    }
                }
            };
            scrollView.onDragFinished += () => {
                if (moveType == UIScrollView.Movement.Vertical)
                {
                    tableBound = NGUIMath.CalculateRelativeWidgetBounds(table.transform, false);
                    itemBound  = NGUIMath.CalculateRelativeWidgetBounds(templateItem.transform, false);
                    if (tableBound.size.y + itemBound.size.y * 0.5f < panel.height)
                    {
                        SpringPanel.Begin(panel.gameObject, lastPosX, 13f).strength = 8f;
                    }
                }
            };
        }
        scrollItemList.StoreQueuePoolItem();
        table.Reposition();
    }
Beispiel #33
0
	private void UpdateScrollPosition()
	{
		if (null == _uiScrollView)
			return;

		if (_uiScrollView.isDragging)
		{
			if (_isFirstTouch)
			{
				_startTouchPos = _currentPos;
				_isFirstTouch = false;
			}

			float verticalSwipeDistance =  Mathf.Abs(DeltaTouchPos.y);
			float horizontalSwipeDistance =  Mathf.Abs(DeltaTouchPos.x);

			if (_swipeState == SwipeState.None)
			{
				if (verticalSwipeDistance >= TouchDragThreshold)
				{
					_swipeState = SwipeState.UseVerticalScroll;

					_uiScrollView.movement = UIScrollView.Movement.Vertical;
					_begintScrollContainerPos = _uiScrollView.transform.localPosition;
				}
				else if (horizontalSwipeDistance >= TouchDragThreshold)
				{
					_swipeState = SwipeState.UseHorizontalSwipe;
					SetBasicDataBeforeDragging();
				}
			}

			UpdateScrollViewScale();
		}
		else
		{
			if (_uiScrollView.movement != UIScrollView.Movement.Vertical)
			{
				_previousMovementState = _uiScrollView.movement;

				_uiScrollView.customMovement = new Vector2(1, 1);

				_uiScrollView.movement = UIScrollView.Movement.Vertical;

				if (Mathf.Abs(_currentDistance) > _thresholdDistanceToCloseCard )
				{
					_isNeedResetToDefault = false;
				}
				else
				{
					_isNeedResetToDefault = true;
				}

			}

			_isFirstTouch = true;

			_swipeState = SwipeState.None;

			ResetScaleToDefault();
		}
	}