lua

您所在的位置:网站首页 读取二进制文件的软件叫什么名字 lua

lua

2024-07-15 22:45| 来源: 网络整理| 查看: 265

第一章.编译lua-protobuf支持库(Windows插件-Win10编译) 第二章.Unity & lua-protobuf 环境配置 第三章.二进制proto读取功能,与,lua-protobuf注意事项简介说明 第四章.编译lua-protobuf支持库(Android插件-Win10编译) 第五章.编译lua-protobuf支持库(Android插件-Mac10.13.6编译) 第六章.编译lua-protobuf支持库(IOS插件-Mac10.13.6编译) 一,写测试用到的,C#代码,LUA代码 1,打开 D:\lua_proto\Assets\Lua_proto.cs C#代码

public string LoadProtoBufFile(string fileName) { string luaPath = Application.dataPath + "/lua/" + fileName; string strLuaContent = File.ReadAllText(luaPath); return strLuaContent; }

以上函数下面,添加以下代码

public byte[] LoadProtoBufFileBinary(string fileName) { string luaPath = Application.dataPath + "/lua/" + fileName; FileStream file = new FileStream(luaPath, FileMode.Open, FileAccess.Read); BinaryReader read = new BinaryReader(file); int count = (int)file.Length; byte[] buffer = new byte[count]; read.Read(buffer, 0, buffer.Length); return buffer; }

2,打开 D:\lua_proto\Assets\lua\lua_proto.lua 文件

protoString=luaproto:LoadProtoBufFile("ectype.proto") p:load(protoString,"ectype.proto") print(pb.enum("ECtype",2)) print(pb.enum("ECtype","eUnameLoginReq")) protoString=luaproto:LoadProtoBufFile("login3b.proto") assert(p:load(protoString,"login3b.proto")) protoString=luaproto:LoadProtoBufFile("login3a.proto") assert(p:load(protoString,"login3a.proto"))

以上代码用–[[–]]注释掉.以上代码下面添加 以下代码

protoString=luaproto:LoadProtoBufFileBinary("ectype.pb") assert(pb.load(protoString,"ectype.pb")) print(pb.enum("ECtype",2)) print(pb.enum("ECtype","eUnameLoginReq")) protoString=luaproto:LoadProtoBufFileBinary("login3b.pb") assert(pb.load(protoString,"login3b.pb")) protoString=luaproto:LoadProtoBufFileBinary("login3a.pb") assert(pb.load(protoString,"login3a.pb"))

二,编译二进制proto文件 1,打开,CMD窗口,CD转到D:\lua_proto\Assets\lua 路经下,执行以下三行命令,编译二进制文件,protoc_release.exe文件就是protoc.exe文件, (有的人说这个ectype.pb二进制文件,叫Schema文件,Schema文件到底是什么意思我还不明白,有知道的网友,发表评论给我,非常感谢)

protoc_release.exe -o ectype.pb ectype.proto protoc_release.exe -o login3b.pb login3b.proto protoc_release.exe -o login3a.pb login3a.proto

三,运行Unity,测试 在这里插入图片描述 打印以上图片内容,不出错,就算是,成功读取二进制proto文件了.

二进制proto读取功能完

注(lua-protobuf注意事项简介说明): 1,编写lua代码时pb变量名,和,p变量名,混写会出错. 2,编写lua代码时pb和p后面的.点,与,:冒号,混写会出错. 3,load函数第二参数,必须要写加载文件名与扩展名,不然写import public 时会出错. 4,读二进制proto文件时,必须要用byte[]读,要用string读会出错

第一章.编译lua-protobuf支持库(Windows插件-Win10编译) 第二章.Unity & lua-protobuf 环境配置 第三章.二进制proto读取功能,与,lua-protobuf注意事项简介说明 第四章.编译lua-protobuf支持库(Android插件-Win10编译) 第五章.编译lua-protobuf支持库(Android插件-Mac10.13.6编译) 第六章.编译lua-protobuf支持库(IOS插件-Mac10.13.6编译)



【本文地址】


今日新闻


推荐新闻


CopyRight 2018-2019 办公设备维修网 版权所有 豫ICP备15022753号-3