UGUI—AssetHelpBox

作者:追风剑情 发布于:2024-3-21 14:29 分类:Unity3d

用于在 GameObject 上写备注信息。

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;
            }
        }
    }
}


11111.png

标签: Unity3d

Powered by emlog  蜀ICP备18021003号-1   sitemap

川公网安备 51019002001593号