コード例 #1
0
ファイル: ListView.cs プロジェクト: ly774508966/UGUIWidgets
        private void _updateItems()
        {
            while (this._itemContents.Count > this._contentPanel.transform.childCount)
            {
                this._createItemContainer();
            }

            while (this._itemContents.Count < this._contentPanel.transform.childCount)
            {
                GameObject item = this._contentPanel.transform.GetChild(this._contentPanel.transform.childCount - 1).gameObject;
                if (item)
                {
                    this._removeItemContainer(item);
                }
                else
                {
                    break;
                }
            }

            for (int itemIndex = 0; itemIndex < this._itemContents.Count; itemIndex++)
            {
                GameObject            itemContainer          = this._contentPanel.transform.GetChild(itemIndex).gameObject;
                ListViewItemContainer itemContainerComponent = itemContainer.GetComponent <ListViewItemContainer> ();

                itemContainer.transform.DetachChildren();
                this._itemContents [itemIndex].transform.SetParent(itemContainer.transform);

                itemContainerComponent.itemIndex = itemIndex;
                itemContainerComponent.content   = this._itemContents[itemIndex];
            }
        }
コード例 #2
0
ファイル: ListView.cs プロジェクト: Zachary625/TestUnity3D
        private void _removeItemContainer(GameObject itemContainer)
        {
            ListViewItemContainer itemContainerComponent = itemContainer.GetComponent <ListViewItemContainer> ();

            itemContainerComponent.listView = null;
            itemContainerComponent.content  = null;

            itemContainer.transform.SetParent(null);
            itemContainer.transform.DetachChildren();
        }
コード例 #3
0
ファイル: ListView.cs プロジェクト: Zachary625/TestUnity3D
        private GameObject _createItemContainer()
        {
            GameObject            itemContainer          = Instantiate(this.itemContainerPrefab);
            ListViewItemContainer itemContainerComponent = itemContainer.GetComponent <ListViewItemContainer> ();

//			ContentSizeFitter contentSizeFitter = itemContainer.AddComponent<ContentSizeFitter> ();

            itemContainer.transform.SetParent(this._contentPanel.transform);

            itemContainerComponent.listView = this.gameObject;

            switch (this.direction)
            {
            case Direction.Vertical:
            {
                VerticalLayoutGroup verticalLayoutGroup = itemContainer.AddComponent <VerticalLayoutGroup> ();
                verticalLayoutGroup.childAlignment         = TextAnchor.UpperCenter;
                verticalLayoutGroup.childForceExpandWidth  = true;
                verticalLayoutGroup.childForceExpandHeight = false;

//					contentSizeFitter.horizontalFit = ContentSizeFitter.FitMode.Unconstrained;
//					contentSizeFitter.verticalFit = ContentSizeFitter.FitMode.PreferredSize;
                break;
            }

            case Direction.Horizontal:
            {
                HorizontalLayoutGroup horizontalLayoutGroup = itemContainer.AddComponent <HorizontalLayoutGroup> ();
                horizontalLayoutGroup.childAlignment         = TextAnchor.MiddleLeft;
                horizontalLayoutGroup.childForceExpandWidth  = false;
                horizontalLayoutGroup.childForceExpandHeight = true;

//					contentSizeFitter.horizontalFit = ContentSizeFitter.FitMode.PreferredSize;
//					contentSizeFitter.verticalFit = ContentSizeFitter.FitMode.Unconstrained;
                break;
            }
            }

            return(itemContainer);
        }