Beispiel #1
0
        public void prepare()
        {
            if (nodeNum > 0)
            {
                if (cell_tpl == null)
                {
                    cell_tpl = transform.Find("container/cell_tpl").gameObject;
                }
                if (cell_sub_tpl == null)
                {
                    cell_sub_tpl = transform.Find("container/cell_sub_tpl").gameObject;
                }
                cell_tpl.SetActive(false);
                cell_sub_tpl.SetActive(false);

                for (int i = 0; i < nodeNum; i++)
                {
                    GameObject nodeObj = Instantiate(cell_tpl);
                    nodeObj.SetActive(true);
                    nodeObj.transform.SetParent(container.transform);
                    LExpandNode node = nodeObj.AddComponent <LExpandNode>();
                    node.tpl = cell_sub_tpl;
                    node.prepare(nodeItemNum);
                    insertExpandableNodeAtLast(node);
                }
            }
        }
Beispiel #2
0
        public void insertExpandableNodeAtFront(LExpandNode node)
        {
            if (node == null)
            {
                Debug.LogWarning("insert node is null");
                return;
            }

            _expandableNodeList.Insert(0, node);
            node.transform.SetParent(container.transform);
        }
Beispiel #3
0
        public void removeExpandNode(LExpandNode node)
        {
            if (node == null)
            {
                Debug.LogWarning("insert node is null");
                return;
            }

            if (_expandableNodeList.Count == 0)
            {
                return;
            }
            _expandableNodeList.Remove(node);
        }
Beispiel #4
0
        public void updateNodesPosition()
        {
            if (_expandableNodeList.Count == 0)
            {
                return;
            }

            float allNodesHeight = 0.0f;
            int   nodeLen        = _expandableNodeList.Count;

            for (int i = 0; i < nodeLen; i++)
            {
                LExpandNode node = _expandableNodeList[i];
                allNodesHeight += node.gameObject.GetComponent <RectTransform>().rect.height;

                if (node.isExpanded())
                {
                    List <GameObject> nodeItems = node.getExpandableNodeItemList();
                    if (nodeItems.Count > 0)
                    {
                        foreach (GameObject obj in nodeItems)
                        {
                            obj.SetActive(true);
                            allNodesHeight += obj.GetComponent <RectTransform>().rect.height;
                        }
                    }
                }
                else
                {
                    List <GameObject> nodeItems = node.getExpandableNodeItemList();
                    if (nodeItems.Count > 0)
                    {
                        foreach (GameObject obj in nodeItems)
                        {
                            obj.SetActive(false);
                        }
                    }
                }
            }

            Rect rect = GetComponent <RectTransform>().rect;

            allNodesHeight = Mathf.Max(allNodesHeight, rect.height);
            setContainerSize(new Vector2(rect.width, allNodesHeight));

            for (int i = 0; i < nodeLen; i++)
            {
                LExpandNode   node  = _expandableNodeList[i];
                RectTransform rtran = node.gameObject.GetComponent <RectTransform>();
                allNodesHeight = allNodesHeight - rtran.rect.height;

                rtran.pivot     = Vector2.zero;
                rtran.anchorMax = new Vector2(0, 0);
                rtran.anchorMin = new Vector2(0, 0);
                node.transform.SetParent(container.transform);
                node.transform.localPosition = new Vector2(0, allNodesHeight);
                node.transform.localScale    = new Vector3(1, 1, 1);

                if (node.isExpanded())
                {
                    List <GameObject> itemLists = node.getExpandableNodeItemList();
                    for (int j = 0; j < itemLists.Count; j++)
                    {
                        RectTransform _rtran = itemLists[j].GetComponent <RectTransform>();
                        allNodesHeight = allNodesHeight - _rtran.rect.height;

                        _rtran.pivot     = Vector2.zero;
                        _rtran.anchorMax = new Vector2(0, 0);
                        _rtran.anchorMin = new Vector2(0, 0);
                        itemLists[j].transform.SetParent(container.transform);
                        itemLists[j].transform.localPosition = new Vector2(0, allNodesHeight);
                        itemLists[j].transform.localScale    = new Vector3(1, 1, 1);
                    }
                }
            }
        }