toLua使用protobuf協議轉Lua表


原貼:http://blog.csdn.net/wuming0108/article/details/70161886

根據原貼會有一點點小坑,這里我將其重新整理一下。

我使用的環境:

1、unity5.3.3

2、使用的LuaFramwWork_NGUI插件:https://github.com/jarjin/LuaFramework_NGUI

3、protobuf:https://github.com/google/protobuf

4、protoc-gen-lua:https://github.com/sean-lin/protoc-gen-lua

5、protoc:https://github.com/google/protobuf/releases

6、python:我用的py27,自己下載,程序猿不要這么懶。

 

以上內容到位后開始以下操作:

1、把上面5解壓后的Protoc放到3的protobuf/src下,5解壓后的目錄下有個bin,把bin下的protoc.exe也復制到3的protobuf/src下。

2. cmd進入到上面3的protobuf/python 執行以下命令

  python setup.py build
  python setup.py install

3、執行2如果有下圖的錯誤,說明1操作不正確,也就是protoc.exe沒有按1說的復制過去。

4、進入protoc-gen-lua/plugin 下面 新建一個protoc-gen-lua.bat 把以下內容填寫進去,星號為protoc-gen-lua的路徑

@python ****\protoc-gen-lua\plugin\protoc-gen-lua

注:

 

在每個protoc-gen-lua生成的lua文件里, 都有一行

local protobuf = require "protobuf"

本身按照官方出的沒問題, 但是在ulua的目錄里, 總是報protobuf找不到的錯誤. 前后對比了下我生成的lua和ulua官方生成的代碼里

發現居然他修改了地址改為了

local protobuf = require "protobuf/protobuf"

好吧, 只有修改生成器代碼protoc-gen-lua\plugin\protoc-gen-lua中第412行改為

lua('local protobuf = require "protobuf/protobuf"\n')
 如果有需要,自己去protoc-gen-lua/plugin的目錄下對plugin_pb2.py這個腳本進行調整。

 

5. 進入Unity Packager.cs BuildProtobufFile函數

dir 修改為proto文件路徑

protoc修改為 protobuf/src/protoc.exe

protoc_gen_dir 修改為protoc-gen-lua.bat的路徑

6、 unity 菜單LuaFramework/Build Protobuf-lua-gen File 點擊生成

 

有問題的小伙伴可以加我QQ或者發QQ郵件,我在博客簽名里留下了我的QQ號。

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM