diff --git a/Assets/VRM/UniGLTF/Scripts/IO/ImporterContext.cs b/Assets/VRM/UniGLTF/Scripts/IO/ImporterContext.cs index 7c9d2da87..82c78e51e 100644 --- a/Assets/VRM/UniGLTF/Scripts/IO/ImporterContext.cs +++ b/Assets/VRM/UniGLTF/Scripts/IO/ImporterContext.cs @@ -802,14 +802,31 @@ namespace UniGLTF } } - public virtual bool IsOverwrite(UnityEngine.Object o) + public virtual bool AvoidOverwriteAndLoad(UnityPath assetPath, UnityEngine.Object o) { - if(o is Material) + if (o is Material) { - return false; + var loaded = assetPath.LoadAsset(); + + // replace component reference + foreach(var mesh in Meshes) + { + foreach(var r in mesh.Renderers) + { + for(int i=0; i x == o ? loaded : x).ToArray(); + } + } + } + } + + return true; } - return true; + return false; } public void SaveAsAsset(UnityPath prefabPath) @@ -841,13 +858,14 @@ namespace UniGLTF { if (assetPath.IsFileExists) { - if (!IsOverwrite(o)) + if (AvoidOverwriteAndLoad(assetPath, o)) { - // 上書きしない - Debug.LogWarningFormat("already exists. skip {0}", assetPath); + // 上書きせずに既存のアセットからロードして置き換えた continue; } } + + // アセットとして書き込む assetPath.Parent.EnsureFolder(); assetPath.CreateAsset(o); paths.Add(assetPath); diff --git a/Assets/VRM/UniGLTF/Scripts/IO/MeshWithMaterials.cs b/Assets/VRM/UniGLTF/Scripts/IO/MeshWithMaterials.cs index 56838167b..42c2e11d4 100644 --- a/Assets/VRM/UniGLTF/Scripts/IO/MeshWithMaterials.cs +++ b/Assets/VRM/UniGLTF/Scripts/IO/MeshWithMaterials.cs @@ -8,6 +8,8 @@ namespace UniGLTF { public Mesh Mesh; public Material[] Materials; + + // 複数のノードから参照されうる public List Renderers=new List(); // SkinnedMeshRenderer or MeshRenderer } } diff --git a/Assets/VRM/UniVRM/Scripts/Format/VRMImporterContext.cs b/Assets/VRM/UniVRM/Scripts/Format/VRMImporterContext.cs index df4ffe155..e3b8d372d 100644 --- a/Assets/VRM/UniVRM/Scripts/Format/VRMImporterContext.cs +++ b/Assets/VRM/UniVRM/Scripts/Format/VRMImporterContext.cs @@ -341,18 +341,23 @@ namespace VRM } #if UNITY_EDITOR - public override bool IsOverwrite(UnityEngine.Object o) + public override bool AvoidOverwriteAndLoad(UnityPath assetPath, UnityEngine.Object o) { if (o is BlendShapeAvatar) { - return false; - } - if (o is BlendShapeClip) - { - return false; + var loaded = assetPath.LoadAsset(); + var proxy = Root.GetComponent(); + proxy.BlendShapeAvatar = loaded; + + return true; } - return base.IsOverwrite(o); + if (o is BlendShapeClip) + { + return true; + } + + return base.AvoidOverwriteAndLoad(assetPath, o); } protected override UnityPath GetAssetPath(UnityPath prefabPath, UnityEngine.Object o)