Unity Editor 知识点整理(创建 自定义编辑器窗体 三)

//具体绘制GUI的方法
private void OnGUI()
{
    
    
    //显示文本
    EditorGUILayout.LabelField("当前GUI已经被修改了");
    DrawTabs();
    DrawScroll();
}

绘制页签

//绘制页签
private void DrawTabs()
{
    
    
    //当前选中枚举的索引值
    int index = (int)_CategorySelected;

    //绘制页签 创建一排按钮
    //参数 当前选中按钮索引值 一排按钮的名字
    //返回选中按钮的索引值
    index = GUILayout.Toolbar(index, _CategoryLabels.ToArray());
    //更新_CategorySelected
    _CategorySelected = _Catgories[index];
}

绘制滚动区域

//绘制滚动区域
private void DrawScroll()
{
    
    
    //判断当前选中的页签下是否有关卡碎片
    if (_CategorizedItemDic[_CategorySelected].Count==0)
    {
    
    
        //如果没有,弹出提示
        EditorGUILayout.HelpBox("这个类型下没有关卡碎片",MessageType.Info);
    }

    //窗体一共可以显示多少列 读取窗体的宽度 
    int colCapacity = Mathf.FloorToInt(position.width / itemWidth);
    
    //开始滚动区域
    //参数 当前滚动的位置
    _scrollPosition = GUILayout.BeginScrollView(_scrollPosition);

    //显示当前选中类型的 所有关卡碎片的预览图
    //因为显示的比较多,所以要创建排列
    int selectionGridIndex = -1;//默认不选中
    //参数 当前选中的网格索引 所有的预览图 列数 定制Item的显示样式
    //返回当前选中的索引值
    selectionGridIndex = GUILayout.SelectionGrid(selectionGridIndex,GetGUIContentsFromItems(), colCapacity,GetGUIStyle());
   

    GUILayout.EndScrollView();
}

猜你喜欢

转载自blog.csdn.net/qq_43388137/article/details/122239276
今日推荐