VRMBlnedShapeProxyEditor.cs
2.02 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
using System.Collections.Generic;
using UnityEditor;
using UnityEngine;
using System.Linq;
namespace VRM
{
[CustomEditor(typeof(VRMBlendShapeProxy))]
public class VRMBlnedShapeProxyEditor : Editor
{
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 KeyValuePair<BlendShapeKey, float> Slider()
{
var oldValue = m_target.GetValue(m_key);
var enable = GUI.enabled;
GUI.enabled = Application.isPlaying;
var newValue = EditorGUILayout.Slider(m_key.ToString(), oldValue, 0, 1.0f);
GUI.enabled = enable;
return new KeyValuePair<BlendShapeKey, float>(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 (!Application.isPlaying)
{
EditorGUILayout.HelpBox("Enable when playing", MessageType.Info);
}
if (m_target.BlendShapeAvatar == null)
{
return;
}
if (m_sliders != null)
{
m_target.SetValues(m_sliders.Select(x => x.Slider()));
}
}
}
}