public void RefreshItem(int index) { if (index >= this.itemList.Count || index < 0) { return; } ListView.ListItem listItem = this.itemList[index]; this.ShowItem(listItem, true); float num = Mathf.Abs(listItem.endPos - listItem.startPos); float itemSize = this.GetItemSize(listItem); listItem.endPos = this.m_isPositive ? (listItem.startPos + itemSize) : (listItem.startPos - itemSize); float num2 = itemSize - num; this.totalSize += num2; this.SetContainerSize(this.totalSize); for (int i = index + 1; i < this.itemList.Count; i++) { ListView.ListItem listItem2 = this.itemList[i]; listItem2.startPos = this.m_isPositive ? (listItem2.startPos + num2) : (listItem2.startPos - num2); listItem2.endPos = this.m_isPositive ? (listItem2.endPos + num2) : (listItem2.endPos - num2); if (listItem2.go != null) { this.UpdateItemGameObjectPosition(listItem2); } this.ShowItem(listItem2, false); } }
public void RemoveAt(int index) { if (index >= this.itemList.Count || index < 0) { return; } ListView.ListItem listItem = this.itemList[index]; float num = Mathf.Abs(listItem.endPos - listItem.startPos) + this.spacing; this.totalSize -= num; this.SetContainerSize(this.totalSize); this.OnItemLeave(listItem); for (int i = index + 1; i < this.itemList.Count; i++) { ListView.ListItem listItem2 = this.itemList[i]; listItem2.index--; listItem2.startPos = this.m_isPositive ? (listItem2.startPos - num) : (listItem2.startPos + num); listItem2.endPos = this.m_isPositive ? (listItem2.endPos - num) : (listItem2.endPos + num); if (listItem2.go != null) { this.UpdateItemGameObjectPosition(listItem2); this.ShowItem(listItem2); } else { this.ShowItem(listItem2, true); } } this.itemList.RemoveAt(index); }
public void Clear() { for (int i = 0; i < this.itemList.Count; i++) { ListView.ListItem listItem = this.itemList[i]; if (listItem.go != null) { m_funcTab.ItemRemove?.Invoke(listItem); PrefabManager.Instance.UnloadAsset(listItem.go); listItem.go = null; } } this.prefabSizeMap.Clear(); this.containerLastPos = 0f; this.itemList.Clear(); this.totalSize = 0f; this.SetContainerSize(0f); ScrollRect component = base.GetComponent <ScrollRect>(); if (component != null) { component.StopMovement(); } }
private void UpdateItemGameObjectPosition(ListView.ListItem item) { Vector3 v = (!this.isVertical) ? new Vector2(item.startPos, 0f) : new Vector2(0f, item.startPos); RectTransform component = item.go.GetComponent <RectTransform>(); component.anchoredPosition = v; component.localScale = Vector3.one; }
private string GetItemTag(ListView.ListItem item) { if (m_funcTab != null && m_funcTab.GetItemTag != null) { return(m_funcTab.GetItemTag(item)); } return(string.Empty); }
private string GetItemPrefabName(ListView.ListItem item) { if (m_funcTab != null && m_funcTab.GetItemPrefabName != null) { return(m_funcTab.GetItemPrefabName(item)); } return(this.defaultPrefabName); }
public void Insert(int index) { if (index > this.itemList.Count || index < 0) { return; } ListView.ListItem listItem = new ListView.ListItem(); listItem.index = index; listItem.prefabName = this.GetItemPrefabName(listItem); listItem.tag = this.GetItemTag(listItem); if (index != 0) { if (m_isPositive) { listItem.startPos = (this.itemList[index - 1].endPos + this.spacing); } else { listItem.startPos = (this.itemList[index - 1].endPos - this.spacing); } } else { if (m_isPositive) { listItem.startPos = this.offset; } else { listItem.startPos = -this.offset; } } float itemSize = this.GetItemSize(listItem); listItem.endPos = this.m_isPositive ? (listItem.startPos + itemSize) : (listItem.startPos - itemSize); this.itemList.Insert(index, listItem); this.ShowItem(listItem, false); this.totalSize += itemSize; this.SetContainerSize(this.totalSize); for (int i = index + 1; i < this.itemList.Count; i++) { listItem = this.itemList[i]; listItem.index++; listItem.startPos = this.m_isPositive ? (listItem.startPos + itemSize) : (listItem.startPos - itemSize); listItem.endPos = this.m_isPositive ? (listItem.endPos + itemSize) : (listItem.endPos - itemSize); if (listItem.go != null) { this.UpdateItemGameObjectPosition(listItem); } this.ShowItem(listItem, false); } }
private void OnItemLeave(ListView.ListItem item) { if (item.go == null) { return; } RecycleItem(item); //CoreUtils.assetService.Destroy(item.go); //item.go = null; //item.isInit = false; }
public void ShowContentAt(float pos) { this.SetViewRect(pos); for (int i = 0; i < this.itemList.Count; i++) { ListView.ListItem item = this.itemList[i]; this.ShowItem(item, false); } this.containerLastPos = pos; }
private bool ShowItem(ListView.ListItem item, bool force = false) { if (this.ItemVisible(item)) { this.OnItemEnter(item, force); return(true); } this.OnItemLeave(item); return(false); }
public void RecycleItem(ListView.ListItem item) { if (!mItemObjectDict.ContainsKey(item.go)) { mItemObjectDict[item.go] = item.data; } m_funcTab.ItemRemove?.Invoke(item); item.data = null; item.go.SetActive(false); this.mItemPoolDict[item.prefabName].Add(item.go); item.go = null; }
private float GetItemSize(ListView.ListItem item) { if (m_funcTab != null && m_funcTab.GetItemSize != null) { return(m_funcTab.GetItemSize(item)); } if (item.startPos != 0 || item.endPos != 0) { return(Mathf.Abs(item.startPos - item.endPos)); } return(this.prefabSizeMap[item.prefabName]); }
public void FillContent(int listLength) { int count = this.itemList.Count; this.totalSize = ((!this.isVertical) ? this.offset : (-this.offset)); for (int i = 0; i < listLength; i++) { ListView.ListItem listItem; if (i < count) { listItem = this.itemList[i]; this.OnItemLeave(listItem); } else { listItem = new ListView.ListItem(); this.itemList.Add(listItem); } listItem.index = i; listItem.prefabName = this.GetItemPrefabName(listItem); listItem.tag = this.GetItemTag(listItem); float itemSize = this.GetItemSize(listItem); if (this.m_isPositive) { listItem.startPos = this.totalSize; listItem.endPos = this.totalSize + itemSize; this.totalSize += (itemSize + this.spacing); } else { listItem.startPos = this.totalSize; listItem.endPos = this.totalSize - itemSize; this.totalSize += (-(itemSize + this.spacing)); } } for (int j = count - 1; j >= listLength; j--) { this.OnItemLeave(this.itemList[j]); this.itemList.RemoveAt(j); } this.totalSize = Mathf.Abs(this.totalSize); this.SetContainerSize(this.totalSize); this.SetContainerPos(this.containerLastPos); this.ShowContentAt(this.containerLastPos); }
public void ScrollList2IdxCenter(int index) { if (index >= this.itemList.Count || index < 0) { return; } float num = -this.itemList[index].startPos; ListView.ListItem item = this.itemList[index]; float itemSize = this.GetItemSize(item); float containerSize = this.GetContainerSize(); if (m_isPositive) { if (this.itemList[index].startPos < this.viewSize / 2f) { num = 0f; } else if (this.itemList[index].startPos > containerSize - this.viewSize / 2f) { num = this.viewSize - containerSize; } else { num = -this.itemList[index].startPos + this.viewSize / 2f - itemSize / 2f; } } else { if (this.itemList[index].startPos > -this.viewSize / 2f) { num = 0f; } else if (this.itemList[index].startPos < -(containerSize - this.viewSize / 2f)) { num = -this.viewSize + containerSize; } else { num = -this.itemList[index].startPos - this.viewSize / 2f + itemSize / 2f; } } this.SetContainerPos(num); this.ShowContentAt(num); }
private bool ItemVisible(ListView.ListItem item) { if (m_isPositive) { if (item.endPos < this.viewStartPos || item.startPos > this.viewEndPos) { return(false); } } else { if (item.endPos > this.viewStartPos || item.startPos < this.viewEndPos) { return(false); } } return(true); }
public void RefreshAndRestPos(int count = 0) { for (int i = 0; i < this.itemList.Count; i++) { ListView.ListItem listItem = this.itemList[i]; if (listItem.go != null) { RecycleItem(listItem); } } this.itemList.Clear(); this.containerLastPos = 0f; this.totalSize = 0f; this.SetContainerSize(0f); ScrollRect component = base.GetComponent <ScrollRect>(); if (component != null) { component.StopMovement(); } FillContent(count); }
private void OnItemEnter(ListView.ListItem item, bool force = false) { if (item.go != null && !force) { return; } if (item.go == null) { item.go = GetRecycleItem(item.prefabName); if (item.go == null) { item.go = GameObject.Instantiate(assetObjectDic[item.prefabName], this.listContainer); item.isInit = false; item.data = null; } else { item.isInit = true; this.mItemObjectDict.TryGetValue(item.go, out item.data); //item.go.transform.SetParent(this.listContainer); } if (!item.go.activeSelf) { item.go.SetActive(true); } RectTransform rect = item.go.GetComponent <RectTransform>(); Vector2 size = rect.rect.size; switch (this.layoutType) { case ListViewLayoutType.TopToBottom: rect.pivot = TopToDownPreset; rect.anchorMin = TopToDownPreset; rect.anchorMax = TopToDownPreset; break; case ListViewLayoutType.BottomToTop: rect.pivot = DownToTopPreset; rect.anchorMin = DownToTopPreset; rect.anchorMax = DownToTopPreset; break; case ListViewLayoutType.LeftToRight: rect.pivot = LeftToRightPreset; rect.anchorMin = LeftToRightPreset; rect.anchorMax = LeftToRightPreset; break; case ListViewLayoutType.RightToLeft: rect.pivot = RightToLeftPreset; rect.anchorMin = RightToLeftPreset; rect.anchorMax = RightToLeftPreset; break; default: break; } rect.sizeDelta = size; } this.UpdateItemGameObjectPosition(item); m_funcTab.ItemEnter(item); }