diff --git a/Scripts/BlendShape/Editor/VRMBlnedShapeProxyEditor.cs b/Scripts/BlendShape/Editor/VRMBlnedShapeProxyEditor.cs index 6a7408b31..11de4603d 100644 --- a/Scripts/BlendShape/Editor/VRMBlnedShapeProxyEditor.cs +++ b/Scripts/BlendShape/Editor/VRMBlnedShapeProxyEditor.cs @@ -1,5 +1,7 @@ -using UnityEditor; +using System.Collections.Generic; +using UnityEditor; using UnityEngine; +using System.Linq; namespace VRM @@ -10,18 +12,54 @@ namespace VRM VRMBlendShapeProxy m_target; SkinnedMeshRenderer[] m_renderers; + public class BlendShapeSlider + { + VRMBlendShapeProxy m_target; + BlendShapeKey m_key; + + public BlendShapeSlider(VRMBlendShapeProxy target, BlendShapeKey key) + { + m_target = target; + m_key = key; + } + + public void Slider() + { + if (m_target.BlendShapeAvatar == null) + { + return; + } + + var oldValue = m_target.GetValue(m_key); + var newValue = EditorGUILayout.Slider(m_key.ToString(), oldValue, 0, 1.0f); + if (oldValue != newValue) + { + m_target.SetValue(m_key, newValue); + } + } + } + List m_sliders; + void OnEnable() { m_target = (VRMBlendShapeProxy)target; + if (m_target.BlendShapeAvatar != null && m_target.BlendShapeAvatar.Clips != null) + { + m_sliders = m_target.BlendShapeAvatar.Clips + .Where(x => x != null) + .Select(x => new BlendShapeSlider(m_target, BlendShapeKey.CreateFrom(x))) + .ToList() + ; + } } public override void OnInspectorGUI() { base.OnInspectorGUI(); - if (m_target.Sliders != null) + if (m_sliders != null) { - foreach (var slider in m_target.Sliders) + foreach (var slider in m_sliders) { slider.Slider(); } diff --git a/Scripts/BlendShape/VRMBlendShapeProxy.cs b/Scripts/BlendShape/VRMBlendShapeProxy.cs index 111bbe870..3fbb9d863 100644 --- a/Scripts/BlendShape/VRMBlendShapeProxy.cs +++ b/Scripts/BlendShape/VRMBlendShapeProxy.cs @@ -3,9 +3,6 @@ using System.Collections.Generic; using System.Linq; using UnityEngine; using UniGLTF; -#if UNITY_EDITOR -using UnityEditor; -#endif namespace VRM @@ -16,57 +13,6 @@ namespace VRM [SerializeField] public BlendShapeAvatar BlendShapeAvatar; -#if UNITY_EDITOR - public class BlendShapeSlider - { - VRMBlendShapeProxy m_target; - BlendShapeKey m_key; - - public BlendShapeSlider(VRMBlendShapeProxy target, BlendShapeKey key) - { - m_target = target; - m_key = key; - } - - public void Slider() - { - if (m_target.BlendShapeAvatar == null) - { - return; - } - - var oldValue = m_target.GetValue(m_key); - var newValue = EditorGUILayout.Slider(m_key.ToString(), oldValue, 0, 1.0f); - if (oldValue != newValue) - { - m_target.SetValue(m_key, newValue); - } - } - } - List m_sliders; - public List Sliders - { - get { return m_sliders; } - } - private void SetupSliders() - { - if (BlendShapeAvatar != null && BlendShapeAvatar.Clips != null) - { - m_sliders = BlendShapeAvatar.Clips - .Where(x => x != null) - .Select(x => new BlendShapeSlider(this, BlendShapeKey.CreateFrom(x))) - .ToList() - ; - } - } -#endif - - struct BlendShapePath - { - public String RelativePath; - public int Index; - } - delegate void BlendShapeSetter(float value); class BlendShapePathHandler @@ -74,13 +20,6 @@ namespace VRM public BlendShapeSetter Setter; float m_value; - /* - public void ReplaceValue(float value) - { - m_value = value; - } - */ - public void AddValue(float value) { m_value += value; @@ -244,10 +183,6 @@ namespace VRM } } } - -#if UNITY_EDITOR - SetupSliders(); -#endif } private void OnDestroy()