public void Initialize(IList <System.Object> dataArray, E_ScrollOption scrollOption = E_ScrollOption.ResetToZero) { m_initialized = true; m_dataArray = dataArray; m_transNodeRoot.localPosition = Vector3.zero; if (m_dataArray == null || m_dataArray.Count < 1) { m_transNodeRoot.SetChildCount(0); m_poolSize = 0; m_maxLine = 0; m_firstIndexMax = 0; SetHeadAndTailSpritePosition(); CachedScrollView.ResetPosition(); return; } int visibleLines = GetVisibleLines(); m_poolSize = Mathf.Min(m_dataArray.Count, visibleLines * m_columnCount); m_maxLine = Mathf.Max(0, (m_dataArray.Count - 1) / m_columnCount); m_firstIndexMax = Mathf.Max(0, m_dataArray.Count - m_poolSize); // calculate the position of the head and the tail SetHeadAndTailSpritePosition(); m_prototype.gameObject.SetActive(true); // initialize prototypes m_transNodeRoot.SetChildCount(m_poolSize, m_prototype); m_prototype.gameObject.SetActive(false); // add prototypes into dynamic item pool m_dynamicNodes.Clear(); for (int i = 0; i < m_poolSize; i++) { Transform childTrans = m_transNodeRoot.GetChild(i); childTrans.gameObject.SetActive(true); UIPoolListNode uiItem = childTrans.GetComponent <UIPoolListNode>(); m_dynamicNodes.Add(uiItem); } m_firstIndexLastFrame = -1; if (scrollOption == E_ScrollOption.ResetToZero) { CachedScrollView.ResetPosition(); UpdateItems(0); } else { if (gameObject.activeInHierarchy) { StartCoroutine(RestrictWithInBounds()); } UpdateItems(GetFirstVisibleIndex()); } //CachedScrollView.onDragFinished = OnPanelDragFinished; m_lastPull = 0; }
protected virtual void OnClick() { if (s_current == null && Initialized && enabled) { s_current = this; EventDelegate.Execute(m_onClick); s_current = null; } }
protected void UpdateItems(int firstVisibleIndex) { int lastVisibleIndex = firstVisibleIndex + m_poolSize; // find out nodes to be updated List <UIPoolListNode> nodesToUpdate = new List <UIPoolListNode>(m_dynamicNodes); List <System.Object> dataToUpdate = new List <System.Object>(); List <int> indexes = new List <int>(); for (int i = firstVisibleIndex; i < lastVisibleIndex; i++) { System.Object data = m_dataArray[i]; UIPoolListNode existingNode = null; if (data != null) { existingNode = nodesToUpdate.Find(x => data.Equals(x.m_data)); } if (existingNode != null && existingNode.Initialized) { nodesToUpdate.Remove(existingNode); existingNode.CachedTrans.localPosition = GetPositionByIndex(i) + NodeOffset; } else { dataToUpdate.Add(data); indexes.Add(i); } } for (int i = 0; i < dataToUpdate.Count; i++) { UIPoolListNode node = nodesToUpdate[i]; System.Object data = dataToUpdate[i]; node.Initialize(data); node.name = "item" + i; node.CachedTrans.localPosition = GetPositionByIndex(indexes[i]) + NodeOffset; } m_firstIndexLastFrame = firstVisibleIndex; }