项目环境
Addressable
lua-protobuf
xlua
前提
之前使用UnityWebRequest和IO已经成功加载.pb文件,并且能够正常解析数据
#现有问题及尝试
1.使用自定义ScriptImpoter的方法让Unity识别.pb文件为TextAsset,然后通过Addressable加载这个TextAsset,使用pb.load方法加载TextAsset.bytes
using System.IO;
using UnityEditor.AssetImporters;
using UnityEngine;
[ScriptedImporter(1, "pb")]
public class PbImporter : ScriptedImporter
{
public override void OnImportAsset(AssetImportContext ctx)
{
var text = File.ReadAllText(ctx.assetPath);
var asset = new TextAsset(text);
ctx.AddObjectToAsset("main obj", asset);
ctx.SetMainObject(asset);
}
}
结果:
解析第一个数据的时候会报type does not exists
2.使用protoc:load直接读取TextAsset.text
local p=protoc.new()
local respText=AddressableManager.GetTextAsset("RespFully.pb")
assert(p:load(respText.text,"RespFully.pb"))
local rqstText=AddressableManager.GetTextAsset("RqstFully.pb")
assert(p:load(rqstText.text,"RqstFully.pb"))
结果:调用pb:load方法时报错
LuaException: protoc:70: RespFully.pb:2:1: name expected
stack traceback:
[C]: in function 'error'
protoc:70: in function <protoc:68>
(...tail calls...)
protoc:763: in function 'protoc.parse'
protoc:1020: in upvalue 'do_compile'
protoc:1024: in function 'protoc.compile'
protoc:1034: in function 'protoc.load'