unity中预览lua文件

using UnityEditor;
using System.IO;
using UnityEngine;

[CustomEditor(typeof(UnityEditor.DefaultAsset))]
public class ShowLuaFile : Editor
{
    public override void OnInspectorGUI()
    {
        base.OnInspectorGUI();
        var path = AssetDatabase.GetAssetPath(target);
        if (path.EndsWith(".lua"))
        {
            var str = File.ReadAllText(path);
            if (str.Length > 1024 * 20)
                str = str.Substring(0, 1024 * 20) + "...";
            GUIStyle myStyle = new GUIStyle();
            myStyle.fontSize = 15;
            myStyle.fontStyle = FontStyle.Bold;
            myStyle.normal.textColor = Color.white;
            EditorGUILayout.TextArea(str, myStyle);
        }
    }
}

 

你可能感兴趣的:(个人心得)