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