diff --git a/Scripts/BlendShape/BlendShapeAvatar.cs b/Scripts/BlendShape/BlendShapeAvatar.cs index cc2cb36e6..606dd62ea 100644 --- a/Scripts/BlendShape/BlendShapeAvatar.cs +++ b/Scripts/BlendShape/BlendShapeAvatar.cs @@ -3,6 +3,10 @@ using System.Linq; using System; using System.Collections.Generic; using UniGLTF; +using System.IO; +#if UNITY_EDITOR +using UnityEditor; +#endif namespace VRM { @@ -37,6 +41,31 @@ namespace VRM } Clips = Clips.OrderBy(x => BlendShapeKey.CreateFrom(x)).ToList(); } + + public void AddBlendShapeClip() + { + var dir = Path.GetDirectoryName(AssetDatabase.GetAssetPath(this)); + var path = EditorUtility.SaveFilePanel( + "Create BlendShapeClip", + dir, + string.Format("BlendShapeClip#{0}.asset", Clips.Count), + "asset"); + if (string.IsNullOrEmpty(path)) + { + return; + } + path = path.ToUnityRelativePath(); + //Debug.LogFormat("{0}", path); + var clip = ScriptableObject.CreateInstance(); + clip.BlendShapeName = Path.GetFileNameWithoutExtension(path); + clip.Prefab = AssetDatabase.LoadAssetAtPath(AssetDatabase.GetAssetPath(this)); + AssetDatabase.CreateAsset(clip, path); + AssetDatabase.ImportAsset(path); + + Clips.Add(clip); + EditorUtility.SetDirty(this); + AssetDatabase.SaveAssets(); + } #endif /// diff --git a/Scripts/BlendShape/Editor/BlendShapeAvatarEditor.cs b/Scripts/BlendShape/Editor/BlendShapeAvatarEditor.cs index f3657d42f..0e72aba9b 100644 --- a/Scripts/BlendShape/Editor/BlendShapeAvatarEditor.cs +++ b/Scripts/BlendShape/Editor/BlendShapeAvatarEditor.cs @@ -16,30 +16,6 @@ namespace VRM .Select(x => x.ToString()).ToArray(); BlendShapeAvatar m_target; - void AddBlendShapeClip() - { - var dir = Path.GetDirectoryName(AssetDatabase.GetAssetPath(m_target)); - var path = EditorUtility.SaveFilePanel( - "Create BlendShapeClip", - dir, - string.Format("BlendShapeClip#{0}.asset", m_target.Clips.Count), - "asset"); - if (string.IsNullOrEmpty(path)) - { - return; - } - path = path.ToUnityRelativePath(); - //Debug.LogFormat("{0}", path); - var clip = ScriptableObject.CreateInstance(); - clip.BlendShapeName = Path.GetFileNameWithoutExtension(path); - clip.Prefab = AssetDatabase.LoadAssetAtPath(AssetDatabase.GetAssetPath(m_target)); - AssetDatabase.CreateAsset(clip, path); - AssetDatabase.ImportAsset(path); - - m_target.Clips.Add(clip); - EditorUtility.SetDirty(m_target); - AssetDatabase.SaveAssets(); - } BlendShapeClip m_currentClip; BlendShapeClip CurrentClip @@ -119,7 +95,7 @@ namespace VRM // Add if (GUILayout.Button("Add BlendShapeClip")) { - AddBlendShapeClip(); + m_target.AddBlendShapeClip(); } if (CurrentClip != null)