轉載:http://blog.csdn.net/liqiangeastsun/article/details/42173557
使用Unity編輯器類編輯 helpBox、Toggle、Button、Label
在Editor文件夾下創建腳本
using UnityEngine;
using System.Collections;
using UnityEditor;
[CanEditMultipleObjects]
[CustomEditor(typeof(TestScript))]
public class EditorScript : Editor {
private TestScript testScript;
private bool isTrue = true;
private void OnEnable()
{
testScript = (TestScript)target;
}
public override void OnInspectorGUI()
{
EditorGUILayout.BeginVertical("box"); //開始水平布局, “box” 為一個 方框區域
EditorGUILayout.LabelField("ALDJLG0"); //不可點的Label
EditorGUILayout.SelectableLabel("adfdfdfdfdsf"); //可點的Label
if (GUILayout.Button("Click")) //創建Button ,當點擊按鈕時,調用相應方法
{
testScript.MyTestA();
}
EditorGUILayout.EndVertical();
EditorGUILayout.Space(); //空格行
isTrue = EditorGUILayout.Toggle("isTrigger",isTrue);
EditorGUILayout.BeginVertical();
EditorGUI.BeginDisabledGroup(isTrue); // 如果 isTrue為真,則下方顯示在面板上(灰色)不可操作, 為假則可操作
if (GUILayout.Button("Button"))
{
testScript.MyTestA();
}
EditorGUI.EndDisabledGroup();
EditorGUILayout.EndVertical();
EditorGUILayout.HelpBox("help help help", MessageType.Warning); //顯示幫助框,類型為 警告
EditorGUILayout.Space();
EditorGUILayout.HelpBox("aaa aaa aaa", MessageType.Error); //顯示幫助框,類型為 錯誤
}
}
TestScript腳本如下,將其綁定在對象上即可
using UnityEngine;
using System.Collections;
public class TestScript : MonoBehaviour {
public void MyTestA()
{
Debug.Log("Click");
}
}