栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 游戏开发 > 其他

unity 三级下拉菜单(树形下拉菜单UGUI)

其他 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

unity 三级下拉菜单(树形下拉菜单UGUI)

unity 三级下拉菜单(树形下拉菜单UGUI)
  1. 最新项目需求要求做一个下拉菜单列表(树形下拉菜单)。但UGUI并没有原生的插件,只能自己实现。
    思路每个级的ItemPanel(一个单级菜单条)样式是一样的,于是需要一个panel来装所有的itemPanel,在整个菜单 顶部panel上添加vertically layout group组件,使下面的子菜单从上到下依次排列。文章最后会附上 demo下载地址
  2. 效果图
  3. 具体实现新建Canvas->Panel,

    粘出部分代码,详细可以下载demo

控制端

public class PullDownList : MonoBehaviour
{
    private List itemPanelList;
    public GameObject itemPanel;
 
 
    private void Awake()
    {
        itemPanelList = new List();
    }
    // Use this for initialization
    void Start()
    {
        for (int i = 0; i < 10; i++)
        {
            GameObject newItemPanel = Instantiate(itemPanel);
            itemPanelList.Add(newItemPanel);
            newItemPanel.GetComponent().SetBaseParent(this.transform);
            newItemPanel.GetComponent().InitPanelContent(new ItemBean("一级菜单" + i, i));
        }
 
        for (int i = 0; i < 5; i++)
        {
            GameObject newItemPanel2 = Instantiate(itemPanel);
            itemPanelList.Add(newItemPanel2);
            newItemPanel2.GetComponent().SetItemParent(itemPanelList[i].GetComponent());
            newItemPanel2.GetComponent().InitPanelContent(new ItemBean("二级菜单" + i, i));
        }
 
        for (int i = 0; i < 2; i++)
        {
            GameObject newItemPanel3 = Instantiate(itemPanel);
            itemPanelList.Add(newItemPanel3);
            newItemPanel3.GetComponent().SetItemParent(itemPanelList[11].GetComponent());
            newItemPanel3.GetComponent().InitPanelContent(new ItemBean("三级菜单" + i, i));
        }
    }   
}

itempanel端

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
 
public class ItemPanelBase : MonoBehaviour
{
    private List childList;//子物体集合
    [HideInInspector]
    public Button downArrow;//下箭头按钮
    public Sprite down, right,dot;
    public bool isOpen { get; set; }//子物体开启状态
    private Vector2 startSize;//起始大小
 
    private void Awake()
    {
        childList = new List();
        downArrow = this.transform.Find("ContentPanel/ArrowButton").GetComponent
  1. 最后附上项目地址 demo下载地址
转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/906691.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号