[Unity编辑器] 对Lua文件的支持

在Unity安装目录下 Editor\Data\Resources\ScriptTemplates 创建一个(87-Lua Script-NewLuaScript.lua.txt )文件

 

在编辑器下预览Lua文件

 

using UnityEngine;  
using UnityEditor;  
using System.IO;  
  
[CanEditMultipleObjects, CustomEditor(typeof(DefaultAsset))]  
public class LuaInspector : Editor  
{  
    private GUIStyle m_TextStyle;  
  
    public override void OnInspectorGUI()  
    {  
        if (this.m_TextStyle == null)  
        {  
            this.m_TextStyle = "ScriptText";  
        }  
        bool enabled = GUI.enabled;  
        GUI.enabled = true;  
        string assetPath = AssetDatabase.GetAssetPath(target);  
        if (assetPath.EndsWith(".lua"))  
        {  
            string luaFile = File.ReadAllText(assetPath);  
            string text;  
            if (base.targets.Length > 1)  
            {  
                text = Path.GetFileName(assetPath);  
            }  
            else  
            {  
                text = luaFile;  
                if (text.Length > 7000)  
                {  
                    text = text.Substring(0, 7000) + "...\n\n<...etc...>";  
                }  
            }  
            Rect rect = GUILayoutUtility.GetRect(new GUIContent(text), this.m_TextStyle);  
            rect.x = 0f;  
            rect.y -= 3f;  
            rect.width = EditorGUIUtility.currentViewWidth + 1f;  
            GUI.Box(rect, text, this.m_TextStyle);  
        }  
        GUI.enabled = enabled;  
    }  
}  

 

 

 

你可能感兴趣的:(Unity)