Move VRMBlnedShapeProxyEditor.BlendShapeSlider to VRMBlnedShapeProxyEditor.BlendShapeSlider

This commit is contained in:
ousttrue
2018-04-20 14:11:35 +09:00
parent 80e699ba2b
commit 9a2fd83fef
2 changed files with 41 additions and 68 deletions

View File

@@ -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<BlendShapeSlider> 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();
}