【优化】path检查支持 Assets/xxxx/yyyy[abc] 这样的子资源文件
parent
c009d54d26
commit
a560c23c67
|
|
@ -22,6 +22,10 @@
|
||||||
</None>
|
</None>
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<PackageReference Include="YamlDotNet" Version="11.2.1" />
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<ProjectReference Include="..\Luban.Common\Luban.Common.csproj" />
|
<ProjectReference Include="..\Luban.Common\Luban.Common.csproj" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
|
||||||
|
|
@ -2,8 +2,8 @@
|
||||||
"profiles": {
|
"profiles": {
|
||||||
"Luban.Client": {
|
"Luban.Client": {
|
||||||
"commandName": "Project",
|
"commandName": "Project",
|
||||||
"commandLineArgs": "-h %LUBAN_SERVER_IP% -j cfg -w ..\\DesignerConfigs\\Datas -- -d ..\\DesignerConfigs\\Defines\\__root__.xml --input_data_dir ..\\DesignerConfigs\\Datas --output_code_dir TsScripts/src/Gen/Cfg --output_data_dir ConfigData --gen_types code_typescript_bin,data_bin -s client --export_test_data --validate_root_dir Assets ",
|
"commandLineArgs": "-h %LUBAN_SERVER_IP% -j cfg -- -d ..\\..\\DesignerConfigs\\Defines\\__root__.xml --input_data_dir ..\\..\\DesignerConfigs\\Datas --output_code_dir Assets/Gen --output_data_dir ..\\GenerateDatas\\json --gen_types code_cs_unity_json,data_json -s all --validate_root_dir .",
|
||||||
"workingDirectory": "C:\\workspace\\unity-world\\Client"
|
"workingDirectory": "D:\\workspace\\luban_examples\\Projects\\Csharp_Unity_json"
|
||||||
},
|
},
|
||||||
"Luban.Client-db": {
|
"Luban.Client-db": {
|
||||||
"commandName": "Project",
|
"commandName": "Project",
|
||||||
|
|
|
||||||
|
|
@ -8,11 +8,14 @@ using Luban.Client.Common.Utils;
|
||||||
using Luban.Common.Protos;
|
using Luban.Common.Protos;
|
||||||
using Luban.Common.Utils;
|
using Luban.Common.Utils;
|
||||||
using System;
|
using System;
|
||||||
|
using System.Collections.Concurrent;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Net;
|
using System.Net;
|
||||||
|
using System.Text.RegularExpressions;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
|
using YamlDotNet.RepresentationModel;
|
||||||
|
|
||||||
namespace Luban.Client.Common.Net
|
namespace Luban.Client.Common.Net
|
||||||
{
|
{
|
||||||
|
|
@ -163,14 +166,84 @@ namespace Luban.Client.Common.Net
|
||||||
Session.ReplyRpc<GetInputFile, GetInputFileArg, GetInputFileRes>(rpc, res);
|
Session.ReplyRpc<GetInputFile, GetInputFileArg, GetInputFileRes>(rpc, res);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private readonly Regex _subResPattern = new Regex(@"(.+)\[(\d+)]$");
|
||||||
|
|
||||||
|
private readonly ConcurrentDictionary<string, YamlDocument> _cacheYamlDocs = new();
|
||||||
|
|
||||||
|
private YamlDocument GetCacheYamlDoc(string mainResFileName)
|
||||||
|
{
|
||||||
|
return _cacheYamlDocs.GetOrAdd(mainResFileName, (file) =>
|
||||||
|
{
|
||||||
|
var yamlStream = new YamlStream();
|
||||||
|
yamlStream.Load(new StreamReader(new FileStream(mainResFileName, FileMode.Open, FileAccess.Read, FileShare.ReadWrite)));
|
||||||
|
return yamlStream.Documents[0];
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
private bool CheckSubResourceExists(string mainResFileName, string subResName)
|
||||||
|
{
|
||||||
|
s_logger.Debug("check resources main:{} sub:{}", mainResFileName, subResName);
|
||||||
|
if (!File.Exists(mainResFileName))
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
try
|
||||||
|
{
|
||||||
|
var yamlNode = (YamlMappingNode) GetCacheYamlDoc(mainResFileName).RootNode;
|
||||||
|
var yamlSubResName = new YamlScalarNode(subResName);
|
||||||
|
foreach (var (resType, node) in yamlNode)
|
||||||
|
{
|
||||||
|
|
||||||
|
switch(resType.ToString())
|
||||||
|
{
|
||||||
|
case "SpriteAtlas":
|
||||||
|
{
|
||||||
|
var mnode = (YamlMappingNode)node;
|
||||||
|
var r = (YamlSequenceNode) mnode[new YamlScalarNode("m_PackedSpriteNamesToIndex")];
|
||||||
|
if (r == null)
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return r.Contains(yamlSubResName);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
s_logger.Error(ex);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private void Process(QueryFilesExists p)
|
private void Process(QueryFilesExists p)
|
||||||
{
|
{
|
||||||
var root = p.Arg.Root;
|
var root = p.Arg.Root;
|
||||||
var files = p.Arg.Files;
|
var files = p.Arg.Files;
|
||||||
var re = new QueryFilesExistsRes() { Exists = new List<bool>(files.Count) };
|
var re = new QueryFilesExistsRes() { Exists = new List<bool>(files.Count) };
|
||||||
|
|
||||||
|
var tasks = new List<Task<bool>>();
|
||||||
|
|
||||||
foreach (var f in files)
|
foreach (var f in files)
|
||||||
{
|
{
|
||||||
re.Exists.Add(File.Exists(Path.Combine(root, f)));
|
var match = _subResPattern.Match(f);
|
||||||
|
if (match.Success)
|
||||||
|
{
|
||||||
|
var groups = match.Groups;
|
||||||
|
tasks.Add(Task.Run(() => CheckSubResourceExists(Path.Join(root, groups[1].Value), groups[2].Value)));
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
tasks.Add(Task.Run(() => File.Exists(Path.Combine(root, f))));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Task.WhenAll(tasks);
|
||||||
|
foreach (var task in tasks)
|
||||||
|
{
|
||||||
|
re.Exists.Add(task.Result);
|
||||||
}
|
}
|
||||||
Session.ReplyRpc<QueryFilesExists, QueryFilesExistsArg, QueryFilesExistsRes>(p, re);
|
Session.ReplyRpc<QueryFilesExists, QueryFilesExistsArg, QueryFilesExistsRes>(p, re);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue