欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

unity中预览lua文件

程序员文章站 2024-03-14 15:04:10
...
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);
        }
    }
}

 

相关标签: 个人心得