【特性】新增unity ScriptableObject asset数据源支持

【优化】允许为目录数据源指定参数,这些参数会作用到所有目录下的子文件上
main
walon 2021-12-18 13:36:21 +08:00
parent 9e6463f18d
commit 6bc3552a1f
6 changed files with 107 additions and 31 deletions

View File

@ -25,7 +25,7 @@
luban相较于常规的excel导表工具有以下核心优势
- 增强了excel格式。可以比较简洁地excel配置**任意复杂**的数据,像子结构、结构列表,以及更复杂的深层次的嵌套结构都能直接解析处理。
- 完备的类型系统和多原始数据支持excel、xml、json、lua、yaml可以轻松表达和解析**任意复杂**的数据。意味着传统excel导表工具无法处理的技能、行为树、副本等等复杂配置luban也能够统一处理了彻底将程序从复杂的配置解析中解放出来。
- 完备的类型系统和多原始数据支持excel、xml、json、lua、yaml、unity asset),可以轻松表达和解析**任意复杂**的数据。意味着传统excel导表工具无法处理的技能、行为树、副本等等复杂配置luban也能够统一处理了彻底将程序从复杂的配置解析中解放出来。
- 支持binary、**protobuf**同时可以生成相应的pb定义、**msgpack**、**flatbuffers**、json、lua等多种导出数据格式。
- 完善的工作流支持。如id的外键引用检查;资源合法性检查;灵活的数据源定义(拆表或者多表合一);灵活的分组导出机制;多种本地化支持;生成极快日常迭代300ms以内[Excel2TextDiff](https://github.com/focus-creative-games/Excel2TextDiff)工具方便diff查看excel文件的版本间差异
- **LubanAssistant Excel插件**。支持把json、lua、xml等文本格式的配置数据加载到excel中批量编辑处理最后再保存回原文件较好地解决大型项目中多人合作数据编辑冲突合并的问题较好解决在编辑器中制作的配置难以在excel中批量修改的问题。
@ -45,7 +45,7 @@ luban相较于常规的excel导表工具有以下核心优势
## 特性
- 支持excel族、json、xml、lua、yaml 多种数据格式,基本统一了游戏常见的配置数据
- 支持excel族、json、xml、lua、yaml、unity asset等多种数据格式,基本统一了游戏常见的配置数据
- **强大完备的类型系统**。**可以优雅表达任意复杂的数据结构**。支持所有常见原生类型、text本地化类型、datetime类型、vector{2,3,4}、容器类型list,set,map、枚举和结构、**多态结构**以及**可空类型**。
- 支持增强的excel格式。可以在excel里比较简洁填写出任意复杂的嵌套数据。
- 生成代码清晰易读、良好模块化。支持指定变量命名风格约定。特地支持运行时原子性热更新配置。

View File

@ -0,0 +1,13 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Luban.Job.Cfg.DataCreators
{
class UnityAssetDataCreator : YamlDataCreator
{
public new static UnityAssetDataCreator Ins = new();
}
}

View File

@ -1,26 +0,0 @@
using Luban.Job.Cfg.Datas;
using Luban.Job.Common.Types;
using System;
using System.Collections.Generic;
using System.IO;
namespace Luban.Job.Cfg.DataSources.Binary
{
class BinaryDataSource : AbstractDataSource
{
public override void Load(string rawUrl, string sheetName, Stream stream)
{
throw new NotImplementedException();
}
public override List<Record> ReadMulti(TBean type)
{
throw new NotImplementedException();
}
public override Record ReadOne(TBean type)
{
throw new NotImplementedException();
}
}
}

View File

@ -15,7 +15,7 @@ namespace Luban.Job.Cfg.DataSources
".lua",
".json",
".yml",
".bin",
".asset",
};
public static AbstractDataSource Create(string url, string sheetName, Stream stream)
@ -32,8 +32,8 @@ namespace Luban.Job.Cfg.DataSources
case "xml": source = new Xml.XmlDataSource(); break;
case "lua": source = new Lua.LuaDataSource(); break;
case "json": source = new Json.JsonDataSource(); break;
case "bin": source = new Binary.BinaryDataSource(); break;
case "yml": source = new Yaml.YamlDataSource(); break;
case "asset": source = new UnityAsset.UnityAssetDataSource(); break;
default: throw new Exception($"不支持的文件类型:{url}");
}
source.Load(url, sheetName, stream);

View File

@ -0,0 +1,89 @@
using Luban.Job.Cfg.DataCreators;
using Luban.Job.Cfg.Datas;
using Luban.Job.Cfg.Defs;
using Luban.Job.Cfg.Utils;
using Luban.Job.Common.Types;
using System;
using System.Collections.Generic;
using System.IO;
using YamlDotNet.RepresentationModel;
using System.Linq;
namespace Luban.Job.Cfg.DataSources.UnityAsset
{
class UnityAssetDataSource : AbstractDataSource
{
private YamlNode _root;
public override void Load(string rawUrl, string sheetOrFieldName, Stream stream)
{
var ys = new YamlStream();
ys.Load(new StreamReader(stream));
var rootNode = (YamlMappingNode)ys.Documents[0].RootNode;
// unity asset 格式为 包含一个doc的 yaml文件
// doc顶层为map只包含一个字段字段key为类型名。
if (rootNode.Children.Count != 1)
{
throw new Exception($"asset doc 应该只包含一个顶层字段");
}
this._root = rootNode.First().Value;
if (!string.IsNullOrEmpty(sheetOrFieldName))
{
if (sheetOrFieldName.StartsWith("*"))
{
sheetOrFieldName = sheetOrFieldName[1..];
}
if (!string.IsNullOrEmpty(sheetOrFieldName))
{
foreach (var subField in sheetOrFieldName.Split('.'))
{
this._root = _root[new YamlScalarNode(subField)];
}
}
}
}
public override List<Record> ReadMulti(TBean type)
{
var records = new List<Record>();
foreach (var ele in (YamlSequenceNode)_root)
{
var rec = ReadRecord(ele, type);
if (rec != null)
{
records.Add(rec);
}
}
return records;
}
private static readonly YamlScalarNode s_tagNameNode = new(TAG_KEY);
public override Record ReadOne(TBean type)
{
return ReadRecord(_root, type);
}
private Record ReadRecord(YamlNode yamlNode, TBean type)
{
string tagName;
if (((YamlMappingNode)yamlNode).Children.TryGetValue(s_tagNameNode, out var tagNode))
{
tagName = (string)tagNode;
}
else
{
tagName = null;
}
if (DataUtil.IsIgnoreTag(tagName))
{
return null;
}
var data = (DBean)type.Apply(UnityAssetDataCreator.Ins, yamlNode, (DefAssembly)type.Bean.AssemblyBase);
var tags = DataUtil.ParseTags(tagName);
return new Record(data, RawUrl, tags);
}
}
}

View File

@ -51,7 +51,7 @@ namespace Luban.Job.Cfg.Utils
}
else
{
return fileOrDirContent.SubFiles.Select(f => new InputFileInfo() { OriginFile = f.FilePath, ActualFile = f.FilePath, MD5 = f.MD5 }).ToList();
return fileOrDirContent.SubFiles.Select(f => new InputFileInfo() { OriginFile = f.FilePath, ActualFile = f.FilePath, SheetName = sheetName, MD5 = f.MD5 }).ToList();
}
}));
}