diff --git a/Scripts/BlendShape/BlendShapeClip.cs b/Scripts/BlendShape/BlendShapeClip.cs index 7163ede38..dcc7aa5f2 100644 --- a/Scripts/BlendShape/BlendShapeClip.cs +++ b/Scripts/BlendShape/BlendShapeClip.cs @@ -24,6 +24,26 @@ namespace VRM [CreateAssetMenu(menuName = "VRM/BlendShapeClip")] public class BlendShapeClip : ScriptableObject { + [SerializeField] + GameObject m_prefab; + public GameObject Prefab + { + set { m_prefab = value; } + get { +#if UNITY_EDITOR + if (m_prefab == null) + { + var assetPath = UnityEditor.AssetDatabase.GetAssetPath(this); + if (!string.IsNullOrEmpty(assetPath)) + { + m_prefab = UnityEditor.AssetDatabase.LoadAssetAtPath(assetPath); + } + } +#endif + return m_prefab; + } + } + [SerializeField] public string BlendShapeName = ""; @@ -74,14 +94,5 @@ namespace VRM } */ } - - public static BlendShapeClip Create(BlendShapePreset preset) - { - var clip = ScriptableObject.CreateInstance(); - clip.Preset = preset; - clip.BlendShapeName = preset.ToString(); - clip.name = preset.ToString(); - return clip; - } } } diff --git a/Scripts/BlendShape/Editor/BlendShapeAvatarEditor.cs b/Scripts/BlendShape/Editor/BlendShapeAvatarEditor.cs index 3746edb6b..ff5a20863 100644 --- a/Scripts/BlendShape/Editor/BlendShapeAvatarEditor.cs +++ b/Scripts/BlendShape/Editor/BlendShapeAvatarEditor.cs @@ -32,6 +32,7 @@ namespace VRM Debug.LogFormat("{0}", path); var clip = ScriptableObject.CreateInstance(); m_target.Clips.Add(clip); + clip.Prefab = AssetDatabase.LoadAssetAtPath(AssetDatabase.GetAssetPath(m_target)); AssetDatabase.CreateAsset(clip, path); AssetDatabase.ImportAsset(path); } diff --git a/Scripts/BlendShape/Editor/BlendShapeClipEditor.cs b/Scripts/BlendShape/Editor/BlendShapeClipEditor.cs index 62d3435f7..2c0f1578e 100644 --- a/Scripts/BlendShape/Editor/BlendShapeClipEditor.cs +++ b/Scripts/BlendShape/Editor/BlendShapeClipEditor.cs @@ -23,8 +23,14 @@ namespace VRM BlendShapeClip m_target; bool m_changed; + protected override GameObject GetPrefab() + { + return m_target.Prefab; + } + void OnPrefabChanged() { + m_target.Prefab = Prefab; Bake(m_target.Values, m_target.MaterialValues, 1.0f); } diff --git a/Scripts/BlendShape/Editor/PreviewEditor.cs b/Scripts/BlendShape/Editor/PreviewEditor.cs index 8044ff531..aba657e78 100644 --- a/Scripts/BlendShape/Editor/PreviewEditor.cs +++ b/Scripts/BlendShape/Editor/PreviewEditor.cs @@ -40,10 +40,10 @@ namespace VRM /// Previewシーンに表示するPrefab /// GameObject m_prefab; - GameObject Prefab + protected GameObject Prefab { get { return m_prefab; } - set + private set { if (m_prefab == value) return; m_prefab = value; @@ -89,15 +89,20 @@ namespace VRM } } + protected virtual GameObject GetPrefab() + { + var assetPath = AssetDatabase.GetAssetPath(target); + if (string.IsNullOrEmpty(assetPath)) + { + return null; + } + return AssetDatabase.LoadAssetAtPath(assetPath); + } + protected virtual void OnEnable() { m_renderer = new PreviewFaceRenderer(); - var assetPath = AssetDatabase.GetAssetPath(target); - //Debug.LogFormat("assetPath: {0}", assetPath); - if (!string.IsNullOrEmpty(assetPath)) - { - Prefab = AssetDatabase.LoadAssetAtPath(assetPath); - } + Prefab = GetPrefab(); } protected virtual void OnDisable()