示例
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);
}
}
测试