当前位置: 首页 > news >正文

Unity 接入Luabn记录图解

Luban

      • 文档及链接
      • 项目目录
      • UnityEditor 导表工具

文档及链接

官方文档

最新版本

项目目录

接入的方法有很多,我这里随便找了一种

https://gitee.com/focus-creative-games/luban_examples.git

如上图,git拉去后,只保留圈起来的2个文件夹。基础使用已经够了

每个项目工程目录不尽相同,这里及以下根据我自己的项目目录配置,

在Unity平级目录创建一个文件夹,用来存放导表工具Luban

将上面Git保留的2个文件夹放入这个文件夹下,如上图

这个路径下存放的是配置表,将配表填入_tables_.xlsx中,用以生成表数据及代码

这个是生成工具,需要用文档打开,修改为自己路径

set WORKSPACE=..
set LUBAN_DLL=%WORKSPACE%\Tools\Luban\Luban.dll
set CONF_ROOT=.dotnet %LUBAN_DLL% ^-t client ^-c cs-simple-json ^-c cs-bin ^-d json ^-d bin ^--conf %CONF_ROOT%\luban.conf ^-x cs-simple-json.outputCodeDir=..\Code\Json ^-x cs-bin.outputCodeDir=..\..\ClientFrame\Assets\Game\Scripts\DataTable ^-x json.outputDataDir=..\..\ClientFrame\Assets\DataTable\Json ^-x bin.outputDataDir=..\..\ClientFrame\Assets\Res\Tablepause

这里同时导出了二进制和json,项目中用的是二进制,Json用于自己查表方便。可根据自己需求保留二进制和json
outputCodeDir是导出代码路径
outputDataDir是导出数据路径
可根据自己需求修改路径。

例如:只保留二进制

set WORKSPACE=..
set LUBAN_DLL=%WORKSPACE%\Tools\Luban\Luban.dll
set CONF_ROOT=.dotnet %LUBAN_DLL% ^-t client ^-c cs-bin ^-d bin ^--conf %CONF_ROOT%\luban.conf ^-x cs-bin.outputCodeDir=..\..\ClientFrame\Assets\Game\Scripts\DataTable ^-x bin.outputDataDir=..\..\ClientFrame\Assets\Res\Tablepause

UnityEditor 导表工具

每次导表需要到项目找到对应文件夹,执行bat,很麻烦。
在UnityEditor 加个工具,直接执行bat导表


using System.Diagnostics;
using System.IO;
using UnityEngine;
using UnityEditor;public class LubanExpand
{[MenuItem("Luban/Export Excel")]public static void ExecuteBat(){// 获取上一级目录var parentPath = Path.GetDirectoryName(Path.GetDirectoryName(Application.dataPath));// 确定 .bat 文件的绝对路径var batFilePath = Path.Combine(parentPath, "Luban/DataTables/gen.bat").Replace("\\", "/" );// 获取.bat文件所在目录var batDirectory = Path.GetDirectoryName(batFilePath);if (!File.Exists(batFilePath)){UnityEngine.Debug.LogError($"Bat file not found: {batFilePath}");return;}try{var processInfo = new ProcessStartInfo{FileName = batFilePath,UseShellExecute = false,          // 不使用系统ShellRedirectStandardOutput = true,    // 重定向输出RedirectStandardError = true,     // 重定向错误CreateNoWindow = false,            // 不创建新窗口WorkingDirectory = batDirectory   // 关键点:工作目录设为.bat所在文件夹};var process = new Process { StartInfo = processInfo };process.Start();// 读取输出(防止进程阻塞)var output = process.StandardOutput.ReadToEnd();var error = process.StandardError.ReadToEnd();process.WaitForExit();AssetDatabase.Refresh();if (!string.IsNullOrEmpty(output))UnityEngine.Debug.Log($"Bat Output:\n{output}");if (!string.IsNullOrEmpty(error))UnityEngine.Debug.LogError($"Bat Error:\n{error}");UnityEngine.Debug.Log("Bat executed successfully!");}catch (System.Exception e){UnityEngine.Debug.LogError($"Failed to execute bat: {e.Message}");}}
}

坑点:上面代码中 WorkingDirectory 是指定工作目录。如果不设置,工作目录会默认是Unity项目的Assets平级目录,gen.bat 里的WORKSPACE 生效错误,无法导出

http://www.lryc.cn/news/538439.html

相关文章:

  • 【MySQL】我在广州学Mysql 系列——Mysql 日志管理详解
  • 【线段树 二分查找】P3939 数颜色|普及+
  • 2011年下半年软件设计师考试上午题真题的详细知识点分类整理(附真题及答案解析)
  • tmagic-editor,腾讯开源的基于 Vue3 的页面可视化编辑器
  • K8s学习总结
  • 正则表达式(Regular expresssion)
  • Python的那些事第二十一篇:Python Web开发的“秘密武器”Flask
  • MySQL的聚簇索引与非聚簇索引
  • vscode的一些实用操作
  • C++11 thread
  • rabbitmq五种模式的总结——附java-se实现(详细)
  • Qt中基于开源库QRencode生成二维码(附工程源码链接)
  • Java数据结构---链表
  • mongodb是怎么分库分表的
  • C++自研游戏引擎-碰撞检测组件-八叉树AABB检测算法实现
  • spring boot对接clerk 实现用户信息获取
  • 一种动态地址的查询
  • 周雨彤:用角色与生活,诠释审美的艺术
  • 使用jks给空apk包签名
  • 500. 键盘行 771. 宝石与石头 简单 find接口的使用
  • 仙剑世界手游新手攻略 仙剑世界能用云手机玩吗
  • [题解]2024CCPC重庆站-小 C 的神秘图形
  • NPS内网穿透SSH使用手册
  • 大幂计算和大阶乘计算【C语言】
  • 【Linux】详谈 进程控制
  • Linux top 命令
  • Leetcode 424-替换后的最长重复字符
  • 《StyleDiffusion:通过扩散模型实现可控的解耦风格迁移》学习笔记
  • Django 创建表时 “__str__ ”方法的使用
  • 图像处理之CSC