//表现
//编辑器扩展脚本放到Editor下
using System.Collections;
using System.Collections.Generic;
using UnityEditor;
using UnityEngine;
[CustomEditor(typeof(objPropPrefab))] //指定要编辑的脚本对象
public class PropInspector : Editor
{
public override void OnInspectorGUI()
{
base.OnInspectorGUI();
objPropPrefab script = target as objPropPrefab;
EditorGUILayout.BeginHorizontal();
script.PropType = (enumProp)EditorGUILayout.
EnumPopup("类别:", script.PropType);
EditorGUILayout.EndHorizontal();
EditorGUILayout.BeginHorizontal();
if (script.PropType == enumProp.Yaoshui)
{
script.YaoshuiType = (enumYaoshui)EditorGUILayout.
EnumPopup("药水:", script.YaoshuiType);
} else if (script.PropType == enumProp.Food) {
script.FoodType = (enumFood)EditorGUILayout.
EnumPopup("消耗品:", script.FoodType);
}
else if (script.PropType == enumProp.Paotai)
{
script.PaotaiType = (enumPaotai)EditorGUILayout.
EnumPopup("炮台:", script.PaotaiType);
}
else if (script.PropType == enumProp.Baoxiang)
{
script.ChackType = (enumChack)EditorGUILayout.
EnumPopup("宝箱:", script.ChackType);
}
EditorGUILayout.EndHorizontal();
}
}
示例中用到的枚举
/**buff药水道具枚举*/
public enum enumYaoshui
{
addHp = 1, //加血药水、
maxHp, //增加血量上限药水永久
addLuck //爆率药水有时效
}
/**消耗类物品枚举*/
public enum enumFood
{
money = 1, ///消耗类物品 钱 食物 心情 燃料
food,
fuel,
happy,
wood,
stone,
magic
}
/**宝箱枚举*/
public enum enumChack
{
Chack0 = 1, //宝箱
Chack1,
Chack2
}
/**炮台枚举*/
public enum enumPaotai
{
Paotai0 = 1,
Paotai1,
Paotai2,
Paotai3
}
////Unity编辑器扩展: GUILayout、EditorGUILayout 控件整理 https://blog.csdn.net/linxinfa/article/details/87863123
//objPropPrefab 脚本 挂到场景的物体上就可以
using System.Collections;
using UnityEngine.UI;
using System.Collections.Generic;
/**道具预制体*/
public class objPropPrefab : MonoBehaviour
{
public int vid;//作为物品的唯一标识
private GlobalDate.BagDate date;//物品的信息
[HideInInspector]
public enumProp PropType;//物品类别 大类
[HideInInspector]
public enumYaoshui YaoshuiType;//物品类别
[HideInInspector]
public enumChack ChackType;//物品类别
[HideInInspector]
public enumPaotai PaotaiType;//物品类别
[HideInInspector]
public enumFood FoodType;//物品类别
void Start()
{
}