Unity如何在Inspector中预览lua脚本的内容

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/linxinfa/article/details/82215911
using UnityEnging;
using UnityEditor;
using System.IO;

[CustomeEditor(typeof(UnityEditor.DefaultAsset))]
public class ShowLuaFile:Editor
{
    public override void OnInspectorGUI()
    {
        var path = AssetDatabase.GetAssetPath(target);
        if(path.EndsWith(".lua"))
        {
            GUI.enabled = true;
            GUI.backgroundColor = new Color(60,60,60);
            var str = File.ReadAllText(path);
            if(str.Length > 1024 *20)
                str = str.Substring(0,1024*20)+"...";
            
            GUILayout.TextArea(str);
        }
    }
}

把这个脚本放在Editor目录中即可

猜你喜欢

转载自blog.csdn.net/linxinfa/article/details/82215911