編輯器擴(kuò)展根據(jù)類型顯示不同內(nèi)容。

實(shí)現(xiàn)效果

using UnityEngine;

using UnityEditor;

[CustomEditor(typeof(BtoolDemo))]//關(guān)聯(lián)之前的腳本

public classBtoolDemoEditor : Editor

{

??? private SerializedObject test;//序列化

? ? private SerializedProperty m_type, a_int,b_int;//定義類型m_type,變量a,變量b

??? void OnEnable()

??? {

??????? test = new SerializedObject(target);

??????? //獲取m_type

??????? m_type =test.FindProperty("m_type");

??????? //獲取a_int

??????? a_int =test.FindProperty("a_int");

??????? //獲取b_int

??????? b_int =test.FindProperty("b_int");

??? }

??? public override void OnInspectorGUI()

??? {

??????? //更新test

??????? test.Update();

??????? //顯示m_type

??????? EditorGUILayout.PropertyField(m_type);

??????? //根據(jù)類型顯示不同內(nèi)容

??????? if (m_type.enumValueIndex == 0)

??????? {

???????????EditorGUILayout.PropertyField(a_int);

??????? }

??????? else if (m_type.enumValueIndex == 1)

??????? {

???????????EditorGUILayout.PropertyField(b_int);

??????? }

??????? test.ApplyModifiedProperties();//應(yīng)用于界面

??? }

}

using UnityEngine;

public class BtoolDemo : MonoBehaviour {

? public enum type1

??? {

??????? a,

??????? b

??? }

??? public type1 m_type;

??? public int a_int;

??? public int b_int;

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容