Unity 修改Inspector面板上的属性

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class TestCube : MonoBehaviour
{
public string monsterName = “”;
public void PrintNmae()
{
Debug.Log(monsterName);//输出名字
}

}
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEditor;

public enum MonsterName
{
建民水怪,
精英怪,
小怪,
红名Boss
}
[CustomEditor(typeof(TestCube))]//将脚本TestCube变成一个可以自定义的脚本
public class TestEditor : Editor
{
MonsterName Enermy = MonsterName.建民水怪;//枚举类型变量的初始值
public override void OnInspectorGUI()//重写Inspector面板
{
base.OnInspectorGUI();
TestCube script = target as TestCube;//target指要重写的这个对象
EditorGUILayout.BeginHorizontal();
GUILayout.Label(“monster”);//创建一个文本,显示文字
//创建一个枚举的下拉菜单
Enermy = (MonsterName)EditorGUILayout.EnumPopup(Enermy, GUILayout.Width(100), GUILayout.Height(20));
//将下拉菜单的值赋给脚本变量
script.monsterName = Enermy.ToString();
EditorGUILayout.EndHorizontal();
if (GUILayout.Button(“输出怪物的名字”, GUILayout.Width(100), GUILayout.Height(20)))
{
script.PrintNmae();
}

}

}

猜你喜欢

转载自blog.csdn.net/bellainvan/article/details/108512989