当前位置:网站首页>Excel转换为Lua的配置文件
Excel转换为Lua的配置文件
2022-07-06 05:02:00 【帅_shuai_】
Excel转换为Lua的配置文件
1.下载Excel转Lua的第三方库
首先我们下载一个第三方开源库,来给Excel表生成lua配置文件,下载地址https://github.com/XINCGer/Unity3DTraining/tree/master/XlsxTools
2.准备生成Lua配置文件
- 在跟Assets平级的目录下,新建一个Tools文件夹,然后把下载的XlsxTools文件夹放在这里
- 然后在debug模式下编译这个解决方案
这个文件有几点需要注意:
excel文件必须保存为.xls格式,而不是.xlsx格式
左下角的tab页签名字必须个文件名一样,并且加一个#前缀,比如我的这个CharacterTable文件,tab页签名字是#CharacterTable
excel的前4行是有特殊含义的:
第1行是每个字段的名字说明
第2行是每个字段的变量类型,一般只支持int和string类型
第3行是每个字段的变量名字,这个变量名字是可以在代码中直接使用的
第4行是注释,可以详细解释这个字段的含义
还有最重要的一点:首字段必须是int型,并且变量名必须是Id
- 配置.ini文件,设置Excel读取和输出的路径
- 接下来,我们在Tools文件夹下新建一个ExcelToLua.bat文件,用来自动将Excel文件生成出对应的lua文件
cd ./XlsxTools/Xls2Lua/Xls2Lua/bin/Debug/
Xls2Lua ^
pause
双击运行即可生成Lua配置文件
3.使用Lua配置文件
- 创建ExcelMgr 来管理所有的lua配置文件
ExcelMgr = {
}
-- Excel表管理器
ExcelMgr.CacheTable = {
}
ExcelMgr.CacheTableRow = {
}
function ExcelMgr:GetTable(tableName)
local oneTable = self.CacheTable[tableName]
if oneTable ~= nil then
return oneTable
end
oneTable = require(tableName)
self.CacheTable[tableName] = oneTable
return self.CacheTable[tableName]
end
function ExcelMgr:GetRow(tableName, id)
if self.CacheTableRow[tableName] == nil then
local oneTable = self:GetTable(tableName)
self.CacheTableRow[tableName] = {
}
for _,v in ipairs(oneTable) do
self.CacheTableRow[tableName][v.Id]= v
end
end
if self.CacheTableRow[tableName] then
return self.CacheTableRow[tableName][id]
end
end
return ExcelMgr
边栏推荐
- Fiddler installed the certificate, or prompted that the certificate is invalid
- 项目经理,你会画原型嘛?项目经理需要做产品设计了?
- Basic knowledge and examples of binary tree
- [buuctf.reverse] 159_ [watevrCTF 2019]Watshell
- Compilation et connexion de shader dans games202 - webgl (comprendre la direction)
- MySQL if and ifnull use
- Flink kakfa data read and write to Hudi
- ISP learning (2)
- 2021 RoboCom 世界机器人开发者大赛-本科组(复赛)
- Postman关联
猜你喜欢
Postman manage test cases
麦斯克电子IPO被终止:曾拟募资8亿 河南资产是股东
Idea one key guide package
The IPO of mesk Electronics was terminated: Henan assets, which was once intended to raise 800 million yuan, was a shareholder
趋势前沿 | 达摩院语音 AI 最新技术大全
ORM aggregate query and native database operation
Yolov5 tensorrt acceleration
Vite configures the development environment and production environment
Application of Flody
Ora-01779: the column corresponding to the non key value saving table cannot be modified
随机推荐
The underlying structure of five data types in redis
Flody的应用
Zynq learning notes (3) - partial reconfiguration
acwing周赛58
Collection + interview questions
Simple understanding of interpreters and compilers
Flink kakfa data read and write to Hudi
关于es8316的音频爆破音的解决
The IPO of mesk Electronics was terminated: Henan assets, which was once intended to raise 800 million yuan, was a shareholder
Programmers' position in the Internet industry | daily anecdotes
Request (request object) and response (response object)
Postman test report
Summary of redis AOF and RDB knowledge points
力扣(LeetCode)186. 翻转字符串里的单词 II(2022.07.05)
Compilation and connection of shader in games202 webgl (learn from)
Building intelligent gray-scale data system from 0 to 1: Taking vivo game center as an example
Hometown 20 years later (primary school exercises)
Fiddler installed the certificate, or prompted that the certificate is invalid
行业专网对比公网,优势在哪儿?能满足什么特定要求?
从0到1建设智能灰度数据体系:以vivo游戏中心为例