Official manual: ScriptedImporter official manual description
Solution:
Put the following files into the Editor folder and wait for Unity to automatically refresh or reopen Unity to recognize them.
using System.IO;
using UnityEditor.Experimental.AssetImporters;
using UnityEngine;
[ScriptedImporter(1, ".lua")]
public class LuaImporter : ScriptedImporter
{
public override void OnImportAsset(AssetImportContext ctx)
{
//读取文件内容
var luaTxt = File.ReadAllText(ctx.assetPath);
//转成TextAsset(Unity可识别类型)
var assetsText = new TextAsset(luaTxt);
//将对象assetText添加到导入操作(AssetImportContext)的结果中。
ctx.AddObjectToAsset("main obj", assetsText);
//将对象assetText作为导入操作的主要对象。
ctx.SetMainObject(assetsText);
}
}
In this way, it can be correctly recognized as the same thing as TextAsset file. You can write t:TextAsset in the search bar of the Project window to search for all .lua files, and the AB package can be packaged normally.