private void WrapMatrix() { Vector3 center = Vector3.Lerp(Corners[0], Corners[2], 0.5f); for (int i = 0; i < TransChildCount; i++) { Transform child = Children[i]; if (child != null) { float min = 0, max = 0, distance = 0; if (arrangement == Arrangement.MatrixHorizontal) { min = Corners[0].x - cellWidth; max = Corners[2].x + cellWidth; distance = child.localPosition.x - center.x; distance += mPanel.clipOffset.x - transform.localPosition.x; } else if (arrangement == Arrangement.MatrixVertical) { min = Corners[0].y - cellHeight; max = Corners[2].y + cellHeight; distance = child.localPosition.y - center.y; distance += Panel.clipOffset.y - transform.localPosition.y; } if (!UICamera.IsPressed(child.gameObject)) { child.gameObject.SetActive(distance > min && distance < max); } } } }
static int IsPressed(IntPtr L) { LuaScriptMgr.CheckArgsCount(L, 1); GameObject arg0 = (GameObject)LuaScriptMgr.GetUnityObject(L, 1, typeof(GameObject)); bool o = UICamera.IsPressed(arg0); LuaScriptMgr.Push(L, o); return(1); }
private void WrapContent() { Vector3[] worldCorners = this.mPanel.worldCorners; for (int i = 0; i < 4; i++) { Vector3 vector = worldCorners[i]; vector = this.mTrans.InverseTransformPoint(vector); worldCorners[i] = vector; } Vector3 vector2 = Vector3.Lerp(worldCorners[0], worldCorners[2], 0.5f); if (this.mHorizontal) { int j = 0; int count = this.mChildren.Count; while (j < count) { Transform transform = this.mChildren[j]; float num = transform.localPosition.x - vector2.x; float num2 = worldCorners[0].x - 100f; float num3 = worldCorners[2].x + 100f; num += this.mPanel.clipOffset.x - this.mTrans.localPosition.x; if (!UICamera.IsPressed(transform.gameObject)) { NGUITools.SetActive(transform.gameObject, num > num2 && num < num3, false); } j++; } } else { int k = 0; int count2 = this.mChildren.Count; while (k < count2) { Transform transform2 = this.mChildren[k]; float num4 = transform2.localPosition.y - vector2.y; float num5 = worldCorners[0].y - 100f; float num6 = worldCorners[2].y + 100f; num4 += this.mPanel.clipOffset.y - this.mTrans.localPosition.y; if (!UICamera.IsPressed(transform2.gameObject)) { bool activeSelf = transform2.gameObject.activeSelf; bool flag = num4 > num5 && num4 < num6; if (activeSelf != flag) { NGUITools.SetActive(transform2.gameObject, flag, false); } } k++; } } }
//18.09.27 //wrap content 에서 꺼지고 켜지는 object 자체의 pressed 상태만 원래 확인해서 press 되있으면 //끄는거를 막았었는데 이걸 추가함으로써 그 child 중에 press 되있는게 있으면 꺼지지 않게 한다 bool CheckChildrenPressed(GameObject go) { BoxCollider[] childrenWithColliders = go.GetComponentsInChildren <BoxCollider>(); for (int i = 0; i < childrenWithColliders.Length; i++) { if (UICamera.IsPressed(childrenWithColliders[i].gameObject)) { return(true); } } return(false); }
void WrapContent() { 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); if (mHorizontal) //横向 { for (int i = 0, imax = mChildren.Count; i < imax; ++i) { Transform t = mChildren[i]; float distance = t.localPosition.x - center.x; float min = corners[0].x - 100; float max = corners[2].x + 100; distance += mPanel.clipOffset.x - mTrans.localPosition.x; if (!UICamera.IsPressed(t.gameObject)) { NGUITools.SetActive(t.gameObject, (distance > min && distance < max), false); } } } else //竖向 { for (int i = 0, imax = mChildren.Count; i < imax; ++i) { Transform t = mChildren[i]; float distance = t.localPosition.y - center.y; float min = corners[0].y - 100; float max = corners[2].y + 100; distance += mPanel.clipOffset.y - mTrans.localPosition.y; if (!UICamera.IsPressed(t.gameObject)) { bool active = t.gameObject.activeSelf; bool willactive = distance > min && distance < max; if (active == willactive) { continue; } NGUITools.SetActive(t.gameObject, willactive, false); } } } }
public void Blink() { if (scrollView.panel == null) { return; } Vector3[] corners = scrollView.panel.worldCorners; for (int i = 0; i < 4; i++) { Vector3 v = corners[i]; v = transform.InverseTransformPoint(v); corners[i] = v; } Vector3 center = Vector3.Lerp(corners[0], corners[2], 0.5f); for (int i = 0; i < transform.childCount; i++) { Transform t = transform.GetChild(i); if (UICamera.IsPressed(t.gameObject) == true) { continue; } Bounds b; UIWidget widget = t.GetComponent <UIWidget>(); if (widget == null) { b = NGUIMath.CalculateRelativeWidgetBounds(t); } else { b = new Bounds(Vector3.zero, new Vector3(widget.width, widget.height)); } float minX = corners[0].x - b.extents.x; float minY = corners[0].y - b.extents.y; float maxX = corners[2].x + b.extents.x; float maxY = corners[2].y + b.extents.y; float distanceX = t.localPosition.x - center.x + scrollView.panel.clipOffset.x - transform.localPosition.x; float distanceY = t.localPosition.y - center.y + scrollView.panel.clipOffset.y - transform.localPosition.y; bool active = (distanceX > minX && distanceX < maxX) && (distanceY > minY && distanceY < maxY); NGUITools.SetActive(t.gameObject, active, false); } }
public void WrapContent() { Vector3[] worldCorners = this.mPanel.worldCorners; for (int i = 0; i < 4; i++) { Vector3 vector = worldCorners[i]; vector = this.mTrans.InverseTransformPoint(vector); worldCorners[i] = vector; } Vector3 vector2 = Vector3.Lerp(worldCorners[0], worldCorners[2], 0.5f); if (this.mHorizontal) { float num = worldCorners[0].x - (float)this.itemSize; float num2 = worldCorners[2].x + (float)this.itemSize; for (int j = 0; j < this.mChildren.size; j++) { Transform transform = this.mChildren[j]; float num3 = transform.localPosition.x - vector2.x; if (this.cullContent) { num3 += this.mPanel.clipOffset.x - this.mTrans.localPosition.x; if (!UICamera.IsPressed(transform.gameObject)) { NGUITools.SetActive(transform.gameObject, num3 > num && num3 < num2, false); } } } } else { float num4 = worldCorners[0].y - (float)this.itemSize; float num5 = worldCorners[2].y + (float)this.itemSize; for (int k = 0; k < this.mChildren.size; k++) { Transform transform2 = this.mChildren[k]; float num6 = transform2.localPosition.y - vector2.y; if (this.cullContent) { num6 += this.mPanel.clipOffset.y - this.mTrans.localPosition.y; if (!UICamera.IsPressed(transform2.gameObject)) { NGUITools.SetActive(transform2.gameObject, num6 > num4 && num6 < num5, false); } } } } }
public virtual void WrapContent() { float num = (float)(this.itemSize * this.mChildren.Count) * 0.5f; Vector3[] worldCorners = this.mPanel.worldCorners; for (int i = 0; i < 4; i++) { Vector3 vector = worldCorners[i]; vector = this.mTrans.InverseTransformPoint(vector); worldCorners[i] = vector; } Vector3 vector2 = Vector3.Lerp(worldCorners[0], worldCorners[2], 0.5f); bool flag = true; float num2 = num * 2f; if (this.mHorizontal) { float num3 = worldCorners[0].x - (float)this.itemSize; float num4 = worldCorners[2].x + (float)this.itemSize; int j = 0; int count = this.mChildren.Count; while (j < count) { Transform transform = this.mChildren[j]; float num5 = transform.localPosition.x - vector2.x; if (num5 < -num) { Vector3 localPosition = transform.localPosition; localPosition.x += num2; num5 = localPosition.x - vector2.x; int num6 = Mathf.RoundToInt(localPosition.x / (float)this.itemSize); if (this.minIndex == this.maxIndex || (this.minIndex <= num6 && num6 <= this.maxIndex)) { transform.localPosition = localPosition; this.UpdateItem(transform, j); } else { flag = false; } } else if (num5 > num) { Vector3 localPosition2 = transform.localPosition; localPosition2.x -= num2; num5 = localPosition2.x - vector2.x; int num7 = Mathf.RoundToInt(localPosition2.x / (float)this.itemSize); if (this.minIndex == this.maxIndex || (this.minIndex <= num7 && num7 <= this.maxIndex)) { transform.localPosition = localPosition2; this.UpdateItem(transform, j); } else { flag = false; } } else if (this.mFirstTime) { this.UpdateItem(transform, j); } if (this.cullContent) { num5 += this.mPanel.clipOffset.x - this.mTrans.localPosition.x; if (!UICamera.IsPressed(transform.gameObject)) { NGUITools.SetActive(transform.gameObject, num5 > num3 && num5 < num4, false); } } j++; } } else { float num8 = worldCorners[0].y - (float)this.itemSize; float num9 = worldCorners[2].y + (float)this.itemSize; int k = 0; int count2 = this.mChildren.Count; while (k < count2) { Transform transform2 = this.mChildren[k]; float num10 = transform2.localPosition.y - vector2.y; if (num10 < -num) { Vector3 localPosition3 = transform2.localPosition; localPosition3.y += num2; num10 = localPosition3.y - vector2.y; int num11 = Mathf.RoundToInt(localPosition3.y / (float)this.itemSize); if (this.minIndex == this.maxIndex || (this.minIndex <= num11 && num11 <= this.maxIndex)) { transform2.localPosition = localPosition3; this.UpdateItem(transform2, k); } else { flag = false; } } else if (num10 > num) { Vector3 localPosition4 = transform2.localPosition; localPosition4.y -= num2; num10 = localPosition4.y - vector2.y; int num12 = Mathf.RoundToInt(localPosition4.y / (float)this.itemSize); if (this.minIndex == this.maxIndex || (this.minIndex <= num12 && num12 <= this.maxIndex)) { transform2.localPosition = localPosition4; this.UpdateItem(transform2, k); } else { flag = false; } } else if (this.mFirstTime) { this.UpdateItem(transform2, k); } if (this.cullContent) { num10 += this.mPanel.clipOffset.y - this.mTrans.localPosition.y; if (!UICamera.IsPressed(transform2.gameObject)) { NGUITools.SetActive(transform2.gameObject, num10 > num8 && num10 < num9, false); } } k++; } } this.mScroll.restrictWithinPanel = !flag; this.mScroll.InvalidateBounds(); }
/// <summary> /// Wrap all content, repositioning all children as needed. /// </summary> public virtual void WrapContent() { float extents = itemSize * MChildren.Count * 0.5f; 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; if (mHorizontal) { float min = corners[0].x - itemSize; float max = corners[2].x + itemSize; for (int i = 0, imax = MChildren.Count; i < imax; ++i) { Transform t = MChildren[i]; float distance = t.localPosition.x - center.x; int index = Mathf.RoundToInt(t.localPosition.x / itemSize); if (wrapInCircle) { index = (index % (maxIndex - minIndex) + (maxIndex - minIndex)) % (maxIndex - minIndex) + minIndex; } if (distance < -extents) { Vector3 pos = t.localPosition; pos.x += ext2; distance = pos.x - center.x; int realIndex = Mathf.RoundToInt(pos.x / itemSize); if (wrapInCircle) { realIndex = (realIndex % (maxIndex - minIndex) + (maxIndex - minIndex)) % (maxIndex - minIndex) + minIndex; } if (minIndex == maxIndex || (minIndex <= realIndex && realIndex < maxIndex)) { t.localPosition = pos; UpdateItem(t, i); } else { allWithinRange = false; } } else if (distance > extents) { Vector3 pos = t.localPosition; pos.x -= ext2; distance = pos.x - center.x; int realIndex = Mathf.RoundToInt(pos.x / itemSize); if (wrapInCircle) { realIndex = (realIndex % (maxIndex - minIndex) + (maxIndex - minIndex)) % (maxIndex - minIndex) + minIndex; } if (minIndex == maxIndex || (minIndex <= realIndex && realIndex < maxIndex)) { t.localPosition = pos; UpdateItem(t, i); } 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 { NGUITools.SetActive(t.gameObject, true); } if (!(maxIndex < 0 && maxIndex < 0) && (index < minIndex || index >= maxIndex)) { NGUITools.SetActive(t.gameObject, false); } } } else { float min = corners[0].y - itemSize; float max = corners[2].y + itemSize; for (int i = 0, imax = MChildren.Count; i < imax; ++i) { Transform t = MChildren[i]; float distance = t.localPosition.y - center.y; int index = Mathf.RoundToInt(-t.localPosition.y / itemSize);//y轴向下为负轴,所以index要取反 if (wrapInCircle) { index = (index % (maxIndex - minIndex) + (maxIndex - minIndex)) % (maxIndex - minIndex) + minIndex; } if (distance < -extents) { Vector3 pos = t.localPosition; pos.y += ext2; distance = pos.y - center.y; int realIndex = Mathf.RoundToInt(-pos.y / itemSize); //y轴向下为负轴,所以index要取反 if (wrapInCircle) { realIndex = (realIndex % (maxIndex - minIndex) + (maxIndex - minIndex)) % (maxIndex - minIndex) + minIndex; } if (minIndex == maxIndex || (minIndex <= realIndex && realIndex < maxIndex)) { t.localPosition = pos; UpdateItem(t, i); } else { allWithinRange = false; } } else if (distance > extents) { Vector3 pos = t.localPosition; pos.y -= ext2; distance = pos.y - center.y; int realIndex = Mathf.RoundToInt(-pos.y / itemSize); //y轴向下为负轴,所以index要取反 if (wrapInCircle) { realIndex = (realIndex % (maxIndex - minIndex) + (maxIndex - minIndex)) % (maxIndex - minIndex) + minIndex; } if (minIndex == maxIndex || (minIndex <= realIndex && realIndex < maxIndex)) { t.localPosition = pos; UpdateItem(t, i); } else { allWithinRange = false; } } else if (mFirstTime) { UpdateItem(t, i); } if (cullContent) { distance += mPanel.clipOffset.y - mTrans.localPosition.y; if (!UICamera.IsPressed(t.gameObject)) { NGUITools.SetActive(t.gameObject, (distance > min && distance < max), false); } } else { NGUITools.SetActive(t.gameObject, true); } if (!(maxIndex < 0 && maxIndex < 0) && (index < minIndex || index >= maxIndex)) { NGUITools.SetActive(t.gameObject, false); } } } //Start首次WrapContent的时候会影响ScrollView的restrictWithPanel所以注释掉。 //只要能保证WrapContent还没有滑到min或maxIndex的时候,底部的下一个Item的active为true, //注释掉这句就不会有什么影响 // mScroll.restrictWithinPanel = !allWithinRange; mScroll.InvalidateBounds(); }
public void WrapContent() { //IL_0034: Unknown result type (might be due to invalid IL or missing references) //IL_0039: Unknown result type (might be due to invalid IL or missing references) //IL_0040: Unknown result type (might be due to invalid IL or missing references) //IL_0041: Unknown result type (might be due to invalid IL or missing references) //IL_0046: Unknown result type (might be due to invalid IL or missing references) //IL_004e: Unknown result type (might be due to invalid IL or missing references) //IL_004f: Unknown result type (might be due to invalid IL or missing references) //IL_0066: Unknown result type (might be due to invalid IL or missing references) //IL_0072: Unknown result type (might be due to invalid IL or missing references) //IL_007c: Unknown result type (might be due to invalid IL or missing references) //IL_0081: Unknown result type (might be due to invalid IL or missing references) //IL_00ec: Unknown result type (might be due to invalid IL or missing references) //IL_00f1: Unknown result type (might be due to invalid IL or missing references) //IL_012c: Unknown result type (might be due to invalid IL or missing references) //IL_0131: Unknown result type (might be due to invalid IL or missing references) //IL_0140: Unknown result type (might be due to invalid IL or missing references) //IL_0145: Unknown result type (might be due to invalid IL or missing references) //IL_0154: Unknown result type (might be due to invalid IL or missing references) //IL_0159: Expected O, but got Unknown //IL_0165: Unknown result type (might be due to invalid IL or missing references) //IL_017d: Expected O, but got Unknown //IL_01e8: Unknown result type (might be due to invalid IL or missing references) //IL_01ed: Unknown result type (might be due to invalid IL or missing references) //IL_0228: Unknown result type (might be due to invalid IL or missing references) //IL_022d: Unknown result type (might be due to invalid IL or missing references) //IL_023c: Unknown result type (might be due to invalid IL or missing references) //IL_0241: Unknown result type (might be due to invalid IL or missing references) //IL_0250: Unknown result type (might be due to invalid IL or missing references) //IL_0255: Expected O, but got Unknown //IL_0261: Unknown result type (might be due to invalid IL or missing references) //IL_0279: Expected O, but got Unknown float num = (float)(itemSize * mChildren.Count) * 0.5f; Vector3[] worldCorners = mPanel.worldCorners; for (int i = 0; i < 4; i++) { Vector3 val = worldCorners[i]; val = mTrans.InverseTransformPoint(val); worldCorners[i] = val; } Vector3 val2 = Vector3.Lerp(worldCorners[0], worldCorners[2], 0.5f); bool flag = true; float num2 = num * 2f; if (mHorizontal) { float num3 = worldCorners[0].x - (float)itemSize; float num4 = worldCorners[2].x + (float)itemSize; int j = 0; for (int count = mChildren.Count; j < count; j++) { Transform val3 = mChildren[j]; Vector3 localPosition = val3.get_localPosition(); float num5 = localPosition.x - val2.x; if (mFirstTime) { UpdateItem(val3, j); } if (cullContent) { float num6 = num5; Vector2 clipOffset = mPanel.clipOffset; float x = clipOffset.x; Vector3 localPosition2 = mTrans.get_localPosition(); num5 = num6 + (x - localPosition2.x); if (!UICamera.IsPressed(val3.get_gameObject())) { NGUITools.SetActive(val3.get_gameObject(), num5 > num3 && num5 < num4, false); } } } } else { float num7 = worldCorners[0].y - (float)itemSize; float num8 = worldCorners[2].y + (float)itemSize; int k = 0; for (int count2 = mChildren.Count; k < count2; k++) { Transform val4 = mChildren[k]; Vector3 localPosition3 = val4.get_localPosition(); float num9 = localPosition3.y - val2.y; if (mFirstTime) { UpdateItem(val4, k); } if (cullContent) { float num10 = num9; Vector2 clipOffset2 = mPanel.clipOffset; float y = clipOffset2.y; Vector3 localPosition4 = mTrans.get_localPosition(); num9 = num10 + (y - localPosition4.y); if (!UICamera.IsPressed(val4.get_gameObject())) { NGUITools.SetActive(val4.get_gameObject(), num9 > num7 && num9 < num8, false); } } } } }
public void WrapContent() { float num = (float)(this.itemSize * this.mChildren.size) * 0.5f; Vector3[] worldCorners = this.mPanel.worldCorners; for (int i = 0; i < 4; i++) { Vector3 vector = worldCorners[i]; vector = this.mTrans.InverseTransformPoint(vector); worldCorners[i] = vector; } Vector3 vector2 = Vector3.Lerp(worldCorners[0], worldCorners[2], 0.5f); if (this.mHorizontal) { float num2 = worldCorners[0].x - (float)this.itemSize; float num3 = worldCorners[2].x + (float)this.itemSize; for (int j = 0; j < this.mChildren.size; j++) { Transform transform = this.mChildren[j]; float num4 = transform.localPosition.x - vector2.x; if (num4 < -num) { if (this.OpenLog) { } this.UpdateItem(false, transform, j); num4 = transform.localPosition.x - vector2.x; } else if (num4 > num) { if (this.OpenLog) { } this.UpdateItem(true, transform, j); num4 = transform.localPosition.x - vector2.x; } if (this.cullContent) { num4 += this.mPanel.clipOffset.x - this.mTrans.localPosition.x; if (!UICamera.IsPressed(transform.gameObject)) { NGUITools.SetActive(transform.gameObject, num4 > num2 && num4 < num3, false); } } } } else { float num5 = worldCorners[0].y - (float)this.itemSize; float num6 = worldCorners[2].y + (float)this.itemSize; for (int k = 0; k < this.mChildren.size; k++) { Transform transform2 = this.mChildren[k]; float num7 = transform2.localPosition.y - vector2.y; if (num7 < -num) { if (this.OpenLog) { } this.UpdateItem(true, transform2, k); num7 = transform2.localPosition.y - vector2.y; } else if (num7 > num) { if (this.OpenLog) { } this.UpdateItem(false, transform2, k); num7 = transform2.localPosition.y - vector2.y; } if (this.cullContent) { num7 += this.mPanel.clipOffset.y - this.mTrans.localPosition.y; if (!UICamera.IsPressed(transform2.gameObject)) { NGUITools.SetActive(transform2.gameObject, num7 > num5 && num7 < num6, false); } } } } }
public void WrapContent() { float num = (float)(itemSize * mChildren.Count) * 0.5f; Vector3[] worldCorners = mPanel.worldCorners; for (int i = 0; i < 4; i++) { Vector3 position = worldCorners[i]; position = mTrans.InverseTransformPoint(position); worldCorners[i] = position; } Vector3 vector = Vector3.Lerp(worldCorners[0], worldCorners[2], 0.5f); bool flag = true; float num2 = num * 2f; if (mHorizontal) { float num3 = worldCorners[0].x - (float)itemSize; float num4 = worldCorners[2].x + (float)itemSize; int j = 0; for (int count = mChildren.Count; j < count; j++) { Transform transform = mChildren[j]; Vector3 localPosition = transform.localPosition; float num5 = localPosition.x - vector.x; if (num5 < 0f - num) { Vector3 localPosition2 = transform.localPosition; localPosition2.x += num2; num5 = localPosition2.x - vector.x; int num6 = Mathf.RoundToInt(localPosition2.x / (float)itemSize); if (minIndex == maxIndex || (minIndex <= num6 && num6 <= maxIndex)) { transform.localPosition = localPosition2; UpdateItem(transform, j); transform.name = num6.ToString(); } else { flag = false; } } else if (num5 > num) { Vector3 localPosition3 = transform.localPosition; localPosition3.x -= num2; num5 = localPosition3.x - vector.x; int num7 = Mathf.RoundToInt(localPosition3.x / (float)itemSize); if (minIndex == maxIndex || (minIndex <= num7 && num7 <= maxIndex)) { transform.localPosition = localPosition3; UpdateItem(transform, j); transform.name = num7.ToString(); } else { flag = false; } } else if (mFirstTime) { UpdateItem(transform, j); } if (cullContent) { float num8 = num5; Vector2 clipOffset = mPanel.clipOffset; float x = clipOffset.x; Vector3 localPosition4 = mTrans.localPosition; num5 = num8 + (x - localPosition4.x); if (!UICamera.IsPressed(transform.gameObject)) { NGUITools.SetActive(transform.gameObject, num5 > num3 && num5 < num4, compatibilityMode: false); } } } } else { float num9 = worldCorners[0].y - (float)itemSize; float num10 = worldCorners[2].y + (float)itemSize; int k = 0; for (int count2 = mChildren.Count; k < count2; k++) { Transform transform2 = mChildren[k]; Vector3 localPosition5 = transform2.localPosition; float num11 = localPosition5.y - vector.y; if (num11 < 0f - num) { Vector3 localPosition6 = transform2.localPosition; localPosition6.y += num2; num11 = localPosition6.y - vector.y; int num12 = Mathf.RoundToInt(localPosition6.y / (float)itemSize); if (minIndex == maxIndex || (minIndex <= num12 && num12 <= maxIndex)) { transform2.localPosition = localPosition6; UpdateItem(transform2, k); transform2.name = num12.ToString(); } else { flag = false; } } else if (num11 > num) { Vector3 localPosition7 = transform2.localPosition; localPosition7.y -= num2; num11 = localPosition7.y - vector.y; int num13 = Mathf.RoundToInt(localPosition7.y / (float)itemSize); if (minIndex == maxIndex || (minIndex <= num13 && num13 <= maxIndex)) { transform2.localPosition = localPosition7; UpdateItem(transform2, k); transform2.name = num13.ToString(); } else { flag = false; } } else if (mFirstTime) { UpdateItem(transform2, k); } if (cullContent) { float num14 = num11; Vector2 clipOffset2 = mPanel.clipOffset; float y = clipOffset2.y; Vector3 localPosition8 = mTrans.localPosition; num11 = num14 + (y - localPosition8.y); if (!UICamera.IsPressed(transform2.gameObject)) { NGUITools.SetActive(transform2.gameObject, num11 > num9 && num11 < num10, compatibilityMode: false); } } } } mScroll.restrictWithinPanel = !flag; }
/// <summary> /// 将所有内容,根据需要重新定位所有的子集。 /// </summary> public virtual void WrapContent() { float extents = itemSize * mChildren.Count * 0.5f; 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; #region 左右滑动 if (mHorizontal) { float min = corners[0].x - itemSize; float max = corners[2].x + itemSize; 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 realIndex = Mathf.RoundToInt(pos.x / itemSize); if (minIndex == maxIndex || (minIndex <= realIndex && realIndex <= maxIndex)) { t.localPosition = pos; UpdateItem(t, i); } else { allWithinRange = false; } } else if (distance > extents) { Vector3 pos = t.localPosition; pos.x -= ext2; distance = pos.x - center.x; int realIndex = Mathf.RoundToInt(pos.x / itemSize); if (minIndex == maxIndex || (minIndex <= realIndex && realIndex <= maxIndex)) { t.localPosition = pos; UpdateItem(t, i); } 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); } } } } #endregion #region 滑动 else { float a = mScroll.transform.localPosition.y; float min = corners[0].y - itemSize; float max = corners[2].y + itemSize; if (a - itemSize > mScrollStartDrag) { mScrollDrag = a; countIndex = Mathf.RoundToInt((a - mScrollStartDrag) / itemSize); print(countIndex + " 向上 "); } if (mScrollStartDrag - itemSize > a) { mScrollDrag = a; countIndex = Mathf.RoundToInt((mScrollStartDrag - a) / itemSize); print(countIndex + " 向下 "); } 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 / itemSize); if (minIndex == maxIndex || (minIndex <= realIndex && realIndex <= maxIndex)) { t.localPosition = pos; UpdateItem(t, i); } else { allWithinRange = false; } } //向上滑 else if (distance > extents) { countIndex++; print(countIndex + " 向上 "); Vector3 pos = t.localPosition; pos.y -= ext2; distance = pos.y - center.y; int realIndex = Mathf.RoundToInt(pos.y / itemSize); if (minIndex == maxIndex || (minIndex <= realIndex && realIndex <= maxIndex)) { t.localPosition = pos; UpdateItem(t, i); } else { allWithinRange = false; } } else if (mFirstTime) { UpdateItem(t, i); } if (cullContent) { distance += mPanel.clipOffset.y - mTrans.localPosition.y; if (!UICamera.IsPressed(t.gameObject)) { NGUITools.SetActive(t.gameObject, (distance > min && distance < max), false); } } } } #endregion mScroll.restrictWithinPanel = !allWithinRange; //拖动是否会被限制在滚动视图的范围内 mScroll.InvalidateBounds(); }
public void WrapContent() { float num = (float)(itemSize * mChildren.size) * 0.5f; Vector3[] worldCorners = mPanel.worldCorners; for (int i = 0; i < 4; i++) { Vector3 position = worldCorners[i]; position = mTrans.InverseTransformPoint(position); worldCorners[i] = position; } Vector3 vector = Vector3.Lerp(worldCorners[0], worldCorners[2], 0.5f); float num2; float num3; if (mHorizontal) { num2 = worldCorners[0].x - (float)itemSize; num3 = worldCorners[2].x + (float)itemSize; for (int i = 0; i < mChildren.size; i++) { Transform transform = mChildren[i]; float num4 = transform.localPosition.x - vector.x; if (num4 < 0f - num) { transform.localPosition += new Vector3(num * 2f, 0f, 0f); num4 = transform.localPosition.x - vector.x; UpdateItem(transform, i); } else if (num4 > num) { transform.localPosition -= new Vector3(num * 2f, 0f, 0f); num4 = transform.localPosition.x - vector.x; UpdateItem(transform, i); } if (cullContent) { num4 += mPanel.clipOffset.x - mTrans.localPosition.x; if (!UICamera.IsPressed(transform.gameObject)) { NGUITools.SetActive(transform.gameObject, num4 > num2 && num4 < num3, compatibilityMode: false); } } } return; } num2 = worldCorners[0].y - (float)itemSize; num3 = worldCorners[2].y + (float)itemSize; for (int i = 0; i < mChildren.size; i++) { Transform transform = mChildren[i]; float num4 = transform.localPosition.y - vector.y; if (num4 < 0f - num) { transform.localPosition += new Vector3(0f, num * 2f, 0f); num4 = transform.localPosition.y - vector.y; UpdateItem(transform, i); } else if (num4 > num) { transform.localPosition -= new Vector3(0f, num * 2f, 0f); num4 = transform.localPosition.y - vector.y; UpdateItem(transform, i); } if (cullContent) { num4 += mPanel.clipOffset.y - mTrans.localPosition.y; if (!UICamera.IsPressed(transform.gameObject)) { NGUITools.SetActive(transform.gameObject, num4 > num2 && num4 < num3, compatibilityMode: false); } } } }
/// <summary> /// Wrap all content, repositioning all children as needed. /// </summary> public void WrapContentEx() { float extents = itemSize * mChildren.size * 0.5f; 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); if (mHorizontal) { float min = corners[0].x - itemSize; float max = corners[2].x + itemSize; for (int i = 0; i < mChildren.size; ++i) { Transform t = mChildren[i]; float distance = t.localPosition.x - center.x; if (distance < -extents && (/*rightBottomIndex != totalSize - 1*/ Mathf.Abs(Mathf.RoundToInt(t.localPosition.x / itemSize)) + mChildren.size < totalSize || isEndless)) { leftTopIndex = leftTopIndex == totalSize - 1 ? 0 : leftTopIndex + 1; rightBottomIndex = rightBottomIndex == totalSize - 1 ? 0 : rightBottomIndex + 1; // to do 瞬移的时候,这里不能只+一个extents * 2f,而要加到不能加为止(即,distance小于extents时) while (distance < -extents && (Mathf.Abs(Mathf.RoundToInt(t.localPosition.x / itemSize)) + mChildren.size < totalSize || isEndless)) { //Debuger.LogWarning(string.Format("distance: {0} -extents: {1} t.localPosition: {2} index: {3} min: {4} max: {5} t.name: {6} i: {7} rightBottomIndex: {8} totalSize: {9}", distance, -extents, t.localPosition, Mathf.Abs(Mathf.RoundToInt(t.localPosition.x / itemSize)), min, max, t.name, i, rightBottomIndex, totalSize)); t.localPosition += new Vector3(extents * 2f, 0f, 0f); distance = t.localPosition.x - center.x; } if (onUpdateItem != null) { int dataIndex = Mathf.Abs(Mathf.RoundToInt(t.localPosition.x / itemSize)); if (isEndless) { while (dataIndex >= TotalSize && TotalSize > 0) { dataIndex -= TotalSize; } } if (dataIndex < TotalSize) { onUpdateItem(t, dataIndex); } } // 需要重新计算bounds mScroll.mCalculatedBounds = false; //Debuger.LogWarning(string.Format("distance: {0} i: {1} rightBottomIndex: {3} totalSize: {4} t.localPosition: {5} min: {6} max: {7} t.name: {2} ", distance, i, t.name, rightBottomIndex, totalSize, t.localPosition, min, max)); } else if (distance > extents && (/*leftTopIndex != 0*/ Mathf.Abs(Mathf.RoundToInt(t.localPosition.x / itemSize)) - mChildren.size >= 0 || isEndless)) { leftTopIndex = leftTopIndex == 0 ? totalSize - 1 : leftTopIndex - 1; rightBottomIndex = rightBottomIndex == 0 ? totalSize - 1 : rightBottomIndex - 1; while (distance > extents && (Mathf.Abs(Mathf.RoundToInt(t.localPosition.x / itemSize)) - mChildren.size >= 0 || isEndless)) { //Debuger.LogWarning(string.Format("distance: {0} extents: {1} t.localPosition: {2} index: {3} min: {4} max: {5} t.name: {6} i: {7} rightBottomIndex: {8} totalSize: {9}", distance, extents, t.localPosition, Mathf.Abs(Mathf.RoundToInt(t.localPosition.x / itemSize)), min, max, t.name, i, rightBottomIndex, totalSize)); t.localPosition -= new Vector3(extents * 2f, 0f, 0f); distance = t.localPosition.x - center.x; } if (onUpdateItem != null) { int dataIndex = Mathf.Abs(Mathf.RoundToInt(t.localPosition.x / itemSize)); if (isEndless) { while (dataIndex >= TotalSize && TotalSize > 0) { dataIndex -= TotalSize; } } if (dataIndex < TotalSize) { onUpdateItem(t, dataIndex); } } // 需要重新计算bounds mScroll.mCalculatedBounds = false; //Debuger.LogWarning(string.Format("distance: {0} i: {1} leftTopIndex: {2} totalSize: {4} t.localPosition: {5} min: {6} max: {7} t.name: {3} ", distance, i, leftTopIndex, t.name, totalSize, t.localPosition, min, max)); } if (cullContent) { distance += mPanel.clipOffset.x - mTrans.localPosition.x; if (!UICamera.IsPressed(t.gameObject)) { t.gameObject.SetActive((distance > min && distance < max)); } //NGUITools.SetActive(t.gameObject, (distance > min && distance < max), false); } } } else { float min = corners[0].y - itemSize; float max = corners[2].y + itemSize; for (int i = 0; i < mChildren.size; ++i) { Transform t = mChildren[i]; float distance = t.localPosition.y - center.y; if (distance < -extents && (/*leftTopIndex != 0*/ Mathf.Abs(Mathf.RoundToInt(t.localPosition.y / itemSize)) - mChildren.size >= 0 || isEndless)) { //Debuger.Log(string.Format("totalSize: {0} leftTopIndex: {1} rightBottomIndex: {2}", totalSize, leftTopIndex, rightBottomIndex)); leftTopIndex = leftTopIndex == 0 ? totalSize - 1 : leftTopIndex - 1; rightBottomIndex = rightBottomIndex == 0 ? totalSize - 1 : rightBottomIndex - 1; while (distance < -extents && (Mathf.Abs(Mathf.RoundToInt(t.localPosition.y / itemSize)) - mChildren.size >= 0 || isEndless)) { t.localPosition += new Vector3(0f, extents * 2f, 0f); distance = t.localPosition.y - center.y; //Debuger.LogWarning(string.Format("distance: {0} i: {1} leftTopIndex: {2} rightBottomIndex: {9} updateIndex: {10} totalSize: {4} t.localPosition: {5} min: {6} max: {7} t.name: {3} preLocalPos: {8}", distance, i, leftTopIndex, t.name, totalSize, t.localPosition.y, min, max, preLocalPos, rightBottomIndex, Mathf.Abs(Mathf.RoundToInt(t.localPosition.y / itemSize)))); } if (onUpdateItem != null) { int dataIndex = Mathf.Abs(Mathf.RoundToInt(t.localPosition.y / itemSize)); if (isEndless) { while (dataIndex >= TotalSize && TotalSize > 0) { dataIndex -= TotalSize; } } if (dataIndex < TotalSize) { onUpdateItem(t, dataIndex); } } // 需要重新计算bounds mScroll.mCalculatedBounds = false; } else if (distance > extents && (/*rightBottomIndex != totalSize - 1 */ Mathf.Abs(Mathf.RoundToInt(t.localPosition.y / itemSize)) + mChildren.size < totalSize || isEndless)) { //Debuger.Log(string.Format("totalSize: {0} leftTopIndex: {1} rightBottomIndex: {2}", totalSize, leftTopIndex, rightBottomIndex)); leftTopIndex = leftTopIndex == totalSize - 1 ? 0 : leftTopIndex + 1; rightBottomIndex = rightBottomIndex == totalSize - 1 ? 0 : rightBottomIndex + 1; while (distance > extents && (Mathf.Abs(Mathf.RoundToInt(t.localPosition.y / itemSize)) + mChildren.size < totalSize || isEndless)) { t.localPosition -= new Vector3(0f, extents * 2f, 0f); //Debuger.LogWarning(string.Format("distance: {0} i: {1} leftTopIndex: {2} rightBottomIndex: {9} updateIndex: {10} totalSize: {4} t.localPosition: {5} min: {6} max: {7} t.name: {3} preLocalPos: {8}", distance, i, leftTopIndex, t.name, totalSize, t.localPosition.y, min, max, preLocalPos, rightBottomIndex, Mathf.Abs(Mathf.RoundToInt(t.localPosition.y / itemSize)))); distance = t.localPosition.y - center.y; } if (onUpdateItem != null) { int dataIndex = Mathf.Abs(Mathf.RoundToInt(t.localPosition.y / itemSize)); if (isEndless) { while (dataIndex >= TotalSize && TotalSize > 0) { dataIndex -= TotalSize; } } if (dataIndex < TotalSize) { onUpdateItem(t, dataIndex); } } // 需要重新计算bounds mScroll.mCalculatedBounds = false; } if (cullContent) { distance += mPanel.clipOffset.y - mTrans.localPosition.y; if (!UICamera.IsPressed(t.gameObject)) { t.gameObject.SetActive((distance > min && distance < max)); } //NGUITools.SetActive(t.gameObject, (distance > min && distance < max), false); } } } }
/// <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(); }
/// <summary> /// Wrap all content, repositioning all children as needed. /// </summary> /// //float fffff_LastCenterY = 0; private void WrapVerticalContent() { if (mPanel == null) { return; } int lineCount = (mChildren.Count / rowNumber) + ((mChildren.Count % rowNumber) != 0 ? 1 : 0); //拥有控件的总共大小的一半 float extents = itemYSpace * lineCount * 0.5f; 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); //Debug.LogWarning("center :" + center.ToString()); //if( Mathf.Abs(fffff_LastCenterY - center.y) > 2000 ) //{ // Debug.LogError("fffff_LastCenterY 大于 2000"); //} //fffff_LastCenterY = center.y; bool allWithinRange = true; float ext2 = extents * 2f; float min = corners[0].y - itemYSpace; float max = corners[2].y + itemYSpace; for (int i = 0, imax = mChildren.Count; i < imax; ++i) { Transform t = mChildren[i]; Vector3 pos = t.localPosition; int rowIndex = Mathf.RoundToInt((beginY - pos.y) / itemYSpace); int tempIndex = rowIndex * rowNumber + i % rowNumber; //realIndex = CutOffRealIndex(realIndex); if (tempIndex >= itemCount && itemCount <= pageCount) { NGUITools.SetActive(t.gameObject, false, false); allWithinRange = false; continue; } float distance = t.localPosition.y - center.y; bool bNeedRefresh = false; if (mFirstTime && tempIndex < itemCount) { int iColIndex = 0; if (rowNumber > 1 && itemXSpace > 0) { iColIndex = ((int)(pos.x - corners[0].x) + itemXSpace / 2) / itemXSpace - 1; } UpdateItem(t, tempIndex, iColIndex); continue; } //往上移动时,下面的item超出了veiw的范围,然后把下面的控件移动到上面(y++++) //计算索引,回调刷新 else if (distance < -extents) { while (distance < -extents) { pos.y += ext2; //移动到上面 distance = pos.y - center.y; //记录新距离 } bNeedRefresh = true; } //往下移动时,上面的item超出了veiw的范围 else if (distance > extents) { while (distance > extents) { pos.y -= ext2; distance = pos.y - center.y; } bNeedRefresh = true; } else if (bDirty) { bNeedRefresh = true; } rowIndex = Mathf.RoundToInt((beginY - pos.y) / itemYSpace); int realIndex = rowIndex * rowNumber + i % rowNumber; if (!bLoop) { int dataLineCount = (itemCount / rowNumber) + ((itemCount % rowNumber) != 0 ? 1 : 0); if (rowIndex < 0 || rowIndex > dataLineCount || realIndex >= itemCount) { allWithinRange = false; //NGUITools.SetActive(t.gameObject, false, false); continue; } } if (bNeedRefresh) { realIndex = CutOffRealIndex(realIndex); //Debug.LogWarning("realIndex: " + realIndex.ToString()); if (realIndex >= 0 && realIndex < itemCount) { int a = itemXSpace - 1; if (a == 0) { a = 1; } int iColIndex = ((int)(pos.x - corners[0].x) + itemXSpace / 2) / a; t.localPosition = pos; UpdateItem(t, realIndex, iColIndex); } else { allWithinRange = false; } } if (cullContent && itemCount >= pageCount) { distance += mPanel.clipOffset.y - mTrans.localPosition.y; if (!UICamera.IsPressed(t.gameObject)) { bool bCull = (distance > min && distance < max); NGUITools.SetActive(t.gameObject, bCull, false); } } } mScroll.restrictWithinPanel = !allWithinRange; bDirty = false; }
/// <summary> /// Wrap all content, repositioning all children as needed. /// </summary> public virtual void WrapContent() { var extents = itemSize * mChildren.Count * 0.5f; var corners = mPanel.worldCorners; for (var i = 0; i < 4; ++i) { var v = corners[i]; v = mTrans.InverseTransformPoint(v); corners[i] = v; } var center = Vector3.Lerp(corners[0], corners[2], 0.5f); var allWithinRange = true; var ext2 = extents * 2f; if (mHorizontal) { var min = corners[0].x - itemSize; var max = corners[2].x + itemSize; for (int i = 0, imax = mChildren.Count; i < imax; ++i) { var t = mChildren[i]; var distance = t.localPosition.x - center.x; if (distance < -extents) { var pos = t.localPosition; pos.x += ext2; distance = pos.x - center.x; var realIndex = Mathf.RoundToInt(pos.x / itemSize); if (minIndex == maxIndex || (minIndex <= realIndex && realIndex <= maxIndex)) { t.localPosition = pos; UpdateItem(t, i); } else { allWithinRange = false; } } else if (distance > extents) { var pos = t.localPosition; pos.x -= ext2; distance = pos.x - center.x; var realIndex = Mathf.RoundToInt(pos.x / itemSize); if (minIndex == maxIndex || (minIndex <= realIndex && realIndex <= maxIndex)) { t.localPosition = pos; UpdateItem(t, i); } 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 { var min = corners[0].y - itemSize; var max = corners[2].y + itemSize; for (int i = 0, imax = mChildren.Count; i < imax; ++i) { var t = mChildren[i]; var distance = t.localPosition.y - center.y; if (distance < -extents) { var pos = t.localPosition; pos.y += ext2; distance = pos.y - center.y; var realIndex = Mathf.RoundToInt(pos.y / itemSize); if (minIndex == maxIndex || (minIndex <= realIndex && realIndex <= maxIndex)) { t.localPosition = pos; UpdateItem(t, i); } else { allWithinRange = false; } } else if (distance > extents) { var pos = t.localPosition; pos.y -= ext2; distance = pos.y - center.y; var realIndex = Mathf.RoundToInt(pos.y / itemSize); if (minIndex == maxIndex || (minIndex <= realIndex && realIndex <= maxIndex)) { t.localPosition = pos; UpdateItem(t, i); } else { allWithinRange = false; } } else if (mFirstTime) { UpdateItem(t, i); } if (cullContent) { distance += mPanel.clipOffset.y - mTrans.localPosition.y; if (!UICamera.IsPressed(t.gameObject)) { NGUITools.SetActive(t.gameObject, (distance > min && distance < max), false); } } } } mScroll.restrictWithinPanel = !allWithinRange; mScroll.InvalidateBounds(); }
/// <summary> /// Wrap all content, repositioning all children as needed. /// </summary> private void WrapContent() { float extents = m_itemSize * m_childDic.Count * 0.5f; Vector3[] corners = m_panel.worldCorners; for (int i = 0; i < 4; ++i) { Vector3 v = corners[i]; v = transform.InverseTransformPoint(v); corners[i] = v; } Vector3 center = Vector3.Lerp(corners[0], corners[2], 0.5f); bool allWithinRange = true; float ext2 = extents * 2f; if (m_horizontal) { float min = corners[0].x - m_itemSize; float max = corners[2].x + m_itemSize; for (int i = 0, imax = transform.childCount; i < imax; ++i) { Transform temp = transform.GetChild(i); float distance = temp.localPosition.x - center.x; if (distance < -extents) { Vector3 pos = temp.localPosition; pos.x += ext2; distance = pos.x - center.x; if (m_childDic.ContainsKey(temp)) { int newIndex = m_childDic[temp] + m_childDic.Count; if (m_isEndless) { if (0 <= newIndex && newIndex < m_dataCount) { m_childDic[temp] = newIndex; temp.localPosition = pos; UpdateItem(temp, i); } else { m_childDic[temp] = newIndex - m_dataCount; temp.localPosition = pos; UpdateItem(temp, i); } } else { if (0 <= newIndex && newIndex < m_dataCount) { m_childDic[temp] = newIndex; temp.localPosition = pos; UpdateItem(temp, i); } else { allWithinRange = false; } } //if (m_isEndless || (0 <= newIndex && newIndex < m_dataCount)) { // m_childDic[temp] = newIndex; // temp.localPosition = pos; // UpdateItem(temp, i); //} else { // allWithinRange = false; //} } else { Debug.Log("没有初始化"); } } else if (distance > extents) { Vector3 pos = temp.localPosition; pos.x -= ext2; distance = pos.x - center.x; if (m_childDic.ContainsKey(temp)) { int newIndex = m_childDic[temp] - m_childDic.Count; if (m_isEndless) { if (0 <= newIndex && newIndex < m_dataCount) { m_childDic[temp] = newIndex; temp.localPosition = pos; UpdateItem(temp, i); } else { m_childDic[temp] = newIndex + m_dataCount; temp.localPosition = pos; UpdateItem(temp, i); } } else { if (0 <= newIndex && newIndex < m_dataCount) { m_childDic[temp] = newIndex; temp.localPosition = pos; UpdateItem(temp, i); } else { allWithinRange = false; } } //if (m_isEndless || (0 <= newIndex && newIndex < m_dataCount)) { // m_childDic[temp] = newIndex; // temp.localPosition = pos; // UpdateItem(temp, i); //} else { // allWithinRange = false; //} } else { Debug.Log("没有初始化"); } } if (m_cullContent) { distance += m_panel.clipOffset.x - transform.localPosition.x; if (!UICamera.IsPressed(temp.gameObject)) { NGUITools.SetActive(temp.gameObject, m_isEndless || (distance > min && distance < max && 0 <= m_childDic[temp] && m_childDic[temp] < m_dataCount), false); } } } } else { float min = corners[0].y - m_itemSize; float max = corners[2].y + m_itemSize; for (int i = 0, imax = transform.childCount; i < imax; ++i) { Transform temp = transform.GetChild(i); float distance = temp.localPosition.y - center.y; if (distance < -extents) { Vector3 pos = temp.localPosition; pos.y += ext2; distance = pos.y - center.y; if (m_childDic.ContainsKey(temp)) { int newIndex = m_childDic[temp] - m_childDic.Count; if (m_isEndless) { if (0 <= newIndex && newIndex < m_dataCount) { m_childDic[temp] = newIndex; temp.localPosition = pos; UpdateItem(temp, i); } else { m_childDic[temp] = newIndex + m_dataCount; temp.localPosition = pos; UpdateItem(temp, i); } } else { if (0 <= newIndex && newIndex < m_dataCount) { m_childDic[temp] = newIndex; temp.localPosition = pos; UpdateItem(temp, i); } else { allWithinRange = false; } } //if (m_isEndless || (0 <= newIndex && newIndex < m_dataCount)) { // m_childDic[temp] = newIndex; // temp.localPosition = pos; // UpdateItem(temp, i); //} else { // allWithinRange = false; //} } else { Debug.Log("没有初始化"); } } else if (distance > extents) { Vector3 pos = temp.localPosition; pos.y -= ext2; distance = pos.y - center.y; if (m_childDic.ContainsKey(temp)) { int newIndex = m_childDic[temp] + m_childDic.Count; if (m_isEndless) { if (0 <= newIndex && newIndex < m_dataCount) { m_childDic[temp] = newIndex; temp.localPosition = pos; UpdateItem(temp, i); } else { m_childDic[temp] = newIndex - m_dataCount; temp.localPosition = pos; UpdateItem(temp, i); } } else { if (0 <= newIndex && newIndex < m_dataCount) { m_childDic[temp] = newIndex; temp.localPosition = pos; UpdateItem(temp, i); } else { allWithinRange = false; } } //if (m_isEndless || (0 <= newIndex && newIndex < m_dataCount)) { // m_childDic[temp] = newIndex; // temp.localPosition = pos; // UpdateItem(temp, i); //} else { // allWithinRange = false; //} } else { Debug.Log("没有初始化"); } } if (m_cullContent) { distance += m_panel.clipOffset.y - transform.localPosition.y; if (!UICamera.IsPressed(temp.gameObject)) { NGUITools.SetActive(temp.gameObject, m_isEndless || (distance > min && distance < max && 0 <= m_childDic[temp] && m_childDic[temp] < m_dataCount), false); } } } } m_uiScrollView.restrictWithinPanel = !allWithinRange; }
/// <summary> /// Wrap all content, repositioning all children as needed. /// </summary> public virtual void WrapContent() { float extents = itemSize * (mChildren.Count / (mGrid == null ? 1 : mGrid.maxPerLine)) * 0.5f; // changed by KPH 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; if (mHorizontal) { float min = corners[0].x - itemSize; float max = corners[2].x + itemSize; 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 realIndex = Mathf.RoundToInt(pos.x / itemSize); if (minIndex == maxIndex || (minIndex <= realIndex && realIndex <= maxIndex)) { t.localPosition = pos; UpdateItem(t, i); } else { allWithinRange = false; } } else if (distance > extents) { Vector3 pos = t.localPosition; pos.x -= ext2; distance = pos.x - center.x; int realIndex = Mathf.RoundToInt(pos.x / itemSize); if (minIndex == maxIndex || (minIndex <= realIndex && realIndex <= maxIndex)) { t.localPosition = pos; UpdateItem(t, i); } 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 - itemSize; float max = corners[2].y + itemSize; 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 / itemSize); if (minIndex == maxIndex || (minIndex <= realIndex && realIndex <= maxIndex)) { t.localPosition = pos; UpdateItem(t, i); } else { allWithinRange = false; } } else if (distance > extents) { Vector3 pos = t.localPosition; pos.y -= ext2; distance = pos.y - center.y; int realIndex = Mathf.RoundToInt(pos.y / itemSize); if (minIndex == maxIndex || (minIndex <= realIndex && realIndex <= maxIndex)) { t.localPosition = pos; UpdateItem(t, i); } else { allWithinRange = false; } } else if (mFirstTime) { UpdateItem(t, i); } if (cullContent) { distance += mPanel.clipOffset.y - mTrans.localPosition.y; if (!UICamera.IsPressed(t.gameObject)) { NGUITools.SetActive(t.gameObject, t.gameObject.hideFlags == HideFlags.None && (distance > min && distance < max), false); } } } } mScroll.restrictWithinPanel = mGrid != null ? true : !allWithinRange; mScroll.InvalidateBounds(); }
protected bool WrapVertical(Vector3[] corners) { float extents = GetExtents(); bool allWithinRange = true; float halfExtents = extents * 0.5f; Vector3 center = Vector3.Lerp(corners[0], corners[2], 0.5f); for (int i = 0, imax = mChildren.Count; i < imax; ++i) { Transform t = mChildren[i]; float distance = t.localPosition.y - center.y; if (mForceReset) { // update all int realIndex = GetRealIndex(t.localPosition); if (minIndex == maxIndex || (minIndex <= realIndex && realIndex <= maxIndex)) { t.name = realIndex.ToString(); UpdateItem(t, i, realIndex); } if (extents <= mPanel.finalClipRegion.w) { allWithinRange = false; } } else if (extents > mPanel.finalClipRegion.w) { // if out of panel, update if (Mathf.Abs(distance) > halfExtents) { Vector3 pos = t.localPosition; pos.y = distance < 0f ? pos.y + extents : pos.y - extents; distance = pos.y - center.y; int realIndex = GetRealIndex(pos); if (minIndex == maxIndex || (minIndex <= realIndex && realIndex <= maxIndex)) { t.localPosition = pos; t.name = realIndex.ToString(); UpdateItem(t, i, realIndex); } else { allWithinRange = false; } } } else { allWithinRange = false; } } if (cullContent && mNeedToWrap) { float min = corners[0].y - itemHeight; float max = corners[2].y + itemHeight; for (int i = 0, imax = mChildren.Count; i < imax; ++i) { if (!UICamera.IsPressed(mChildren[i].gameObject)) { bool active = allWithinRange ? mChildren[i].localPosition.y > min && mChildren[i].localPosition.y < max : true; NGUITools.SetActive(mChildren[i].gameObject, active, false); } } } return(allWithinRange); }
/// <summary> /// Wrap all content, repositioning all children as needed. /// </summary> public void WrapContent() { float extents = itemSize * mChildren.size * 0.5f; 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); if (mHorizontal) { float min = corners[0].x - itemSize; float max = corners[2].x + itemSize; for (int i = 0; i < mChildren.size; ++i) { Transform t = mChildren[i]; float distance = t.localPosition.x - center.x; if (distance < -extents) { t.localPosition += new Vector3(extents * 2f, 0f, 0f); distance = t.localPosition.x - center.x; UpdateItem(t, i); } else if (distance > extents) { t.localPosition -= new Vector3(extents * 2f, 0f, 0f); distance = t.localPosition.x - center.x; UpdateItem(t, i); } 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 - itemSize; float max = corners[2].y + itemSize; for (int i = 0; i < mChildren.size; ++i) { Transform t = mChildren[i]; float distance = t.localPosition.y - center.y; if (distance < -extents) { t.localPosition += new Vector3(0f, extents * 2f, 0f); distance = t.localPosition.y - center.y; UpdateItem(t, i); } else if (distance > extents) { t.localPosition -= new Vector3(0f, extents * 2f, 0f); distance = t.localPosition.y - center.y; UpdateItem(t, i); } else if (mFirstTime) { UpdateItem(t, i); } if (cullContent) { distance += mPanel.clipOffset.y - mTrans.localPosition.y; if (!UICamera.IsPressed(t.gameObject)) { NGUITools.SetActive(t.gameObject, (distance > min && distance < max), false); } } } } }
public void WrapContent() { float num = ((!this.mHorizontal) ? this.itemSize.y : this.itemSize.x) * (float)(this.mChildren.size / this.WidthDimension) * 0.5f; num = Mathf.Max(num, 1f); float num2 = num * 2f; float num3 = ((!this.mHorizontal) ? this.itemSize.y : this.itemSize.x) / 2f + num; Vector3 a = (!this.mHorizontal) ? new Vector3(0f, num * 2f, 0f) : new Vector3(num * 2f, 0f, 0f); Vector3[] worldCorners = this.mPanel.worldCorners; for (int i = 0; i < 4; i++) { Vector3 vector = worldCorners[i]; vector = this.mTrans.InverseTransformPoint(vector); worldCorners[i] = vector; } Vector3 vector2 = Vector3.Lerp(worldCorners[0], worldCorners[2], 0.5f); bool flag = false; bool flag2 = true; if (this.mHorizontal) { float num4 = worldCorners[0].x - vector2.x - this.itemSize.x; float num5 = worldCorners[2].x - vector2.x + this.itemSize.x; int j = 0; while (j < this.mChildren.size) { Transform transform = this.mChildren[j]; float num6 = transform.localPosition.x - vector2.x; if (num6 < -num3) { int num7 = (int)(-num - num6) / (int)num2 + 1; if (!this.bBounds || transform.localPosition.x + num2 * (float)num7 <= this.upperBoundWithEpsilon) { transform.localPosition += a * (float)num7; flag = true; num6 = transform.localPosition.x - vector2.x; } } else if (num6 > num3) { int num7 = (int)(num6 - num) / (int)num2 + 1; if (!this.bBounds || transform.localPosition.x - num2 * (float)num7 >= this.lowerBoundWithEpsilon) { transform.localPosition -= a * (float)num7; flag = true; num6 = transform.localPosition.x - vector2.x; } } if (this.bBounds) { if (transform.localPosition.x > this.upperBoundWithEpsilon) { int num7 = (int)(transform.localPosition.x - this.upperBound) / (int)num2 + 1; transform.localPosition -= a * (float)num7; flag = (transform.localPosition.x >= this.lowerBoundWithEpsilon); flag2 = flag; num6 = transform.localPosition.x - vector2.x; } else if (transform.localPosition.x < this.lowerBoundWithEpsilon) { int num7 = (int)(this.lowerBound - transform.localPosition.x) / (int)num2 + 1; transform.localPosition += a * (float)num7; flag = (transform.localPosition.x <= this.upperBoundWithEpsilon); flag2 = flag; num6 = transform.localPosition.x - vector2.x; } } if (this.cullContent) { num6 += -this.mTrans.localPosition.x; if (!UICamera.IsPressed(transform.gameObject)) { if (flag) { if (!transform.gameObject.activeSelf) { NGUITools.SetActive(transform.gameObject, true, false, true); } this.UpdateItem(transform, j); flag = false; } NGUITools.SetActive(transform.gameObject, flag2 && num6 > num4 && num6 < num5, false, true); } } if (flag) { this.UpdateItem(transform, j); } j++; flag = false; flag2 = true; } } else { float num8 = worldCorners[0].y - vector2.y - this.itemSize.y; float num9 = worldCorners[2].y - vector2.y + this.itemSize.y; int k = 0; while (k < this.mChildren.size) { Transform transform2 = this.mChildren[k]; float num10 = transform2.localPosition.y - vector2.y; if (num10 < -num3) { int num7 = (int)(-num - num10) / (int)num2 + 1; if (!this.bBounds || transform2.localPosition.y + num2 * (float)num7 <= this.upperBoundWithEpsilon) { transform2.localPosition += a * (float)num7; flag = true; num10 = transform2.localPosition.y - vector2.y; } } else if (num10 > num3) { int num7 = (int)(num10 - num) / (int)num2 + 1; if (!this.bBounds || transform2.localPosition.y - num2 * (float)num7 >= this.lowerBoundWithEpsilon) { transform2.localPosition -= a * (float)num7; flag = true; num10 = transform2.localPosition.y - vector2.y; } } if (this.bBounds) { if (transform2.localPosition.y > this.upperBoundWithEpsilon) { int num7 = (int)(transform2.localPosition.y - this.upperBound) / (int)num2 + 1; transform2.localPosition -= a * (float)num7; flag = (transform2.localPosition.y >= this.lowerBoundWithEpsilon); flag2 = flag; num10 = transform2.localPosition.y - vector2.y; } else if (transform2.localPosition.y < this.lowerBoundWithEpsilon) { int num7 = (int)(this.lowerBound - transform2.localPosition.y) / (int)num2 + 1; transform2.localPosition += a * (float)num7; flag = (transform2.localPosition.y <= this.upperBoundWithEpsilon); flag2 = flag; num10 = transform2.localPosition.y - vector2.y; } } if (this.cullContent) { num10 += -this.mTrans.localPosition.y; if (!UICamera.IsPressed(transform2.gameObject)) { if (flag) { if (!transform2.gameObject.activeSelf) { NGUITools.SetActive(transform2.gameObject, true, false, true); } this.UpdateItem(transform2, k); flag = false; } else { NGUITools.SetActive(transform2.gameObject, flag2 && num10 > num8 && num10 < num9, false, true); } } } if (flag) { this.UpdateItem(transform2, k); } k++; flag = false; flag2 = true; } } }
public void CalcPosition(bool update = false) { if (enabled) { float extents = itemSize * mChildren.Count * 0.5f; 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; float min = corners[0].y - (itemSize * BotLeniency); float max = corners[2].y + (itemSize * TopLeniency); 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 / itemSize); if (minIndex == maxIndex || (minIndex <= realIndex && realIndex <= maxIndex)) { t.localPosition = pos; } else { allWithinRange = false; } } else if (distance > extents) { int num = (int)(distance / ext2); if (num == 0) { num = 1; } Vector3 pos = t.localPosition; pos.y -= (ext2 * num); distance = pos.y - center.y; int realIndex = Mathf.RoundToInt(pos.y / itemSize); if (minIndex == maxIndex || (minIndex <= realIndex && realIndex <= maxIndex)) { t.localPosition = pos; } else { allWithinRange = false; } } if (cullContent) { distance += mPanel.clipOffset.y - mTrans.localPosition.y; bool setActive = (distance > min && distance < max); if (!UICamera.IsPressed(t.gameObject) && !CheckChildrenPressed(t.gameObject)) { NGUITools.SetActive(t.gameObject, setActive, false); } } if (update) { UpdateItem(t, i); } } mScroll.restrictWithinPanel = !allWithinRange; } }
public void WrapContent() { //IL_0034: Unknown result type (might be due to invalid IL or missing references) //IL_0039: Unknown result type (might be due to invalid IL or missing references) //IL_0040: Unknown result type (might be due to invalid IL or missing references) //IL_0041: Unknown result type (might be due to invalid IL or missing references) //IL_0046: Unknown result type (might be due to invalid IL or missing references) //IL_004e: Unknown result type (might be due to invalid IL or missing references) //IL_004f: Unknown result type (might be due to invalid IL or missing references) //IL_0066: Unknown result type (might be due to invalid IL or missing references) //IL_0072: Unknown result type (might be due to invalid IL or missing references) //IL_007c: Unknown result type (might be due to invalid IL or missing references) //IL_0081: Unknown result type (might be due to invalid IL or missing references) //IL_00ec: Unknown result type (might be due to invalid IL or missing references) //IL_00f1: Unknown result type (might be due to invalid IL or missing references) //IL_010f: Unknown result type (might be due to invalid IL or missing references) //IL_0114: Unknown result type (might be due to invalid IL or missing references) //IL_017a: Unknown result type (might be due to invalid IL or missing references) //IL_01a2: Unknown result type (might be due to invalid IL or missing references) //IL_01a7: Unknown result type (might be due to invalid IL or missing references) //IL_020d: Unknown result type (might be due to invalid IL or missing references) //IL_0253: Unknown result type (might be due to invalid IL or missing references) //IL_0258: Unknown result type (might be due to invalid IL or missing references) //IL_0267: Unknown result type (might be due to invalid IL or missing references) //IL_026c: Unknown result type (might be due to invalid IL or missing references) //IL_027b: Unknown result type (might be due to invalid IL or missing references) //IL_0280: Expected O, but got Unknown //IL_028c: Unknown result type (might be due to invalid IL or missing references) //IL_02a4: Expected O, but got Unknown //IL_030f: Unknown result type (might be due to invalid IL or missing references) //IL_0314: Unknown result type (might be due to invalid IL or missing references) //IL_0332: Unknown result type (might be due to invalid IL or missing references) //IL_0337: Unknown result type (might be due to invalid IL or missing references) //IL_039d: Unknown result type (might be due to invalid IL or missing references) //IL_03c5: Unknown result type (might be due to invalid IL or missing references) //IL_03ca: Unknown result type (might be due to invalid IL or missing references) //IL_0430: Unknown result type (might be due to invalid IL or missing references) //IL_0476: Unknown result type (might be due to invalid IL or missing references) //IL_047b: Unknown result type (might be due to invalid IL or missing references) //IL_048a: Unknown result type (might be due to invalid IL or missing references) //IL_048f: Unknown result type (might be due to invalid IL or missing references) //IL_049e: Unknown result type (might be due to invalid IL or missing references) //IL_04a3: Expected O, but got Unknown //IL_04af: Unknown result type (might be due to invalid IL or missing references) //IL_04c7: Expected O, but got Unknown float num = (float)(itemSize * mChildren.Count) * 0.5f; Vector3[] worldCorners = mPanel.worldCorners; for (int i = 0; i < 4; i++) { Vector3 val = worldCorners[i]; val = mTrans.InverseTransformPoint(val); worldCorners[i] = val; } Vector3 val2 = Vector3.Lerp(worldCorners[0], worldCorners[2], 0.5f); bool flag = true; float num2 = num * 2f; if (mHorizontal) { float num3 = worldCorners[0].x - (float)itemSize; float num4 = worldCorners[2].x + (float)itemSize; int j = 0; for (int count = mChildren.Count; j < count; j++) { Transform val3 = mChildren[j]; Vector3 localPosition = val3.get_localPosition(); float num5 = localPosition.x - val2.x; if (num5 < 0f - num) { Vector3 localPosition2 = val3.get_localPosition(); localPosition2.x += num2; num5 = localPosition2.x - val2.x; int num6 = Mathf.RoundToInt(localPosition2.x / (float)itemSize); if (minIndex == maxIndex || (minIndex <= num6 && num6 <= maxIndex)) { val3.set_localPosition(localPosition2); UpdateItem(val3, j); } else { flag = false; } } else if (num5 > num) { Vector3 localPosition3 = val3.get_localPosition(); localPosition3.x -= num2; num5 = localPosition3.x - val2.x; int num7 = Mathf.RoundToInt(localPosition3.x / (float)itemSize); if (minIndex == maxIndex || (minIndex <= num7 && num7 <= maxIndex)) { val3.set_localPosition(localPosition3); UpdateItem(val3, j); } else { flag = false; } } else if (mFirstTime) { UpdateItem(val3, j); } if (cullContent) { float num8 = num5; Vector2 clipOffset = mPanel.clipOffset; float x = clipOffset.x; Vector3 localPosition4 = mTrans.get_localPosition(); num5 = num8 + (x - localPosition4.x); if (!UICamera.IsPressed(val3.get_gameObject())) { NGUITools.SetActive(val3.get_gameObject(), num5 > num3 && num5 < num4, false); } } } } else { float num9 = worldCorners[0].y - (float)itemSize; float num10 = worldCorners[2].y + (float)itemSize; int k = 0; for (int count2 = mChildren.Count; k < count2; k++) { Transform val4 = mChildren[k]; Vector3 localPosition5 = val4.get_localPosition(); float num11 = localPosition5.y - val2.y; if (num11 < 0f - num) { Vector3 localPosition6 = val4.get_localPosition(); localPosition6.y += num2; num11 = localPosition6.y - val2.y; int num12 = Mathf.RoundToInt(localPosition6.y / (float)itemSize); if (minIndex == maxIndex || (minIndex <= num12 && num12 <= maxIndex)) { val4.set_localPosition(localPosition6); UpdateItem(val4, k); } else { flag = false; } } else if (num11 > num) { Vector3 localPosition7 = val4.get_localPosition(); localPosition7.y -= num2; num11 = localPosition7.y - val2.y; int num13 = Mathf.RoundToInt(localPosition7.y / (float)itemSize); if (minIndex == maxIndex || (minIndex <= num13 && num13 <= maxIndex)) { val4.set_localPosition(localPosition7); UpdateItem(val4, k); } else { flag = false; } } else if (mFirstTime) { UpdateItem(val4, k); } if (cullContent) { float num14 = num11; Vector2 clipOffset2 = mPanel.clipOffset; float y = clipOffset2.y; Vector3 localPosition8 = mTrans.get_localPosition(); num11 = num14 + (y - localPosition8.y); if (!UICamera.IsPressed(val4.get_gameObject())) { NGUITools.SetActive(val4.get_gameObject(), num11 > num9 && num11 < num10, false); } } } } mScroll.restrictWithinPanel = !flag; }
/// <summary> /// Wrap all content, repositioning all children as needed. /// </summary> public void WrapContent() { float extents = itemSize * mChildren.Count * 0.5f; 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; if (mHorizontal) { float min = corners[0].x - itemSize; float max = corners[2].x + itemSize; 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 realIndex = Mathf.RoundToInt(pos.x / itemSize); if (minIndex == maxIndex || (minIndex <= realIndex && realIndex <= maxIndex)) { t.localPosition = pos; UpdateItem(t, i); t.name = realIndex.ToString(); } else { allWithinRange = false; } } else if (distance > extents) { Vector3 pos = t.localPosition; pos.x -= ext2; distance = pos.x - center.x; int realIndex = Mathf.RoundToInt(pos.x / itemSize); if (minIndex == maxIndex || (minIndex <= realIndex && realIndex <= maxIndex)) { t.localPosition = pos; UpdateItem(t, i); t.name = realIndex.ToString(); } 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 - itemSize; float max = corners[2].y + itemSize; for (int i = 0, imax = mChildren.Count; i < imax; ++i) { Transform t = mChildren[i]; if (mFirstTime) { UpdateItem(t, i); continue; } 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 / itemSize); if (minIndex == maxIndex || (minIndex <= realIndex && realIndex <= maxIndex)) { t.localPosition = pos; UpdateItem(t, Mathf.Abs(realIndex)); t.name = realIndex.ToString(); } else { allWithinRange = false; } } else if (distance > extents) { Vector3 pos = t.localPosition; pos.y -= ext2; distance = pos.y - center.y; int realIndex = Mathf.RoundToInt(pos.y / itemSize); if (minIndex == maxIndex || (minIndex <= realIndex && realIndex <= maxIndex)) { t.localPosition = pos; UpdateItem(t, Mathf.Abs(realIndex)); t.name = realIndex.ToString(); } else { allWithinRange = false; } } //else if (mFirstTime) UpdateItem(t, i); if (cullContent) { distance += mPanel.clipOffset.y - mTrans.localPosition.y; if (!UICamera.IsPressed(t.gameObject)) { NGUITools.SetActive(t.gameObject, (distance > min && distance < max), false); } } } } mScroll.restrictWithinPanel = !allWithinRange; }
public void WrapContent() { Vector3[] corners = m_Panel.worldCorners; for (int i = 0; i < 4; ++i) { Vector3 v = corners[i]; v = m_Trans.InverseTransformPoint(v); corners[i] = v; } Vector3 center = Vector3.Lerp(corners[0], corners[2], 0.5f); bool allWithinRange = true; float ext2 = m_Extents * 2f; if (m_Horizontal) { float min = corners[0].x - itemSize; float max = corners[2].x + itemSize; for (int i = 0, imax = m_Children.Count; i < imax && i < m_CurUseCount; ++i) { Transform t = m_Children[i]; float distance = t.localPosition.x - center.x; if (distance < -m_Extents) { Vector3 pos = t.localPosition; pos.x += ext2; distance = pos.x - center.x; int realIndex = Mathf.RoundToInt(pos.x / itemSize); int sortIndex = Mathf.RoundToInt((pos.y - m_FirstPoint.y) / itemInterval); realIndex = realIndex * maxPerLine + sortIndex; if (minIndex == maxIndex || (minIndex <= realIndex && realIndex <= maxIndex)) { t.localPosition = pos; UpdateItem(t, i); } else { allWithinRange = false; } } else if (distance > m_Extents) { Vector3 pos = t.localPosition; pos.x -= ext2; distance = pos.x - center.x; int realIndex = Mathf.RoundToInt(pos.x / itemSize); //--mxh int sortIndex = Mathf.RoundToInt((pos.y - m_FirstPoint.y) / itemInterval); realIndex = realIndex * maxPerLine + sortIndex; if (minIndex == maxIndex || (minIndex <= realIndex && realIndex <= maxIndex)) { t.localPosition = pos; UpdateItem(t, i); } else { allWithinRange = false; } } else if (m_FirstTime) { UpdateItem(t, i); } if (cullContent) { distance += m_Panel.clipOffset.x - m_Trans.localPosition.x; if (!UICamera.IsPressed(t.gameObject)) { NGUITools.SetActive(t.gameObject, (distance > min && distance < max), false); } } } } else { float min = corners[0].y - itemSize; float max = corners[2].y + itemSize; for (int i = 0, imax = m_Children.Count; i < imax && i < m_CurUseCount; ++i) { Transform t = m_Children[i]; float distance = t.localPosition.y - center.y; if (distance > m_Extents) { Vector3 pos = t.localPosition; pos.y -= ext2; //zheng //pos.y += ext2; distance = pos.y - center.y; int realIndex = Mathf.RoundToInt(pos.y / itemSize); int sortIndex = Mathf.RoundToInt((pos.x - m_FirstPoint.x) / itemInterval); realIndex = -realIndex * maxPerLine + sortIndex; if (minIndex == maxIndex || (minIndex <= realIndex && realIndex <= maxIndex)) { t.localPosition = pos; UpdateItem(t, i); } else { allWithinRange = false; } } else if (distance < -m_Extents) { Vector3 pos = t.localPosition; pos.y += ext2; if (pos.y > 0) { } distance = pos.y - center.y; int realIndex = Mathf.RoundToInt(pos.y / itemSize); int sortIndex = Mathf.RoundToInt((pos.x - m_FirstPoint.x) / itemInterval); realIndex = -realIndex * maxPerLine + sortIndex; if (minIndex == maxIndex || (minIndex <= realIndex && realIndex <= maxIndex)) { t.localPosition = pos; UpdateItem(t, i); } else { allWithinRange = false; } } else if (m_FirstTime) { UpdateItem(t, i); } if (cullContent) { distance += m_Panel.clipOffset.y - m_Trans.localPosition.y; if (!UICamera.IsPressed(t.gameObject)) { NGUITools.SetActive(t.gameObject, (distance > min && distance < max), false); } } } } m_Scroll.restrictWithinPanel = !allWithinRange; }