diff --git a/Assets/VRM/UniGLTF/Scripts/IO/ImporterContext.cs b/Assets/VRM/UniGLTF/Scripts/IO/ImporterContext.cs index 7c9d2da87..f2054f465 100644 --- a/Assets/VRM/UniGLTF/Scripts/IO/ImporterContext.cs +++ b/Assets/VRM/UniGLTF/Scripts/IO/ImporterContext.cs @@ -804,14 +804,47 @@ namespace UniGLTF public virtual bool IsOverwrite(UnityEngine.Object o) { - if(o is Material) - { - return false; - } return true; } + public virtual bool LoadAsset(UnityPath assetPath, UnityEngine.Object o) + { + if (o is Material) + { + var loaded = assetPath.LoadAsset(); + + // replace member + for(int i=0; i< m_materials.Count; ++i) + { + if (m_materials[i] == o) + { + m_materials[i] = loaded; + break; + } + } + + // replace renderers.material + foreach(var mesh in Meshes) + { + foreach(var r in mesh.Renderers) + { + for(int i=0; i x == o ? loaded : x).ToArray(); + } + } + } + } + + return true; + } + + return false; + } + public void SaveAsAsset(UnityPath prefabPath) { ShowMeshes(); @@ -841,13 +874,14 @@ namespace UniGLTF { if (assetPath.IsFileExists) { - if (!IsOverwrite(o)) + if (LoadAsset(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 } }