/// <summary> /// Recalculate the position of all elements within the table, sorting them alphabetically if necessary. /// </summary> public void Reposition() { if (mStarted) { Transform myTrans = transform; mChildren.Clear(); List <Transform> ch = children; if (ch.Count > 0) { RepositionVariableSize(ch); } if (mDrag != null) { mDrag.UpdateScrollbars(true); mDrag.RestrictWithinBounds(true); } else if (mPanel != null) { mPanel.ConstrainTargetToBounds(myTrans, true); } if (onReposition != null) { onReposition(); } } else { repositionNow = true; } }
/// <summary> /// Advance toward the target position. /// </summary> void Update() { float delta = UpdateRealTimeDelta(); if (mThreshold == 0f) { mThreshold = (target - mTrans.localPosition).magnitude * 0.005f; } bool trigger = false; Vector3 before = mTrans.localPosition; Vector3 after = NGUIMath.SpringLerp(mTrans.localPosition, target, strength, delta); if (mThreshold >= Vector3.Magnitude(after - target)) { after = target; enabled = false; trigger = true; } mTrans.localPosition = after; Vector3 offset = after - before; Vector4 cr = mPanel.clipRange; cr.x -= offset.x; cr.y -= offset.y; mPanel.clipRange = cr; if (mDrag != null) { mDrag.UpdateScrollbars(false); } if (trigger && onFinished != null) { onFinished(); } }
/// <summary> /// Recalculate the position of all elements within the grid, sorting them alphabetically if necessary. /// </summary> public void Reposition() { if (!mStarted) { repositionNow = true; return; } Transform myTrans = transform; int x = 0; int y = 0; if (sorted) { List <Transform> list = new List <Transform>(); for (int i = 0; i < myTrans.childCount; ++i) { Transform t = myTrans.GetChild(i); if (t && (!hideInactive || NGUITools.GetActive(t.gameObject))) { list.Add(t); } } list.Sort(SortByName); for (int i = 0, imax = list.Count; i < imax; ++i) { Transform t = list[i]; if (!NGUITools.GetActive(t.gameObject) && hideInactive) { continue; } float depth = t.localPosition.z; t.localPosition = (arrangement == Arrangement.Horizontal) ? new Vector3(cellWidth * x, -cellHeight * y, depth) : new Vector3(cellWidth * y, -cellHeight * x, depth); if (++x >= maxPerLine && maxPerLine > 0) { x = 0; ++y; } } } else { for (int i = 0; i < myTrans.childCount; ++i) { Transform t = myTrans.GetChild(i); if (!NGUITools.GetActive(t.gameObject) && hideInactive) { continue; } float depth = t.localPosition.z; t.localPosition = (arrangement == Arrangement.Horizontal) ? new Vector3(cellWidth * x, -cellHeight * y, depth) : new Vector3(cellWidth * y, -cellHeight * x, depth); if (++x >= maxPerLine && maxPerLine > 0) { x = 0; ++y; } } } NGUIDraggablePanel drag = NGUITools.FindInParents <NGUIDraggablePanel>(gameObject); if (drag != null) { drag.UpdateScrollbars(true); } }