void Start() { if (scrollView == null) { scrollView = NGUITools.FindInParents <UILoopScrollView>(gameObject); } }
protected override void InitWindowOnAwake() { loopScrollView = MonoExtendUtil.FindDeepChild <UILoopScrollView>(this.gameObject, "DynamicPanel/ScorePanel"); GameObject backBtn = MonoExtendUtil.FindDeepChild(this.gameObject, "DynamicPanel/BackBtn").gameObject; loopScrollView.onContentUpdate = OnContentUpdate; loopScrollView.onContentClick = OnContentClick; UIEventListener.Get(backBtn).onClick = OnBackBtnClick; }
public static bool IsDragScrollViewBottom(GameObject go) { UILoopScrollView loopScrollView = go.GetComponent <UILoopScrollView>(); if (loopScrollView == null) { return(false); } return(loopScrollView.IsDragScrollViewBottom()); }
public static void CleanScrollViewDatas(GameObject go) { if (go == null) { return; } UILoopScrollView loopScrollView = go.GetComponent <UILoopScrollView>(); if (loopScrollView == null) { return; } loopScrollView.ClearDatas(); }
public static void AddScrollViewData(GameObject go, object data) { if (go == null) { return; } UILoopScrollView loopScrollView = go.GetComponent <UILoopScrollView>(); if (loopScrollView == null) { return; } loopScrollView.AddData(data); }
public static void SetScrollViewData(GameObject go, LuaTable data) { if (go == null) { return; } UILoopScrollView loopScrollView = go.GetComponent <UILoopScrollView>(); if (loopScrollView == null) { return; } loopScrollView.SetData(data); }
public static void AddScrollViewItemClick(GameObject go, LuaFunction luaFunc) { if (go == null || luaFunc == null) { return; } UILoopScrollView loopScrollView = go.GetComponent <UILoopScrollView>(); if (loopScrollView == null) { return; } loopScrollView.onContentClick = delegate(GameObject scrollView, GameObject item, object data) { luaFunc.Call <GameObject, GameObject, object>(scrollView, item, data); }; }
/// <summary> /// Wrap all content, repositioning all children as needed. /// </summary> public virtual void WrapContent() { float extents = 0; if (!mHorizontal) { extents = rowNum * cellHeight * 0.5f; } else { extents = colNum * cellWidth * 0.5f; } //Debug.Log("WrapContent extents===" + extents); Vector3[] corners = mPanel.worldCorners; for (int i = 0; i < 4; ++i) { Vector3 v = corners[i]; v = mTrans.InverseTransformPoint(v); corners[i] = v; } Vector3 center = Vector3.Lerp(corners[0], corners[2], 0.5f); bool allWithinRange = true; float ext2 = extents * 2f; int minIdx = minNum; int maxIdx = -1 * (maxNum - 1); // 判断是否需要循环复用 bool canWarp = true; UILoopScrollView loopSW = mScroll as UILoopScrollView; if (maxNum <= loopSW.maxGridNum) { canWarp = false; } // 水平滚动 if (mHorizontal) { float min = corners[0].x - cellWidth; float max = corners[2].x + cellWidth; for (int i = 0, imax = mChildren.Count; i < imax; ++i) { Transform t = mChildren[i]; float distance = t.localPosition.x - center.x; // 水平向左滑动,左边补在后边 if (distance < -extents) { Vector3 pos = t.localPosition; pos.x += ext2; distance = pos.x - center.x; int row = Mathf.Abs(Mathf.RoundToInt(pos.y / cellHeight)); int col = Mathf.RoundToInt(pos.x / cellWidth); int realIndex = row + col * rowNum; if (minNum == maxNum || ((realIndex >= minIdx && realIndex <= Math.Abs(maxIdx)) && canWarp)) { //Debug.Log("Move Horizontal left row====" + row + " col====" + col + " realIndex===" + realIndex); t.localPosition = pos; UpdateItem(t, realIndex); } else { allWithinRange = false; } } else if (distance > extents) // 水平向后滑动, 右边补在左边 { Vector3 pos = t.localPosition; pos.x -= ext2; distance = pos.x - center.x; int row = Mathf.Abs(Mathf.RoundToInt(pos.y / cellHeight)); int col = Mathf.RoundToInt(pos.x / cellWidth); int realIndex = row + col * rowNum; if (minNum == maxNum || ((realIndex >= minIdx && realIndex <= Math.Abs(maxIdx)) && canWarp)) { //Debug.Log("Move Horizontal right row====" + row + " col====" + col + " realIndex===" + realIndex); t.localPosition = pos; UpdateItem(t, realIndex); } else { allWithinRange = false; } } else if (mFirstTime) { UpdateItem(t, i); } if (cullContent) { distance += mPanel.clipOffset.x - mTrans.localPosition.x; if (!UICamera.IsPressed(t.gameObject)) { NGUITools.SetActive(t.gameObject, (distance > min && distance < max), false); } } } } else // 垂直滚动 { float min = corners[0].y - cellHeight; float max = corners[2].y + cellHeight; for (int i = 0, imax = mChildren.Count; i < imax; ++i) { Transform t = mChildren[i]; float distance = t.localPosition.y - center.y; if (distance < -extents) // 垂直向下滑动, 下面的挂在上面 { Vector3 pos = t.localPosition; pos.y += ext2; distance = pos.y - center.y; int realIndex = Mathf.RoundToInt(pos.y / cellHeight); if (minNum == maxNum || ((maxIdx <= realIndex && realIndex <= minIdx) && canWarp)) { int row = Mathf.Abs(Mathf.RoundToInt(pos.y / cellHeight)); int col = Mathf.RoundToInt(pos.x / cellWidth); realIndex = row * colNum + col; //Debug.Log("Move vertical down row====" + row + " col====" + col + " realIndex===" + realIndex); t.localPosition = pos; UpdateItem(t, realIndex); } else { allWithinRange = false; } } else if (distance > extents) // 垂直向上滑动, 上面的排在下面 { Vector3 pos = t.localPosition; pos.y -= ext2; distance = pos.y - center.y; int row = Mathf.Abs(Mathf.RoundToInt(pos.y / cellHeight)); int col = Mathf.RoundToInt(pos.x / cellWidth); int realIndex = row * colNum + col; if (minNum == maxNum || ((realIndex >= minIdx && realIndex <= Math.Abs(maxIdx)) && canWarp)) { //Debug.Log("Move vertical up row====" + row + " col====" + col + " realIndex===" + realIndex); t.localPosition = pos; UpdateItem(t, realIndex); } else { allWithinRange = false; } } else if (mFirstTime) { UpdateItem(t, i); } if (cullContent) { distance += mPanel.clipOffset.y - mTrans.localPosition.y; if (!UICamera.IsPressed(t.gameObject)) { bool isShow = distance > min && distance < max; NGUITools.SetActive(t.gameObject, isShow, false); } } } } mScroll.restrictWithinPanel = !allWithinRange; //MSLog.LogError("____ mScroll.restrictWithinPanel = " + mScroll.restrictWithinPanel.ToString()); mScroll.InvalidateBounds(); }