Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature10/spring bone editor #994

Merged
merged 16 commits into from
Jun 1, 2021
Merged
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
using System.Text;
using UnityEditor;
using UnityEngine;

namespace UniVRM10
{
Expand Down
28 changes: 28 additions & 0 deletions Assets/VRM10/Editor/Components/Expression/ExpressionSlider.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
using System.Collections.Generic;
using UnityEditor;
using UnityEngine;

namespace UniVRM10
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

いずれ Editor 向けのクラスは UniVRM10.Editor にしたい

{
public class ExpressionSlider
{
Dictionary<ExpressionKey, float> m_expressionKeys;
ExpressionKey m_key;

public ExpressionSlider(Dictionary<ExpressionKey, float> expressionKeys, ExpressionKey key)
{
m_expressionKeys = expressionKeys;
m_key = key;
}

public KeyValuePair<ExpressionKey, float> Slider()
{
var oldValue = m_expressionKeys[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<ExpressionKey, float>(m_key, newValue);
}
}
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
using System.Collections.Generic;
using System.Linq;
using UnityEditor;
using UnityEngine;

namespace UniVRM10
{
//
// Expression 向けの Inspector
//
// Runtime に Expression 操作用の Slider を表示する
//
class VRM10ControllerEditorExpression
{
VRM10Controller m_target;
Dictionary<ExpressionKey, float> m_expressionKeyWeights = new Dictionary<ExpressionKey, float>();
List<ExpressionSlider> m_sliders;

public VRM10ControllerEditorExpression(VRM10Controller target)
{
m_target = target;

m_expressionKeyWeights = m_target.Expression.Clips.ToDictionary(x => ExpressionKey.CreateFromClip(x), x => 0.0f);
m_sliders = m_target.Expression.Clips
.Where(x => x != null)
.Select(x => new ExpressionSlider(m_expressionKeyWeights, ExpressionKey.CreateFromClip(x)))
.ToList()
;
}

public void OnGUI()
{
EditorGUILayout.Space();

if (!Application.isPlaying)
{
EditorGUILayout.HelpBox("Enable when playing", MessageType.Info);
}

if (m_sliders != null)
{
EditorGUILayout.Space();
EditorGUILayout.LabelField("Expression Weights", EditorStyles.boldLabel);

var sliders = m_sliders.Select(x => x.Slider());
foreach (var slider in sliders)
{
m_expressionKeyWeights[slider.Key] = slider.Value;
}
m_target.Expression.SetWeights(m_expressionKeyWeights);
}

EditorGUILayout.Space();
EditorGUILayout.LabelField("Override rates", EditorStyles.boldLabel);
EditorGUI.BeginDisabledGroup(true);
{
EditorGUILayout.Slider("Blink override rate", m_target.Expression.BlinkOverrideRate, 0f, 1f);
EditorGUILayout.Slider("LookAt override rate", m_target.Expression.LookAtOverrideRate, 0f, 1f);
EditorGUILayout.Slider("Mouth override rate", m_target.Expression.MouthOverrideRate, 0f, 1f);
}
EditorGUI.EndDisabledGroup();
}
}
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions Assets/VRM10/Editor/Components/LookAt.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

62 changes: 62 additions & 0 deletions Assets/VRM10/Editor/Components/LookAt/LookAtEditor.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
using UnityEditor;
using UnityEngine;

namespace UniVRM10
{
public static class LookAtEditor
{
public static void Draw2D(VRM10Controller target)
{

}

public static void Draw3D(VRM10Controller target)
{
if(target==null)
{
return;
}
OnSceneGUIOffset(target);
if (!Application.isPlaying)
{
// offset
var p = target.LookAt.OffsetFromHead;
Handles.Label(target.Head.position, $"fromHead: [{p.x:0.00}, {p.y:0.00}, {p.z:0.00}]");
}
else
{
target.LookAt.OnSceneGUILookAt(target.Head);
}
}

static void OnSceneGUIOffset(VRM10Controller m_target)
{
if (!m_target.LookAt.DrawGizmo)
{
return;
}

var head = m_target.Head;
if (head == null)
{
return;
}

EditorGUI.BeginChangeCheck();

var worldOffset = head.localToWorldMatrix.MultiplyPoint(m_target.LookAt.OffsetFromHead);
worldOffset = Handles.PositionHandle(worldOffset, head.rotation);

Handles.DrawDottedLine(head.position, worldOffset, 5);
Handles.SphereHandleCap(0, head.position, Quaternion.identity, 0.02f, Event.current.type);
Handles.SphereHandleCap(0, worldOffset, Quaternion.identity, 0.02f, Event.current.type);

if (EditorGUI.EndChangeCheck())
{
Undo.RecordObject(m_target, "Changed FirstPerson");

m_target.LookAt.OffsetFromHead = head.worldToLocalMatrix.MultiplyPoint(worldOffset);
}
}
}
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

41 changes: 41 additions & 0 deletions Assets/VRM10/Editor/Components/PropGui.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
using UnityEditor;

namespace UniVRM10
{
/// <summary>
/// 指定した SerializedProperty を起点に再帰的に SerializedProperty を表示する。
/// </summary>
class PropGui
{
SerializedProperty m_root;

public PropGui(SerializedProperty property)
{
m_root = property;
}

// public static PropGui FromSerializedObject(SerializedObject serializedObject, string name)
// {
// var prop = serializedObject.FindProperty(name);
// return new PropGui(prop);
// }

public void RecursiveProperty()
{
var depth = m_root.depth;
var iterator = m_root.Copy();
for (var enterChildren = true; iterator.NextVisible(enterChildren); enterChildren = false)
{
if (iterator.depth < depth)
return;

depth = iterator.depth;

using (new EditorGUI.DisabledScope("m_Script" == iterator.propertyPath))
{
EditorGUILayout.PropertyField(iterator, true);
}
}
}
}
}
11 changes: 11 additions & 0 deletions Assets/VRM10/Editor/Components/PropGui.cs.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

44 changes: 44 additions & 0 deletions Assets/VRM10/Editor/Components/ScrollView.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
using System;
using UnityEditor;
using UnityEngine;

namespace UniVRM10
{
public class ScrollView
{
Vector2 m_scrollPosition;

public void Draw(float height, Action content, Action repaint)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

やっぱ IMGUI の部品作ろうと思うと Action 渡すしかないよなあ~…

{
m_scrollPosition = EditorGUILayout.BeginScrollView(m_scrollPosition);

// mouse wheel scroll part 1
var isScroll = Event.current.isScrollWheel;
if (isScroll)
{
m_scrollPosition += Event.current.delta * EditorGUIUtility.singleLineHeight;
if (m_scrollPosition.y < 0)
{
m_scrollPosition = Vector2.zero;
}
}

content();

// mouse wheel scroll part 2
var bottom = EditorGUILayout.GetControlRect();
if (isScroll)
{
var maxScroll = bottom.y - (height - EditorGUIUtility.singleLineHeight * 2);
// Debug.Log($"{bottom.y}: {this.position.size.y}: {maxScroll}");
if (m_scrollPosition.y > maxScroll)
{
m_scrollPosition = new Vector2(0, maxScroll);
}
repaint();
}

EditorGUILayout.EndScrollView();
}
}
}
11 changes: 11 additions & 0 deletions Assets/VRM10/Editor/Components/ScrollView.cs.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading