From 7a09b5930712e839465bc8c86c161946407d7fa4 Mon Sep 17 00:00:00 2001 From: ousttrue Date: Sat, 26 Jan 2019 17:18:36 +0900 Subject: [PATCH] Load and assign VRMBlendShapeProxy.BlendShapeAvatar when importer avoid overwrite #142 --- .../VRM/UniGLTF/Scripts/IO/ImporterContext.cs | 22 +++---------------- .../Scripts/Format/VRMImporterContext.cs | 19 ++++++++++------ 2 files changed, 15 insertions(+), 26 deletions(-) diff --git a/Assets/VRM/UniGLTF/Scripts/IO/ImporterContext.cs b/Assets/VRM/UniGLTF/Scripts/IO/ImporterContext.cs index f2054f465..82c78e51e 100644 --- a/Assets/VRM/UniGLTF/Scripts/IO/ImporterContext.cs +++ b/Assets/VRM/UniGLTF/Scripts/IO/ImporterContext.cs @@ -802,29 +802,13 @@ namespace UniGLTF } } - public virtual bool IsOverwrite(UnityEngine.Object o) - { - - return true; - } - - public virtual bool LoadAsset(UnityPath assetPath, UnityEngine.Object o) + public virtual bool AvoidOverwriteAndLoad(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 + // replace component reference foreach(var mesh in Meshes) { foreach(var r in mesh.Renderers) @@ -874,7 +858,7 @@ namespace UniGLTF { if (assetPath.IsFileExists) { - if (LoadAsset(assetPath, o)) + if (AvoidOverwriteAndLoad(assetPath, o)) { // 上書きせずに既存のアセットからロードして置き換えた continue; 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)