-
Notifications
You must be signed in to change notification settings - Fork 439
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1169 from ousttrue/feature10/add_expression_slider
play mode の expression preview
- Loading branch information
Showing
2 changed files
with
133 additions
and
0 deletions.
There are no files selected for viewing
122 changes: 122 additions & 0 deletions
122
Assets/VRM10/Editor/EditorTool/VRM10ExpressionEditorTool.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,122 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using UnityEditor; | ||
using UnityEditor.EditorTools; | ||
using UnityEngine; | ||
|
||
namespace UniVRM10 | ||
{ | ||
[EditorTool("vrm-1.0/Expression", typeof(UniVRM10.VRM10Controller))] | ||
class VRM10ExpressionEditorTool : EditorTool | ||
{ | ||
static GUIContent s_cachedIcon; | ||
public override GUIContent toolbarIcon | ||
{ | ||
get | ||
{ | ||
if (s_cachedIcon == null) | ||
{ | ||
s_cachedIcon = EditorGUIUtility.IconContent("d_Audio Mixer@2x", "|vrm-1.0 Expression"); | ||
} | ||
return s_cachedIcon; | ||
} | ||
} | ||
|
||
void OnEnable() | ||
{ | ||
EditorTools.activeToolChanged += ActiveToolDidChange; | ||
} | ||
|
||
void OnDisable() | ||
{ | ||
EditorTools.activeToolChanged -= ActiveToolDidChange; | ||
} | ||
|
||
void ActiveToolDidChange() | ||
{ | ||
if (!EditorTools.IsActiveTool(this)) | ||
{ | ||
return; | ||
} | ||
} | ||
|
||
public override void OnToolGUI(EditorWindow window) | ||
{ | ||
var root = Selection.activeTransform.GetComponent<VRM10Controller>(); | ||
if (root == null) | ||
{ | ||
return; | ||
} | ||
|
||
Handles.BeginGUI(); | ||
if (Application.isPlaying) | ||
{ | ||
ExpressionPreviewInPlay(root?.Vrm?.Expression); | ||
} | ||
else | ||
{ | ||
EditorGUILayout.HelpBox("expression preview in play mode", MessageType.Warning); | ||
} | ||
Handles.EndGUI(); | ||
} | ||
|
||
void ExpressionPreviewInPlay(VRM10ObjectExpression expression) | ||
{ | ||
if (expression == null) | ||
{ | ||
EditorGUILayout.HelpBox("no expression settings", MessageType.Warning); | ||
return; | ||
} | ||
|
||
EditorGUILayout.BeginHorizontal(); | ||
{ | ||
GUILayout.FlexibleSpace(); | ||
|
||
// 右よせ | ||
EditorGUILayout.BeginVertical(); | ||
{ | ||
GUILayout.FlexibleSpace(); | ||
|
||
m_map.Clear(); | ||
foreach (var kv in expression.GetWeights()) | ||
{ | ||
var key = kv.Key; | ||
if (kv.Key.Preset != ExpressionPreset.custom) | ||
{ | ||
var value = ExpressionPresetSlider(expression, kv.Key.Preset, kv.Value); | ||
m_map[key] = value; | ||
} | ||
} | ||
GUILayout.FlexibleSpace(); | ||
|
||
expression.SetWeights(m_map); | ||
} | ||
EditorGUILayout.EndVertical(); | ||
} | ||
EditorGUILayout.EndHorizontal(); | ||
} | ||
|
||
Dictionary<ExpressionKey, float> m_map = new Dictionary<ExpressionKey, float>(); | ||
static GUIStyle s_style; | ||
static GUIStyle Style | ||
{ | ||
get | ||
{ | ||
if (s_style == null) | ||
{ | ||
s_style = GUI.skin.GetStyle("box"); | ||
} | ||
return s_style; | ||
} | ||
} | ||
|
||
float ExpressionPresetSlider(VRM10ObjectExpression expression, ExpressionPreset preset, float value) | ||
{ | ||
EditorGUILayout.BeginHorizontal(Style); | ||
EditorGUILayout.LabelField(preset.ToString()); | ||
value = EditorGUILayout.Slider(value, 0, 1.0f); | ||
EditorGUILayout.EndHorizontal(); | ||
return value; | ||
} | ||
} | ||
} |
11 changes: 11 additions & 0 deletions
11
Assets/VRM10/Editor/EditorTool/VRM10ExpressionEditorTool.cs.meta
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.