unity, GUIStyle and Skin
例1:
using UnityEngine;
using System.Collections;
using UnityEditor;
using System.Collections.Generic;
[CustomEditor(typeof(CmyScriptableObject))]
public class myScriptableObjectCustomEditor : Editor
{
public Vector2 scrollPosition = Vector2.zero;
public int selGridInt = 0;
public string[] selStrings = new string[] {"item1", "item2", "item3", "item4", "item5", "item6", "item7", "item8"};
public override void OnInspectorGUI()
{
DrawDefaultInspector ();
CmyScriptableObject data = CmyScriptableObject)target;
scrollPosition = EditorGUILayout.BeginScrollView (scrollPosition,"box",GUILayout.MaxHeight(90));
{
//ref: http://answers.unity3d.com/questions/37223/how-do-i-center-a-gui-label.html
//ref: http://iaimstar.iteye.com/blog/2222128
GUIStyle _style = GUI.skin.GetStyle ("MenuItemMixed");
selGridInt = GUILayout.SelectionGrid(selGridInt, selStrings, 1,_style);
}
EditorGUILayout.EndScrollView ();
}
}
例2:
using UnityEngine;
using System.Collections;
using UnityEditor;
using System.Collections.Generic;
[CustomEditor(typeof(CmyScriptableObject))]
public class myScriptableObjectCustomEditor : Editor
{
public Vector2 scrollPosition = Vector2.zero;
public int selGridInt = 0;
public string[] selStrings = new string[] {"item1", "item2", "item3", "item4", "item5", "item6", "item7", "item8"};
public override void OnInspectorGUI()
{
DrawDefaultInspector ();
CmyScriptableObject data = CmyScriptableObject)target;
scrollPosition = EditorGUILayout.BeginScrollView (scrollPosition,"box",GUILayout.MaxHeight(90));
{
//ref: http://answers.unity3d.com/questions/37223/how-do-i-center-a-gui-label.html
//ref: http://iaimstar.iteye.com/blog/2222128
GUIStyle _style = GUI.skin.GetStyle ("helpbox");
_style.onNormal.textColor=Color.blue;
selGridInt = GUILayout.SelectionGrid(selGridInt, selStrings, 1,_style);
}
EditorGUILayout.EndScrollView ();
}
}
自定义skin教程:http://forum.unity3d.com/threads/creating-custom-gui-skins-part-one.113055/