本文实例为大家分享了Unity实现QQ列表折叠菜单的具体代码,供大家参考,具体内容如下
主要用到了GUI的自动布局功能,VerticalLayoutGroup,注意ChildControlsSize 和ChildForceExpand属性设置为 Width
效果:
实现代码:
////// 折叠菜单 /// public class FoldPanel : MonoBehaviour { [SerializeField] private GameObject panelItem; // 折叠页 [SerializeField] private TitleItem titleItem; [SerializeField] private DataItem dataItem; public ListdataList = new List (); private void Start() { Create(); } public void Create() { for (int i = 0; i ().sizeDelta = new Vector3(260,30 * dataList[i].data.Count); title.SetFoldPanel(panel); panel.SetActive(false); // 创建折叠页数据 for (int j = 0; j
TitleItem.cs
public class TitleItem : MonoBehaviour,IPointerClickHandler { [SerializeField] private Text title; [SerializeField] private Transform arrow; public bool isFold = true; // 是否是折叠状态 public Transform foldPanel; public void OnPointerClick(PointerEventData eventData) { if (isFold) { isFold = false; arrow.DORotate(Vector3.zero, 0.1f); if (foldPanel != null) { foldPanel.gameObject.SetActive(true); foldPanel.DOScaleY(1, 0.1f); } } else { isFold = true; arrow.DORotate(new Vector3(0, 0, 90), 0.1f); if (foldPanel != null) { foldPanel.DOScaleY(0, 0.1f).OnComplete(() => { foldPanel.gameObject.SetActive(false); }); } } } public void SetTitle(string _titleName) { title.text = _titleName; } public void SetFoldPanel(GameObject panel) { foldPanel = panel.transform; } }
列表的数据来源是在界面上手动配置的,当然如果想要读取本地或者服务器的数据也是可以的。
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持。