// void LateUpdate () void Update() { if (itemList.Count < 3) { return; } sourceIndex = -1; targetIndex = -1; // sign = 0; head = itemList [0]; tail = itemList [itemList.Count - 1]; checkHead = itemList [1]; checkTail = itemList [itemList.Count - 2]; firstVislable = checkHead.widget.isVisible; lastVisiable = checkTail.widget.isVisible; // if first and last both visiable or invisiable then return if (firstVislable == lastVisiable) { return; } if (firstVislable && int.Parse(head.name) > 0) { isCanCallOnEndList = true; times--; // move last to first one sourceIndex = itemList.Count - 1; targetIndex = 0; forward = false; } else if (lastVisiable && int.Parse(tail.name) < list.Count - 1) { isCanCallOnEndList = true; times++; // move first to last one sourceIndex = 0; targetIndex = itemList.Count - 1; forward = true; } else if (lastVisiable && int.Parse(tail.name) == list.Count - 1) { //说明已经到最后了 if (isCanCallOnEndList) { isCanCallOnEndList = false; #if UNITY_EDITOR Debug.Log("说明已经到最后了"); #endif Utl.doCallback(this.onEndListCallback); } } else { isCanCallOnEndList = true; } if (sourceIndex > -1) { movedWidget = itemList [sourceIndex]; if (forward) { // movedWidget.name = string.Format ("{0:D5}",); movedWidget.name = NumEx.nStrForLen(NumEx.stringToInt(tail.name) + 1, 6); // movedWidget.name = NumEx.nStrForLen( ((times - 1) / RealCellCount + 1) * RealCellCount + int.Parse (movedWidget.name) % RealCellCount, 6); } else { movedWidget.name = NumEx.nStrForLen(NumEx.stringToInt(head.name) - 1, 6); // movedWidget.name = string.Format ("{0:D5}", ((times) / RealCellCount) * RealCellCount + int.Parse (movedWidget.name) % RealCellCount); // movedWidget.name = NumEx.nStrForLen(((times) / RealCellCount) * RealCellCount + int.Parse (movedWidget.name) % RealCellCount, 6); } int index = int.Parse(movedWidget.name); Utl.doCallback(this.initCellCallback, movedWidget.GetComponent <CLCellBase> (), this.list [index]); // ***after init call, then set the position*** if (movedWidget.isSetWidgetSize) { _boxCollidr = movedWidget.GetComponent <BoxCollider> (); if (_boxCollidr != null) { _boxCollidr.size = Vector2.zero; } movedWidget.widget.SetDimensions(0, 0); } NGUITools.updateAll(movedWidget.transform); if (movedWidget.isSetWidgetSize) { _bound = NGUIMath.CalculateRelativeWidgetBounds(movedWidget.transform, false); movedWidget.widget.SetDimensions((int)(_bound.size.x), (int)(_bound.size.y)); } targetWidget = itemList [targetIndex]; if (forward) { setPosition(movedWidget, targetWidget, table.direction); } else { UITable.Direction dir = table.direction; if (table.direction == UITable.Direction.Up) { dir = UITable.Direction.Down; } else { dir = UITable.Direction.Up; } setPosition(movedWidget, targetWidget, dir); } // change item index itemList.RemoveAt(sourceIndex); itemList.Insert(targetIndex, movedWidget); } }
void _setList(object data, object initCellCallback, object onEndListCallback, bool isNeedRePosition, bool isCalculatePosition = false) { ArrayList _list = null; if (data == null) { _list = new ArrayList(); } else if (data is LuaTable) { _list = CLUtlLua.luaTableVals2List((LuaTable)data); } else if (data is ArrayList) { _list = (ArrayList)data; } else if (data is object[]) { _list = new ArrayList(); _list.AddRange((object[])data); } else { _list = new ArrayList(); } try { this.data = data; this.list = _list; this.initCellCallback = initCellCallback; this.onEndListCallback = onEndListCallback; if (!isFinishInit) { init(); } int tmpIndex = 0; times = 0; itemList.Clear(); for (int i = 0; i < cachedTransform.childCount; ++i) { Transform t = cachedTransform.GetChild(i); CLUILoopTableCell uiw = t.GetComponent <CLUILoopTableCell> (); tmpIndex = i; // uiw.name = string.Format ("{0:D5}", tmpIndex); uiw.name = NumEx.nStrForLen(tmpIndex, 6); if (tmpIndex >= 0 && tmpIndex < this.list.Count) { NGUITools.SetActive(t.gameObject, true); Utl.doCallback(this.initCellCallback, t.GetComponent <CLCellBase> (), list [tmpIndex]); if (uiw.isSetWidgetSize) { BoxCollider box = uiw.GetComponent <BoxCollider> (); if (box != null) { box.size = Vector2.zero; } uiw.widget.SetDimensions(0, 0); } NGUITools.updateAll(uiw.transform); if (uiw.isSetWidgetSize) { Bounds bound = NGUIMath.CalculateRelativeWidgetBounds(t, false); uiw.widget.SetDimensions((int)(bound.size.x), (int)(bound.size.y)); } if (!isNeedRePosition) { if (itemList.Count > 0) { CLUILoopTableCell targetUIW = itemList [itemList.Count - 1]; setPosition(uiw, targetUIW, table.direction); } } itemList.Add(uiw); } else { NGUITools.SetActive(t.gameObject, false); } } if (isNeedRePosition) { resetClip(); table.Reposition(); if (scrollView != null) { scrollView.ResetPosition(); } } } catch (System.Exception e) { Debug.LogError(e); } }
void _appendList(ArrayList list, bool isCalculatePosition) { if (list.Count == 0) { return; } int dataIndex = 0; int tmpIndex = itemList.Count; CLUILoopTableCell uiw = null; CLUILoopTableCell targetUIW = null; Transform t = null; for (int i = 0; i < cachedTransform.childCount; i++) { if (dataIndex >= list.Count) { break; } t = cachedTransform.GetChild(i); if (t.gameObject.activeSelf) { continue; } uiw = t.GetComponent <CLUILoopTableCell> (); if (uiw == null) { continue; } // uiw.name = string.Format ("{0:D5}", (tmpIndex + dataIndex)); uiw.name = NumEx.nStrForLen(tmpIndex + dataIndex, 6); NGUITools.SetActive(t.gameObject, true); Utl.doCallback(this.initCellCallback, t.GetComponent <CLCellBase> (), list [dataIndex]); if (uiw.isSetWidgetSize) { BoxCollider box = uiw.GetComponent <BoxCollider> (); if (box != null) { box.size = Vector2.zero; } uiw.widget.SetDimensions(0, 0); } NGUITools.updateAll(uiw.transform); if (uiw.isSetWidgetSize) { Bounds bound = NGUIMath.CalculateRelativeWidgetBounds(t, false); uiw.widget.SetDimensions((int)(bound.size.x), (int)(bound.size.y)); } if (isCalculatePosition) { if (itemList.Count > 0) { targetUIW = itemList [itemList.Count - 1]; setPosition(uiw, targetUIW, table.direction); } } itemList.Add(uiw); dataIndex++; } }
public void refreshContentOnly(object data, bool isRePositionTable) { ArrayList _list = null; if (data == null) { _list = new ArrayList(); } else if (data is LuaTable) { _list = CLUtlLua.luaTableVals2List((LuaTable)data); } else if (data is ArrayList) { _list = (ArrayList)data; } else if (data is object[]) { _list = new ArrayList(); _list.AddRange((object[])data); } else { _list = new ArrayList(); } list = _list; if (RealCellCount > itemList.Count) { setList(list, this.initCellCallback); } else { Transform t = null; int tmpIndex = 0; CLUILoopTableCell cell = null; CLUILoopTableCell preCell = null; //for (int i = 0; i < cachedTransform.childCount; ++i) { for (int i = 0; i < itemList.Count; i++) { //t = cachedTransform.GetChild (i); cell = itemList[i]; if (!cell.gameObject.activeSelf) { continue; } tmpIndex = int.Parse(cell.name); //cell = t.GetComponent<CLUILoopTableCell> (); if (cell != null) { Utl.doCallback(this.initCellCallback, cell, list [tmpIndex]); } if (cell.isSetWidgetSize) { BoxCollider box = cell.GetComponent <BoxCollider>(); if (box != null) { box.size = Vector2.zero; } cell.widget.SetDimensions(0, 0); } NGUITools.updateAll(cell.transform); if (cell.isSetWidgetSize) { Bounds bound = NGUIMath.CalculateRelativeWidgetBounds(t, false); cell.widget.SetDimensions((int)(bound.size.x), (int)(bound.size.y)); } if (isRePositionTable) { if (preCell != null) { setPosition(cell, preCell, table.direction); } } preCell = cell; } } }