public UITableMessage(UITable uiTable) : base(uiTable) { Columns = uiTable.columns; Direction = uiTable.direction; Sorting = uiTable.sorting; Pivot = uiTable.pivot; CellAlignment = uiTable.cellAlignment; HideInactive = uiTable.hideInactive; KeepWithinPanel = uiTable.keepWithinPanel; Padding = uiTable.padding; }
public override void Deserialize(BinaryReader br) { base.Deserialize(br); Columns = br.ReadInt32(); Direction = (UITable.Direction)br.ReadInt32(); Sorting = (UITable.Sorting)br.ReadInt32(); Pivot = (UIWidget.Pivot)br.ReadInt32(); CellAlignment = (UIWidget.Pivot)br.ReadInt32(); HideInactive = br.ReadBoolean(); KeepWithinPanel = br.ReadBoolean(); Padding = br.ReadVector2(); }
static int get_direction(IntPtr L) { object o = null; try { o = ToLua.ToObject(L, 1); UITable obj = (UITable)o; UITable.Direction ret = obj.direction; ToLua.Push(L, ret); return(1); } catch (Exception e) { return(LuaDLL.toluaL_exception(L, e, o, "attempt to index direction on a nil value")); } }
static int set_direction(IntPtr L) { object o = null; try { o = ToLua.ToObject(L, 1); UITable obj = (UITable)o; UITable.Direction arg0 = (UITable.Direction)ToLua.CheckObject(L, 2, typeof(UITable.Direction)); obj.direction = arg0; return(0); } catch (Exception e) { return(LuaDLL.toluaL_exception(L, e, o, "attempt to index direction on a nil value")); } }
public override void Unity_Deserialize(int depth) { this.columns = SerializedStateReader.Instance.ReadInt32(); this.direction = (UITable.Direction)SerializedStateReader.Instance.ReadInt32(); this.sorting = (UITable.Sorting)SerializedStateReader.Instance.ReadInt32(); this.pivot = (UIWidget.Pivot)SerializedStateReader.Instance.ReadInt32(); this.cellAlignment = (UIWidget.Pivot)SerializedStateReader.Instance.ReadInt32(); this.hideInactive = SerializedStateReader.Instance.ReadBoolean(); SerializedStateReader.Instance.Align(); this.keepWithinPanel = SerializedStateReader.Instance.ReadBoolean(); SerializedStateReader.Instance.Align(); if (depth <= 7) { this.padding.Unity_Deserialize(depth + 1); } SerializedStateReader.Instance.Align(); }
private static int set_direction(IntPtr L) { object obj = null; int result; try { obj = ToLua.ToObject(L, 1); UITable uITable = (UITable)obj; UITable.Direction direction = (UITable.Direction)((int)ToLua.CheckObject(L, 2, typeof(UITable.Direction))); uITable.direction = direction; result = 0; } catch (Exception ex) { result = LuaDLL.toluaL_exception(L, ex, (obj != null) ? ex.Message : "attempt to index direction on a nil value"); } return(result); }
private static int get_direction(IntPtr L) { object obj = null; int result; try { obj = ToLua.ToObject(L, 1); UITable uITable = (UITable)obj; UITable.Direction direction = uITable.direction; ToLua.Push(L, direction); result = 1; } catch (Exception ex) { result = LuaDLL.toluaL_exception(L, ex, (obj != null) ? ex.Message : "attempt to index direction on a nil value"); } return(result); }
public unsafe override void Unity_NamedDeserialize(int depth) { ISerializedNamedStateReader arg_1A_0 = SerializedNamedStateReader.Instance; byte[] var_0_cp_0 = $FieldNamesStorage.$RuntimeNames; int var_0_cp_1 = 0; this.columns = arg_1A_0.ReadInt32(&var_0_cp_0[var_0_cp_1] + 1879); this.direction = (UITable.Direction)SerializedNamedStateReader.Instance.ReadInt32(&var_0_cp_0[var_0_cp_1] + 1639); this.sorting = (UITable.Sorting)SerializedNamedStateReader.Instance.ReadInt32(&var_0_cp_0[var_0_cp_1] + 940); this.pivot = (UIWidget.Pivot)SerializedNamedStateReader.Instance.ReadInt32(&var_0_cp_0[var_0_cp_1] + 697); this.cellAlignment = (UIWidget.Pivot)SerializedNamedStateReader.Instance.ReadInt32(&var_0_cp_0[var_0_cp_1] + 1887); this.hideInactive = SerializedNamedStateReader.Instance.ReadBoolean(&var_0_cp_0[var_0_cp_1] + 996); SerializedNamedStateReader.Instance.Align(); this.keepWithinPanel = SerializedNamedStateReader.Instance.ReadBoolean(&var_0_cp_0[var_0_cp_1] + 1009); SerializedNamedStateReader.Instance.Align(); if (depth <= 7) { SerializedNamedStateReader.Instance.BeginMetaGroup(&var_0_cp_0[var_0_cp_1] + 1353); this.padding.Unity_NamedDeserialize(depth + 1); SerializedNamedStateReader.Instance.EndMetaGroup(); } SerializedNamedStateReader.Instance.Align(); }
/// <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(); }
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); } }
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; } }
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; } }
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(); }
// 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 setPosition(CLUILoopTableCell movement, CLUILoopTableCell target, UITable.Direction direction) { Vector3 v3Offset = Vector3.zero; int flag = 1; if (table.columns == 1) { if (direction == UITable.Direction.Down) { flag = -1; switch (table.cellAlignment) { case UIWidget.Pivot.Bottom: v3Offset = new Vector3(0, flag * (movement.widget.height + mOffset.y + (table.padding.y) * 2), 0); break; case UIWidget.Pivot.BottomLeft: v3Offset = new Vector3(0, flag * (movement.widget.height + mOffset.y + (table.padding.y) * 2), 0); break; case UIWidget.Pivot.BottomRight: v3Offset = new Vector3(0, flag * (movement.widget.height + mOffset.y + (table.padding.y) * 2), 0); break; case UIWidget.Pivot.Center: v3Offset = new Vector3(0, flag * ((movement.widget.height + target.widget.height) / 2.0f + mOffset.y + (table.padding.y) * 2), 0); break; case UIWidget.Pivot.Left: v3Offset = new Vector3(0, flag * ((movement.widget.height + target.widget.height) / 2.0f + mOffset.y + (table.padding.y) * 2), 0); break; case UIWidget.Pivot.Right: v3Offset = new Vector3(0, flag * ((movement.widget.height + target.widget.height) / 2.0f + mOffset.y + (table.padding.y) * 2), 0); break; case UIWidget.Pivot.Top: v3Offset = new Vector3(0, flag * (target.widget.height + mOffset.y + (table.padding.y) * 2), 0); break; case UIWidget.Pivot.TopLeft: v3Offset = new Vector3(0, flag * (target.widget.height + mOffset.y + (table.padding.y) * 2), 0); break; case UIWidget.Pivot.TopRight: v3Offset = new Vector3(0, flag * (target.widget.height + mOffset.y + (table.padding.y) * 2), 0); break; } } else { flag = 1; switch (table.cellAlignment) { case UIWidget.Pivot.Bottom: v3Offset = new Vector3(0, flag * (target.widget.height + mOffset.y + (table.padding.y) * 2), 0); break; case UIWidget.Pivot.BottomLeft: v3Offset = new Vector3(0, flag * (target.widget.height + mOffset.y + (table.padding.y) * 2), 0); break; case UIWidget.Pivot.BottomRight: v3Offset = new Vector3(0, flag * (target.widget.height + mOffset.y + (table.padding.y) * 2), 0); break; case UIWidget.Pivot.Center: v3Offset = new Vector3(0, flag * ((movement.widget.height + target.widget.height) / 2.0f + mOffset.y + (table.padding.y) * 2), 0); break; case UIWidget.Pivot.Left: v3Offset = new Vector3(0, flag * ((movement.widget.height + target.widget.height) / 2.0f + mOffset.y + (table.padding.y) * 2), 0); break; case UIWidget.Pivot.Right: v3Offset = new Vector3(0, flag * ((movement.widget.height + target.widget.height) / 2.0f + mOffset.y + (table.padding.y) * 2), 0); break; case UIWidget.Pivot.Top: v3Offset = new Vector3(0, flag * (movement.widget.height + mOffset.y + (table.padding.y) * 2), 0); break; case UIWidget.Pivot.TopLeft: v3Offset = new Vector3(0, flag * (movement.widget.height + mOffset.y + (table.padding.y) * 2), 0); break; case UIWidget.Pivot.TopRight: v3Offset = new Vector3(0, flag * (movement.widget.height + mOffset.y + (table.padding.y) * 2), 0); break; } } } else if (table.columns == 0) { flag = 1; if (direction == UITable.Direction.Down) { switch (table.cellAlignment) { case UIWidget.Pivot.Bottom: v3Offset = new Vector3(flag * ((target.widget.width + movement.widget.width) / 2.0f + mOffset.x + (table.padding.x) * 2), 0, 0); break; case UIWidget.Pivot.BottomLeft: v3Offset = new Vector3(flag * (target.widget.width + mOffset.x + (table.padding.x) * 2), 0, 0); break; case UIWidget.Pivot.BottomRight: v3Offset = new Vector3(flag * (movement.widget.width + mOffset.x + (table.padding.x) * 2), 0, 0); break; case UIWidget.Pivot.Center: v3Offset = new Vector3(flag * ((target.widget.width + movement.widget.width) / 2.0f + mOffset.x + (table.padding.x) * 2), 0, 0); break; case UIWidget.Pivot.Left: v3Offset = new Vector3(flag * (target.widget.width + mOffset.x + (table.padding.x) * 2), 0, 0); break; case UIWidget.Pivot.Right: v3Offset = new Vector3(flag * (movement.widget.width + mOffset.x + (table.padding.x) * 2), 0, 0); break; case UIWidget.Pivot.Top: v3Offset = new Vector3(flag * ((target.widget.width + movement.widget.width) / 2.0f + mOffset.x + (table.padding.x) * 2), 0, 0); break; case UIWidget.Pivot.TopLeft: v3Offset = new Vector3(flag * (target.widget.width + mOffset.x + (table.padding.x) * 2), 0, 0); break; case UIWidget.Pivot.TopRight: v3Offset = new Vector3(flag * (movement.widget.width + mOffset.x + (table.padding.x) * 2), 0, 0); break; } } else { flag = -1; switch (table.cellAlignment) { case UIWidget.Pivot.Bottom: v3Offset = new Vector3(flag * ((target.widget.width + movement.widget.width) / 2.0f + mOffset.x + (table.padding.x) * 2), 0, 0); break; case UIWidget.Pivot.BottomLeft: v3Offset = new Vector3(flag * (movement.widget.width + mOffset.x + (table.padding.x) * 2), 0, 0); break; case UIWidget.Pivot.BottomRight: v3Offset = new Vector3(flag * (target.widget.width + mOffset.x + (table.padding.x) * 2), 0, 0); break; case UIWidget.Pivot.Center: v3Offset = new Vector3(flag * ((target.widget.width + movement.widget.width) / 2.0f + mOffset.x + (table.padding.x) * 2), 0, 0); break; case UIWidget.Pivot.Left: v3Offset = new Vector3(flag * (movement.widget.width + mOffset.x + (table.padding.x) * 2), 0, 0); break; case UIWidget.Pivot.Right: v3Offset = new Vector3(flag * (target.widget.width + mOffset.x + (table.padding.x) * 2), 0, 0); break; case UIWidget.Pivot.Top: v3Offset = new Vector3(flag * ((target.widget.width + movement.widget.width) / 2.0f + mOffset.x + (table.padding.x) * 2), 0, 0); break; case UIWidget.Pivot.TopLeft: v3Offset = new Vector3(flag * (movement.widget.width + mOffset.x + (table.padding.x) * 2), 0, 0); break; case UIWidget.Pivot.TopRight: v3Offset = new Vector3(flag * (target.widget.width + mOffset.x + (table.padding.x) * 2), 0, 0); break; } } } else { Debug.LogError("The loop table cannot suport this setting! columes must in (0, 1)"); } movement.transform.localPosition = target.transform.localPosition + v3Offset; }
void _insertList(ArrayList list, bool isCalculatePosition) { if (list.Count == 0) { return; } int dataIndex = list.Count - 1; // int tmpIndex = itemList.Count; CLUILoopTableCell uiw = null; CLUILoopTableCell targetUIW = null; Transform t = null; for (int i = 0; i < cachedTransform.childCount; i++) { if (dataIndex < 0) { 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(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 [0]; UITable.Direction dir = table.direction; if (table.direction == UITable.Direction.Up) { dir = UITable.Direction.Down; } else { dir = UITable.Direction.Up; } setPosition(uiw, targetUIW, dir); } } itemList.Insert(0, uiw); dataIndex--; } }