Unity之EditorGUILayout-TextField、Toggle - 七

有些话、适合烂在心里 提交于 2019-12-03 15:36:27

使用Unity编辑器类在Inspector面板编辑 文本输入框TextField和单选框Toggle




Editor文件夹下创建脚本InspectorTest

using UnityEngine;
using System.Collections;
using UnityEditor;


[CustomEditor(typeof(Test))]
public class InspectorTest : Editor {

    public override void OnInspectorGUI()
    {
        Test myTest = (Test)target;

        myTest.MyName = EditorGUILayout.TextField("Object Name", myTest.MyName);

        myTest.showBtn = EditorGUILayout.Toggle("Show Button ", myTest.showBtn);
    }
}



Test脚本如下,将其拖拽到需要绘制的脚本即可

using UnityEngine;
using System.Collections;
using UnityEditor;

public class Test : MonoBehaviour {

    public string MyName;
    public bool showBtn = true;

}










标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!