diff --git a/Assets/VRM/Editor/Format/VRMSampleCopy.cs b/Assets/VRM/Editor/Format/VRMSampleCopy.cs index 028d90ce1..9724cbce1 100644 --- a/Assets/VRM/Editor/Format/VRMSampleCopy.cs +++ b/Assets/VRM/Editor/Format/VRMSampleCopy.cs @@ -1,11 +1,30 @@ using System; using System.IO; +using System.Linq; using UnityEngine; namespace VRM { public static class VRMSampleCopy { + struct CopyInfo + { + public string Src; + public string Dst; + + public CopyInfo(string src, string dst) + { + Src = src; + Dst = dst; + } + } + + static CopyInfo[] CopyList = new CopyInfo[]{ + new CopyInfo(Path.Combine(Application.dataPath, "VRM_Samples"), Path.Combine(Application.dataPath, "VRM/Samples~")), + new CopyInfo(Path.Combine(Application.dataPath, "VRM10_Samples"), Path.Combine(Application.dataPath, "VRM10/Samples~")), + new CopyInfo(Path.Combine(Application.dataPath, "UniGLTF_Samples"), Path.Combine(Application.dataPath, "UniGLTF/Samples~")), + }; + /// /// Assets/VRM_Samples /// を @@ -24,9 +43,10 @@ namespace VRM /// public static void Execute() { - Copy(Path.Combine(Application.dataPath, "VRM_Samples"), Path.Combine(Application.dataPath, "VRM/Samples~")); - Copy(Path.Combine(Application.dataPath, "VRM10_Samples"), Path.Combine(Application.dataPath, "VRM10/Samples~")); - Copy(Path.Combine(Application.dataPath, "UniGLTF_Samples"), Path.Combine(Application.dataPath, "UniGLTF/Samples~")); + foreach (var info in CopyList) + { + Copy(info.Src, info.Dst); + } } static void Copy(string srcDir, string dstDir) @@ -61,5 +81,61 @@ namespace VRM throw new FileNotFoundException(src); } } + + public static bool Validate() + { + return CopyList.All(x => _Validate(x.Src, x.Dst)); + } + + static bool _Validate(string src, string dst) + { + if (Directory.Exists(src)) + { + if (!Directory.Exists(dst)) + { + Debug.LogError($"{dst} not exists"); + return false; + + } + var list = Directory.EnumerateFileSystemEntries(dst).Select(x => x.Substring(dst.Length + 1)).ToList(); + foreach (var child in Directory.EnumerateFileSystemEntries(src)) + { + if (!_Validate(child, Path.Combine(dst, Path.GetFileName(child)).Replace("\\", "/"))) + { + return false; + } + var rel = child.Substring(src.Length + 1); + list.Remove(rel); + } + if (list.Count > 0) + { + var remain = string.Join(",", list); + Debug.LogError($"only dst: {remain}"); + return false; + } + return true; + } + else if (File.Exists(src)) + { + // same file + if (!File.Exists(dst)) + { + Debug.LogError($"{dst} not exists"); + return false; + } + if (!File.ReadAllBytes(src).SequenceEqual(File.ReadAllBytes(dst))) + { + Debug.LogError($"{src} != {dst}"); + return false; + } + return true; + } + else + { + // throw new FileNotFoundException(src); + Debug.LogError($"dir nor file"); + return false; + } + } } } diff --git a/Assets/VRM/Editor/VRMExportUnityPackage.cs b/Assets/VRM/Editor/VRMExportUnityPackage.cs index 4b43eac49..532809479 100644 --- a/Assets/VRM/Editor/VRMExportUnityPackage.cs +++ b/Assets/VRM/Editor/VRMExportUnityPackage.cs @@ -187,6 +187,11 @@ namespace VRM.DevOnly.PackageExporter public static void CreateUnityPackages(string outputDir) { + if (!VRMSampleCopy.Validate()) + { + throw new Exception("SampleCopy is not same !"); + } + { var packages = new[]{ // VRM