protected override void addItemToContainer(IListItemRender item) { GameObject go = null; if (item is MonoBehaviour) { SAListItemRender view = item as SAListItemRender; go = view.skin; } else { SASkinBase view = item as SASkinBase; go = view.skin; } RectTransform rect; if (go != null) { rect = go.GetComponent <RectTransform>(); if (rect == null) { rect = go.AddComponent <RectTransform>(); } rect.transform.SetParent(_layoutTransform, false); rect.anchorMax = new Vector2(0, 1); rect.anchorMin = new Vector2(0, 1); rect.pivot = _itemPivot; rect.sizeDelta = _itemSize; } }
public override object newInstance() { // T instance = (T)base.newInstance(); if (_skinPrefab == null) { return(null); } GameObject go = GameObject.Instantiate(_skinPrefab); go.SetActive(true); SAListItemRender render = go.GetComponent <SAListItemRender>(); return(render); }
override protected void layout(IListItemRender render, int index = 0) { GameObject skin = null; if (render is MonoBehaviour) { SAListItemRender skinBase = render as SAListItemRender; skin = skinBase.skin; } else { SASkinBase skinBase = render as SASkinBase; skin = skinBase.skin; } RectTransform rect = skin.GetComponent <RectTransform>(); rect.anchoredPosition = _itemPivotOffset + indexToPosition(index); }
protected void innerClear(Stack <IListItemRender> willCleanChildren) { IListItemRender item; int length = willCleanChildren.Count; while (willCleanChildren.Count > 0) { item = willCleanChildren.Pop(); if (item is MonoBehaviour) { SAListItemRender view = item as SAListItemRender; view.SetActive(false); } else { SASkinBase view = item as SASkinBase; view.SetActive(false); } bindItemEvent(item, false); _caches.Push(item); } }
protected virtual void renderList() { IntVector2 v = getRenderListRange(); int start = v.x; int end = v.y; int oldChildLen = _childrenList.Count; if (oldChildLen > 0) { for (int j = oldChildLen - 1; j > -1; j--) { _oldChildrenList.Push(_childrenList[j]); } _childrenList.Clear(); } IListItemRender item; currentStartIndex = start; for (int i = start; i < end; i++) { if (oldChildLen > 0) { oldChildLen--; item = _oldChildrenList.Pop(); } else if (_caches.Count > 0) { item = _caches.Pop(); if (item is MonoBehaviour) { SAListItemRender view = item as SAListItemRender; view.SetActive(true); } else { SASkinBase view = item as SASkinBase; view.SetActive(true); } } else { item = (IListItemRender)_itemFacotry.newInstance(); addItemToContainer(item); } item.index = i; if (item is IPageListRef) { ((IPageListRef)item).ownerPageList = this; } layout(item, i); bindItemEvent(item, true); bindItemData(item, getItemData(i)); _childrenList.Add(item); Refresh(); } if (oldChildLen > 0) { innerClear(_oldChildrenList); } }