From 404305d27c74c7f60c03c941a524bc3f3168be6d Mon Sep 17 00:00:00 2001 From: ousttrue Date: Mon, 16 Nov 2020 16:08:27 +0900 Subject: [PATCH] retry random name #611 --- Assets/VRM/UniGLTF/Scripts/IO/UnityPath.cs | 37 +++++++++++++++------- 1 file changed, 25 insertions(+), 12 deletions(-) diff --git a/Assets/VRM/UniGLTF/Scripts/IO/UnityPath.cs b/Assets/VRM/UniGLTF/Scripts/IO/UnityPath.cs index bc04c4ba8..bb236a463 100644 --- a/Assets/VRM/UniGLTF/Scripts/IO/UnityPath.cs +++ b/Assets/VRM/UniGLTF/Scripts/IO/UnityPath.cs @@ -142,10 +142,10 @@ namespace UniGLTF public override bool Equals(object obj) { - if(obj is UnityPath) + if (obj is UnityPath) { var rhs = (UnityPath)obj; - if(Value==null && rhs.Value == null) + if (Value == null && rhs.Value == null) { return true; } @@ -205,7 +205,7 @@ namespace UniGLTF { return new UnityPath { - Value="" + Value = "" }; } return FromFullpath(Path.GetFullPath(unityPath)); @@ -263,19 +263,20 @@ namespace UniGLTF /// public static UnityPath FromFullpath(string fullPath) { - if(fullPath == null) + if (fullPath == null) { fullPath = ""; } fullPath = fullPath.Replace("\\", "/"); - if (fullPath == BaseFullPath) { + if (fullPath == BaseFullPath) + { return new UnityPath { - Value="" + Value = "" }; } - else if(fullPath.StartsWith(BaseFullPath + "/")) + else if (fullPath.StartsWith(BaseFullPath + "/")) { return new UnityPath(fullPath.Substring(BaseFullPath.Length + 1)); } @@ -303,9 +304,9 @@ namespace UniGLTF { yield return this; - foreach(var child in ChildDirs) + foreach (var child in ChildDirs) { - foreach(var x in child.TraverseDir()) + foreach (var x in child.TraverseDir()) { yield return x; } @@ -317,7 +318,7 @@ namespace UniGLTF { get { - foreach(var x in Directory.GetDirectories(FullPath)) + foreach (var x in Directory.GetDirectories(FullPath)) { yield return UnityPath.FromFullpath(x); } @@ -398,7 +399,19 @@ namespace UniGLTF throw new NotImplementedException(); } - AssetDatabase.CreateAsset(o, Value); + try + { + AssetDatabase.CreateAsset(o, Value); + } + catch (UnityException) + { + // アセットを作ることができないファイル名だったと仮定。 + // 元のファイル名のどこに問題があるか不明なので Guid で置き換える。 + var newName = $"{Parent.Value}/{Guid.NewGuid().ToString("N")}{Extension}"; + Debug.LogWarning($"rename: {Value} => {newName}"); + + AssetDatabase.CreateAsset(o, newName); + } } public void AddObjectToAsset(UnityEngine.Object o) @@ -430,6 +443,6 @@ namespace UniGLTF return new UnityPath(AssetDatabase.GenerateUniqueAssetPath(Value)); } - #endif +#endif } }