protected ComUIListElementScript CreateElement(int index, ref stRect rect) { ComUIListElementScript item = null; if (this.m_unUsedElementScripts.Count > 0) { item = this.m_unUsedElementScripts[0]; this.m_unUsedElementScripts.RemoveAt(0); } else if (this.m_elementTemplate != null) { GameObject root = InstantiateElement(this.m_elementTemplate); root.transform.SetParent(this.m_content.transform); root.transform.localScale = Vector3.one; item = root.GetComponent <ComUIListElementScript>(); } if (item != null) { if (onBindItem != null && item.gameObjectBindScript == null) { item.gameObjectBindScript = onBindItem(item.gameObject); } item.Initialize(); item.Enable(this, index, this.m_elementName, ref rect, this.IsSelectedIndex(index)); this.m_elementScripts.Add(item); if (onItemVisiable != null) { onItemVisiable(item); } } return(item); }
protected void RecycleElement(ComUIListElementScript elementScript, bool disableElement) { if (disableElement) { elementScript.Disable(); } if (OnItemRecycle != null) { OnItemRecycle(elementScript); } this.m_elementScripts.Remove(elementScript); this.m_unUsedElementScripts.Add(elementScript); }
public virtual void SelectElement(int index, bool isDispatchSelectedChangeEvent = true) { this.m_lastSelectedElementIndex = this.m_selectedElementIndex; this.m_selectedElementIndex = index; if (this.m_lastSelectedElementIndex == this.m_selectedElementIndex) { if (this.m_alwaysDispatchSelectedChangeEvent) { //this.DispatchElementSelectChangedEvent(); } } else { if (this.m_lastSelectedElementIndex >= 0) { ComUIListElementScript elemenet = this.GetElemenet(this.m_lastSelectedElementIndex); if (elemenet != null) { elemenet.ChangeDisplay(false); } } if (this.m_selectedElementIndex >= 0) { ComUIListElementScript script2 = this.GetElemenet(this.m_selectedElementIndex); if (script2 != null) { script2.ChangeDisplay(true); if (onItemSelected != null) { onItemSelected(script2); } } } if (isDispatchSelectedChangeEvent) { //this.DispatchElementSelectChangedEvent(); } } }
protected void RecycleElement(bool disableElement) { if (this.m_elementScripts == null) { return; } while (this.m_elementScripts.Count > 0) { ComUIListElementScript item = this.m_elementScripts[0]; this.m_elementScripts.RemoveAt(0); if (disableElement) { item.Disable(); } if (OnItemRecycle != null) { OnItemRecycle(item); } this.m_unUsedElementScripts.Add(item); } }
public void Initialize() { if (!m_isInitialized) { m_isInitialized = true; this.m_selectedElementIndex = -1; this.m_lastSelectedElementIndex = -1; this.m_scrollRect = base.GetComponentInChildren <ScrollRect>(base.gameObject); if (this.m_scrollRect != null) { if (m_scrollExternal == false) { this.m_scrollRect.enabled = false; } RectTransform transform = this.m_scrollRect.transform as RectTransform; this.m_scrollAreaSize = new Vector2(transform.rect.width, transform.rect.height); this.m_content = this.m_scrollRect.content.gameObject; } this.m_scrollBar = base.GetComponentInChildren <Scrollbar>(base.gameObject); if ((this.m_listType == enUIListType.Vertical) || (this.m_listType == enUIListType.VerticalGrid)) { if (this.m_scrollBar != null) { this.m_scrollBar.direction = Scrollbar.Direction.BottomToTop; } //DebugHelper.Assert(this.m_scrollRect != null); if (this.m_scrollRect != null) { this.m_scrollRect.horizontal = false; this.m_scrollRect.vertical = true; this.m_scrollRect.horizontalScrollbar = null; this.m_scrollRect.verticalScrollbar = this.m_scrollBar; } } else if ((this.m_listType == enUIListType.Horizontal) || (this.m_listType == enUIListType.HorizontalGrid)) { if (this.m_scrollBar != null) { this.m_scrollBar.direction = Scrollbar.Direction.LeftToRight; } //DebugHelper.Assert(this.m_scrollRect != null); if (this.m_scrollRect != null) { this.m_scrollRect.horizontal = true; this.m_scrollRect.vertical = false; this.m_scrollRect.horizontalScrollbar = this.m_scrollBar; this.m_scrollRect.verticalScrollbar = null; } } this.m_elementScripts = new List <ComUIListElementScript>(); this.m_unUsedElementScripts = new List <ComUIListElementScript>(); if (this.m_useOptimized) { this.m_elementsRect = new List <stRect>(); } ComUIListElementScript component = null; if (this.m_useExternalElement) { /* * GameObject content = (GameObject) Singleton<CResourceManager>.GetInstance().GetResource(this.m_externalElementPrefabPath, typeof(GameObject), enResourceType.UIPrefab, false, false).m_content; * component = content.GetComponent<CUIListElementScript>(); * if (component != null) * { * component.Initialize(formScript); * this.m_elementTemplate = content; * this.m_elementName = content.name; * this.m_elementDefaultSize = component.m_defaultSize; * } */ } else { component = base.GetComponentInChildren <ComUIListElementScript>(base.gameObject); if (component != null) { component.Initialize(); this.m_elementTemplate = component.gameObject; this.m_elementName = component.gameObject.name; this.m_elementDefaultSize = component.m_defaultSize; if (this.m_elementTemplate != null) { this.m_elementTemplate.name = this.m_elementName + "_Template"; } } } if (this.m_elementTemplate != null) { ComUIListElementScript script2 = this.m_elementTemplate.GetComponent <ComUIListElementScript>(); if ((script2 != null) && script2.m_useSetActiveForDisplay) { this.m_elementTemplate.SetActive(false); //this.m_elementTemplate.CustomActive(false); } else { if (!this.m_elementTemplate.activeSelf) { this.m_elementTemplate.SetActive(true); } CanvasGroup group = this.m_elementTemplate.GetComponent <CanvasGroup>(); if (group == null) { group = this.m_elementTemplate.AddComponent <CanvasGroup>(); } group.alpha = 0f; group.blocksRaycasts = false; } } if (this.m_content != null) { this.m_contentRectTransform = this.m_content.transform as RectTransform; this.m_contentRectTransform.pivot = new Vector2(0f, 1f); this.m_contentRectTransform.anchorMin = new Vector2(0f, 1f); this.m_contentRectTransform.anchorMax = new Vector2(0f, 1f); this.m_contentRectTransform.anchoredPosition = Vector2.zero; this.m_contentRectTransform.localRotation = Quaternion.identity; this.m_contentRectTransform.localScale = new Vector3(1f, 1f, 1f); this.m_lastContentPosition = this.m_contentRectTransform.anchoredPosition; } if (this.m_extraContent != null) { RectTransform transform2 = this.m_extraContent.transform as RectTransform; transform2.pivot = new Vector2(0f, 1f); transform2.anchorMin = new Vector2(0f, 1f); transform2.anchorMax = new Vector2(0f, 1f); transform2.anchoredPosition = Vector2.zero; transform2.localRotation = Quaternion.identity; transform2.localScale = Vector3.one; if (this.m_elementTemplate != null) { transform2.sizeDelta = new Vector2((this.m_elementTemplate.transform as RectTransform).rect.width, transform2.sizeDelta.y); } if ((transform2.parent != null) && (this.m_content != null)) { transform2.parent.SetParent(this.m_content.transform); } this.m_extraContent.SetActive(false); } this.SetElementAmount(this.m_elementAmount); } }