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

View File

@ -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<BlendShapeSlider> m_sliders;
public List<BlendShapeSlider> 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()