示例:给资源加描述信息
点击【Edit】可对信息进行编辑
AssetHelpBox.cs
using UnityEngine; /// <summary> /// 显示资源帮助信息 /// </summary> public class AssetHelpBox : MonoBehaviour { [SerializeField] [HideInInspector] public string message; }
AssetHelpBoxInspector.cs
using System.Collections.Generic; using UnityEditor; using UnityEngine; // 将此脚本放到 Editor 目录下 [CustomEditor(typeof(AssetHelpBox))] public class AssetHelpBoxInspector : Editor { protected AssetHelpBox mAsset; private bool isEditing; protected virtual void OnEnable() { mAsset = target as AssetHelpBox; } public override void OnInspectorGUI() { base.OnInspectorGUI();//保留Unity自动生成的Inspector if (isEditing) { mAsset.message = GUILayout.TextArea(mAsset.message); if (GUILayout.Button("OK", GUILayout.Width(50))) { isEditing = false; string path = AssetDatabase.GetAssetPath(mAsset); List<string> list = new List<string>(); list.Add(path); AssetDatabase.ForceReserializeAssets(list); } } else { string msg = mAsset.message; if (!string.IsNullOrEmpty(msg)) EditorGUILayout.HelpBox(msg, MessageType.Info); if (GUILayout.Button("Edit", GUILayout.Width(50))) { isEditing = true; } } } }