[CustomEditor(typeof(SkinResource))]
public class SkinResourceEditor : Editor
{
public override void OnInspectorGUI()
{
var skinRes = target as SkinResource;
skinRes.bodySprite = EditorGUILayout.ObjectField("bodySprite", skinRes.bodySprite, typeof(Sprite), false) as Sprite;
skinRes.wingSprite = EditorGUILayout.ObjectField("wingSprite", skinRes.wingSprite, typeof(Sprite), false) as Sprite;
skinRes.mouseSprite = EditorGUILayout.ObjectField("mouseSprite", skinRes.mouseSprite, typeof(Sprite), false) as Sprite;
skinRes.leftEyeSprite = EditorGUILayout.ObjectField("leftEyeSprite", skinRes.leftEyeSprite, typeof(Sprite), false) as Sprite;
skinRes.rightEyeSprite = EditorGUILayout.ObjectField("rightEyeSprite", skinRes.rightEyeSprite, typeof(Sprite), false) as Sprite;
skinRes.cookScomSprite = EditorGUILayout.ObjectField("cookScomSprite", skinRes.cookScomSprite, typeof(Sprite), false) as Sprite;
skinRes.leftEyeBallSprite = EditorGUILayout.ObjectField("leftEyeBallSprite", skinRes.leftEyeBallSprite, typeof(Sprite), false) as Sprite;
skinRes.rightEyeBallSprite = EditorGUILayout.ObjectField("rightEyeBallSprite", skinRes.rightEyeBallSprite, typeof(Sprite), false) as Sprite;
skinRes.leftLegSprite = EditorGUILayout.ObjectField("leftLegSprite", skinRes.leftLegSprite, typeof(Sprite), false) as Sprite;
skinRes.leftLittleLegSprite = EditorGUILayout.ObjectField("leftLittleLegSprite", skinRes.leftLittleLegSprite, typeof(Sprite), false) as Sprite;
skinRes.rightLegSprite = EditorGUILayout.ObjectField("rightLegSprite", skinRes.rightLegSprite, typeof(Sprite), false) as Sprite;
skinRes.rightLittleLegSprite = EditorGUILayout.ObjectField("rightLittleLegSprite", skinRes.rightLittleLegSprite, typeof(Sprite), false) as Sprite;
skinRes.hatType = (SkinType)EditorGUILayout.EnumPopup("hatType", skinRes.hatType);
if (skinRes.hatType == SkinType.Image)
{
// Sprite
skinRes.hatSprite = EditorGUILayout.ObjectField("hatSprite", skinRes.hatSprite, typeof(Sprite), false) as Sprite;
}
else
{
// Prefab
skinRes.hatPrefab = EditorGUILayout.ObjectField("hatPrefab", skinRes.hatPrefab, typeof(GameObject), false) as GameObject;
}
skinRes.hatBackSprite = EditorGUILayout.ObjectField("hatBackSprite", skinRes.hatBackSprite, typeof(Sprite), false) as Sprite;
}
1.先通过target获取到当前物体的自定义类
2.通过EditorGUILayout.ObjectField将自定义类的数据显示到右侧界面中
3.通过EditorGUILayout.EnumPopup获取枚举的值
4.根据枚举的值绘制不同的显示窗口