GUILayout.SelectionGrid()

作者:追风剑情 发布于:2019-6-14 11:44 分类:Unity3d

示例

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEditor;

public class UITableWindow : EditorWindow
{
    [MenuItem("Example/UI Table Window")]
    static void Init()
    {
        EditorWindow window = EditorWindow.CreateInstance<UITableWindow>();
        window.Show();
    }

    int selected = 0;

    void OnGUI()
    {
        GUIContent[] content = new GUIContent[10];
        //提取内置资源
        Texture toggle_off = EditorGUIUtility.Load("toggle act") as Texture;
        Texture toggle_on = EditorGUIUtility.Load("toggle on act") as Texture;
        for (int i = 0; i <= 9; i++)
        {
            string text = i.ToString();
            Texture image = (selected == i) ? toggle_on : toggle_off;
            string tooltip = "tooltip " + i;
            GUIContent c = new GUIContent(text, image, tooltip);
            content[i] = c;
        }
        selected = GUILayout.SelectionGrid(selected, content, 3);
    }
}

测试

2222.gif

标签: Unity3d

Powered by emlog  蜀ICP备18021003号-1   sitemap

川公网安备 51019002001593号