private void DelItemFromPanel <T>(int index, T item) where T : WndItem { int maxIndex = -1; int minIndex = int.MaxValue; for (int i = _itemList.Count; i > 0; i--) { UIMultiScrollIndex cell = _itemList[i - 1]; if (cell.Index == index) { GameObject.Destroy(item.gameObject); _itemList.Remove(cell); } if (cell.Index > maxIndex) { maxIndex = cell.Index; } if (cell.Index < minIndex) { minIndex = cell.Index; } if (cell.Index > index) { cell.Index -= 1; } } if (maxIndex < DataCount - 1) { CreateItem(maxIndex, item); } }
private void DelItemFromPanel(int index) { int maxIndex = -1; int minIndex = int.MaxValue; for (int i = _itemList.Count; i > 0; i--) { UIMultiScrollIndex item = _itemList[i - 1]; if (item.Index == index) { GameObject.Destroy(item.gameObject); _itemList.Remove(item); } if (item.Index > maxIndex) { maxIndex = item.Index; } if (item.Index < minIndex) { minIndex = item.Index; } if (item.Index > index) { item.Index -= 1; } } if (maxIndex < DataCount - 1) { CreateItem(maxIndex); } }
private void CreateItem(int index) { if (lastItemPrefab != itemPrefab) { while (_unUsedQueue.Count > 0) { UIMultiScrollIndex idx = _unUsedQueue.Pop(); Destroy(idx.gameObject); } } lastItemPrefab = itemPrefab; UIMultiScrollIndex itemBase; if (_unUsedQueue.Count > 0) { itemBase = _unUsedQueue.Pop(); } else { itemBase = UIMultiScrollIndex.Get(AddChild(_content, itemPrefab)); } if (_Tween) { itemBase.Movement = _movement; if (_movement == Arrangement.Vertical) { int x = cellWidth * maxPerLine; if (Type == _type.False) { x = -x; } itemBase.IstweenPosition = new Vector2(x, cellHeight); } else { int y = cellHeight * maxPerLine; if (Type == _type.False) { y = -y; } itemBase.IstweenPosition = new Vector2(cellWidth, y); } } if (test) { itemBase.gameObject.gameObject.SetActive(true); } else { itemBase.gameObject.SetActive(false); TempList.Add(itemBase); //RefreshIconCallback (itemBase.gameObject, index); } //itemBase.gameObject.SetActive(true); itemBase.Scroller = this; itemBase.Index = index; _itemList.Add(itemBase); }
public static UIMultiScrollIndex Get(GameObject obj) { UIMultiScrollIndex index = obj.GetComponent <UIMultiScrollIndex>(); if (index == null) { index = obj.AddComponent <UIMultiScrollIndex>(); } return(index); }
public void OnValueChange(Vector2 pos) { if (null != OnScrollChange) { OnScrollChange(); } if (null != ScrollRectGo) { ScrollBarDelayDis(); } int index = GetPosIndex(); if (_index != index && index > -1) { _index = index; for (int i = _itemList.Count; i > 0; i--) { UIMultiScrollIndex item = _itemList[i - 1]; if (item.Index < index * maxPerLine || (item.Index >= (index + viewCount) * maxPerLine)) { //GameObject.Destroy(item.gameObject); _itemList.Remove(item); _unUsedQueue.Enqueue(item); } } for (int i = _index * maxPerLine; i < (_index + viewCount) * maxPerLine; i++) { if (i < 0) { continue; } if (i > _dataCount - 1) { continue; } bool isOk = false; foreach (UIMultiScrollIndex item in _itemList) { if (item.Index == i) { isOk = true; } } if (isOk) { continue; } int Index = i; OnCreateItem(Index); } } }
private void AddItemIntoPanel(int index) { for (int i = 0; i < _itemList.Count; i++) { UIMultiScrollIndex item = _itemList[i]; if (item.Index >= index) { item.Index += 1; } } CreateItem(index); }
public GameObject GetItem(int index) { for (int i = _itemList.Count; i > 0; i--) { UIMultiScrollIndex item = _itemList[i - 1]; if (item.Index == index) { return(item.gameObject); } } return(null); }
private void AddItemIntoPanel <T>(int index, T item) where T : WndItem { for (int i = 0; i < _itemList.Count; i++) { UIMultiScrollIndex cell = _itemList[i]; if (cell.Index >= index) { cell.Index += 1; } } CreateItem(index, item); }
public void OnValueChange(Vector2 pos) { if (_itemList == null) { return; } int index = GetPosIndex(); if (_index != index && index > -1) { _index = index; for (int i = _itemList.Count; i > 0; i--) { UIMultiScrollIndex item = _itemList[i - 1]; if (item.Index < index * maxPerLine || (item.Index >= (index + viewCount) * maxPerLine)) { //GameObject.Destroy(item.gameObject); _itemList.Remove(item); _unUsedQueue.Enqueue(item); item.gameObject.SetActive(false); } } for (int i = _index * maxPerLine; i < (_index + viewCount) * maxPerLine; i++) { if (i < 0) { continue; } if (i > _dataCount - 1) { continue; } bool isOk = false; foreach (UIMultiScrollIndex item in _itemList) { if (item.Index == i) { isOk = true; } } if (isOk) { continue; } CreateItem(i); } } }
/* * void ShowItems () * { * for (int i = 0; i < DataCount; i++) { * if (i < maxViewCount) { * //yield return new WaitForSeconds(0.1f); * AddItem(i); * Debug.Log("item: "+ i); * } * } * //yield return new WaitForSeconds(0.1f); * } */ public void OnValueChange(Vector2 pos) { int index = GetPosIndex(); //if (_index != index && index >= -1 && index < DataCount-(viewCount -2)) if (_index != index && _itemList != null) { _index = index; for (int i = _itemList.Count; i > 0; i--) { UIMultiScrollIndex item = _itemList[i - 1]; if (item.Index < index * maxPerLine || (item.Index >= (index + viewCount) * maxPerLine)) { //GameObject.Destroy(item.gameObject); item.gameObject.SetActive(false); item.transform.localPosition = new Vector3(-cellWidth, cellHeight, 0); _itemList.Remove(item); _unUsedQueue.Push(item); } } for (int i = _index * maxPerLine; i < (_index + viewCount) * maxPerLine; i++) { if (i < 0) { continue; } if (i > _dataCount - 1) { continue; } bool isOk = false; foreach (UIMultiScrollIndex item in _itemList) { if (item.Index == i) { isOk = true; } } if (isOk) { continue; } CreateItem(i); } } }
public void Clear() { if (null != _itemList) { for (int i = 0; i < _itemList.Count; i++) { DestroyImmediate(_itemList[i].gameObject); } _itemList.Clear(); } if (null != _content) { foreach (Transform item in _content.transform) { DestroyImmediate(item.gameObject); } } if (null != _unUsedQueue) { for (int i = _unUsedQueue.Count; i > 0; i--) { UIMultiScrollIndex item = _unUsedQueue.Dequeue(); if (null != item) { DestroyImmediate(item); } } _unUsedQueue.Clear(); } _index = -1; _dataCount = 0; UpdateTotalWidth(); }
public void ItemRef(int value = -1) { if (value > 0) { if (_dataCount == 0) { SetDataCount(value); } else { //Debug.LogError (_itemList.Count); // int tempCount = _dataCount; _dataCount = value; TempList.Clear(); UpdateTotalWidth(); for (int i = _itemList.Count; i > 0; i--) { UIMultiScrollIndex item = _itemList[i - 1]; // if (item.Index < _index * maxPerLine || (item.Index >= (_index + viewCount) * maxPerLine)) //{ //GameObject.Destroy(item.gameObject); //if (i > _dataCount) //{ //} item.gameObject.SetActive(false); item.transform.localPosition = new Vector3(-cellWidth, cellHeight, 0); _itemList.Remove(item); _unUsedQueue.Push(item); // } } for (int i = _index * maxPerLine; i < (_index + viewCount) * maxPerLine; i++) { if (i < 0) { continue; } if (i > _dataCount - 1) { continue; } CreateItem(i); _itemList[_itemList.Count - 1].transform.localPosition = GetPosition(_itemList[_itemList.Count - 1].Index); } //OnValueChange(Vector2.zero); // if (tempCount > value) // { // for (int i = 0; i < _itemList.Count; i++) // { // //Debug.LogError (_itemList [i].Index + " " + _dataCount); // if (_itemList[i].Index < value) // { // _itemList[i].transform.localPosition = GetPosition(_itemList[i].Index); // RefreshIconCallback(_itemList[i].gameObject, _itemList[i].Index); // } // else // { // _itemList[i].gameObject.SetActive(false); // Debug.Log(i + "_itemList[i]: " + _itemList[i].Index); // _unUsedQueue.Push(_itemList[i]); // _itemList.Remove(_itemList[i]); // i--; // //DelItem(_itemList[i].Index); // //_itemList [i].gameObject.SetActive (false); // //_unUsedQueue.Enqueue (_itemList [i]); // //_itemList.Remove (_itemList [i]); // } // } // } // else // { // //for (int i = 0; i < _itemList.Count; i++) // //{ // // RefreshIconCallback(_itemList[i].gameObject, _itemList[i].Index); // //} // for (int i = _itemList.Count; i > 0; i--) // { // UIMultiScrollIndex item = _itemList[i - 1]; // // if (item.Index < _index * maxPerLine || (item.Index >= (_index + viewCount) * maxPerLine)) // //{ // //GameObject.Destroy(item.gameObject); // item.gameObject.SetActive(false); // _itemList.Remove(item); // _unUsedQueue.Push(item); // // } // } // for (int i = _index * maxPerLine; i < (_index + viewCount) * maxPerLine; i++) // { // if (i < 0) continue; // if (i > _dataCount - 1) continue; // CreateItem(i); // } // } } } else if (value == -1) { for (int i = 0; i < _itemList.Count; i++) { //_itemList [i].gameObject.SetActive (false); //TempList.Add (_itemList[i]); RefreshIconCallback(_itemList[i].gameObject, _itemList[i].Index); } } else { SetDataCount(value); } }