From ab1f61e560bc3a16328ae64ab7630b2d1766aac0 Mon Sep 17 00:00:00 2001 From: Masataka SUMI Date: Thu, 1 Jul 2021 20:48:29 +0900 Subject: [PATCH] make public resource unique method --- .../UniGLTF/IO/Parser/GlbLowLevelParser.cs | 20 ++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/Assets/UniGLTF/Runtime/UniGLTF/IO/Parser/GlbLowLevelParser.cs b/Assets/UniGLTF/Runtime/UniGLTF/IO/Parser/GlbLowLevelParser.cs index 28591e952..b518b9b9a 100644 --- a/Assets/UniGLTF/Runtime/UniGLTF/IO/Parser/GlbLowLevelParser.cs +++ b/Assets/UniGLTF/Runtime/UniGLTF/IO/Parser/GlbLowLevelParser.cs @@ -2,6 +2,7 @@ using System.Collections.Generic; using System.IO; using System.Text; +using System.Text.RegularExpressions; using UniJSON; namespace UniGLTF @@ -13,6 +14,8 @@ namespace UniGLTF public sealed class GlbLowLevelParser { public static readonly string UniqueFixResourceSuffix = "__UNIGLTF__DUPLICATED__"; + private static readonly Regex _removeUniqueFixResourceSuffix = new Regex($@"^(.+){UniqueFixResourceSuffix}(\d+)$"); + private readonly string _path; private readonly byte[] _binary; @@ -274,7 +277,7 @@ namespace UniGLTF } } - private static string FixNameUnique(HashSet used, string originalName) + public static string FixNameUnique(HashSet used, string originalName) { if (used.Add(originalName)) { @@ -291,5 +294,20 @@ namespace UniGLTF } } } + + public static bool TryGetOriginalName(string name, out string originalName) + { + var match = _removeUniqueFixResourceSuffix.Match(name); + if (match.Success) + { + originalName = match.Groups[1].Value; + return true; + } + else + { + originalName = name; + return false; + } + } } } \ No newline at end of file