private void Awake() { this.m_scrollRect = this.transform.GetComponent <ScrollRect>(); this.m_sizeDelta = this.m_scrollRect.GetComponent <RectTransform>().sizeDelta; this.m_scrollRect.onValueChanged.AddListener(new UnityAction <Vector2>(this.ScrollRectEvent)); this.m_scrollRect.decelerationRate = 0.001f; if (!this.transform.Find("Content")) { Debug.LogError("必须先编辑Content,才能使用!"); return; } this.m_content = this.transform.Find("Content").GetComponent <RectTransform>(); m_poolObj = this.transform.Find("Pool"); if (m_poolObj != null) { Destroy(m_poolObj); } m_poolObj = new GameObject("Pool").GetComponent <Transform>(); m_poolObj.SetParent(this.transform); GameObjectUtils.ResetTransform(m_poolObj); GridLayoutGroup m_gridLayoutGroup = this.m_content.GetComponent <GridLayoutGroup>(); this.m_constraintCount = m_gridLayoutGroup.constraintCount; this.m_cellSize = m_gridLayoutGroup.cellSize; this.m_spacing = m_gridLayoutGroup.spacing; this.m_padding = m_gridLayoutGroup.padding; this.m_constraint = m_gridLayoutGroup.constraint; if (this.m_constraint == GridLayoutGroup.Constraint.FixedColumnCount) { this.m_scrollRect.vertical = true; this.m_scrollRect.horizontal = false; } else if (this.m_constraint == GridLayoutGroup.Constraint.FixedRowCount) { this.m_scrollRect.vertical = false; this.m_scrollRect.horizontal = true; } else { this.m_scrollRect.vertical = true; this.m_scrollRect.horizontal = true; } Destroy(m_gridLayoutGroup); this.m_contentLocalPos = this.m_content.localPosition; GameObjectUtils.DestroyChilds(this.m_content.transform); ContentSizeFitter contentSizeFitter = this.m_content.GetComponent <ContentSizeFitter>(); if (contentSizeFitter != null) { Destroy(contentSizeFitter); } this.m_handlerDic = new Dictionary <int, AItemHandler>(); this.m_itemStack = new Stack <GameObject>(); }
private void InitContent(int num) { GameObjectUtils.DestroyChilds(this.m_content); for (int i = 0; i < num; i++) { this.PopStack(i); } }
private void ItemStackClear() { if (this.m_itemStack.Count > 0) { for (int i = 0; i < this.m_itemStack.Count; i++) { GameObject obj = this.m_itemStack.Pop(); UnityEngine.Object.DestroyImmediate(obj); } } GameObjectUtils.DestroyChilds(this.m_poolObj.transform); }