BlendShapeProxyのEditorモード廃止とMaterialMorph対応

This commit is contained in:
ousttrue
2018-04-09 20:24:52 +09:00
parent c9bec38fea
commit bdd80e112e
5 changed files with 119 additions and 107 deletions

View File

@@ -1,62 +0,0 @@
using UnityEditor;
using UnityEngine;
namespace VRM
{
class BlendShapeSlider
{
VRMBlendShapeProxy m_target;
BlendShapeKey m_key;
float? m_editorValue;
public BlendShapeSlider(VRMBlendShapeProxy target, BlendShapeKey key)
{
m_target = target;
m_key = key;
}
public void Slider()
{
if (m_target.BlendShapeAvatar == null)
{
return;
}
if (Application.isPlaying)
{
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);
}
}
else
{
var oldValue = m_editorValue.HasValue ? m_editorValue.Value : 0.0f;
var newValue = EditorGUILayout.Slider(m_key.ToString(), oldValue, 0, 1.0f);
if (oldValue != newValue)
{
var clip = m_target.BlendShapeAvatar.GetClip(m_key);
if (clip != null)
{
clip.Apply(m_target.transform, newValue);
m_editorValue = newValue;
}
}
}
}
public void RestoreEditorValue()
{
if (m_editorValue.HasValue)
{
var clip = m_target.BlendShapeAvatar.GetClip(m_key);
if (clip != null)
{
clip.Apply(m_target.transform, m_editorValue.Value);
}
}
}
}
}

View File

@@ -1,12 +0,0 @@
fileFormatVersion: 2
guid: 84dd38a83c8fb594484159a563312a26
timeCreated: 1520579905
licenseType: Free
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -1,6 +1,4 @@
using System.Collections.Generic;
using System.Linq;
using UnityEditor;
using UnityEditor;
using UnityEngine;
@@ -11,29 +9,19 @@ namespace VRM
{
VRMBlendShapeProxy m_target;
SkinnedMeshRenderer[] m_renderers;
List<BlendShapeSlider> m_sliders;
void OnEnable()
{
m_target = (VRMBlendShapeProxy)target;
if (m_target.BlendShapeAvatar != 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_sliders != null)
if (m_target.Sliders != null)
{
foreach (var slider in m_sliders)
foreach (var slider in m_target.Sliders)
{
slider.Slider();
}