mirror of
https://github.com/vrm-c/UniVRM.git
synced 2026-09-08 03:48:19 -05:00
WIP EditorTool
This commit is contained in:
@@ -1,60 +0,0 @@
|
||||
using UnityEditor;
|
||||
using UnityEngine;
|
||||
|
||||
namespace UniVRM10
|
||||
{
|
||||
public static class LookAtEditor
|
||||
{
|
||||
public static void Draw2D(VRM10Controller target)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public static void Draw3D(VRM10Controller target, Transform head)
|
||||
{
|
||||
if (target == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
if (!target.DrawLookAtGizmo)
|
||||
{
|
||||
return;
|
||||
}
|
||||
if (head == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
OnSceneGUIOffset(target, head);
|
||||
if (!Application.isPlaying)
|
||||
{
|
||||
// offset
|
||||
var p = target.Vrm.LookAt.OffsetFromHead;
|
||||
Handles.Label(head.position, $"fromHead: [{p.x:0.00}, {p.y:0.00}, {p.z:0.00}]");
|
||||
}
|
||||
else
|
||||
{
|
||||
target.Vrm.LookAt.OnSceneGUILookAt(head, target.LookAtTargetType, target.Gaze);
|
||||
}
|
||||
}
|
||||
|
||||
static void OnSceneGUIOffset(VRM10Controller m_target, Transform head)
|
||||
{
|
||||
EditorGUI.BeginChangeCheck();
|
||||
|
||||
var worldOffset = head.localToWorldMatrix.MultiplyPoint(m_target.Vrm.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.Vrm.LookAt.OffsetFromHead = head.worldToLocalMatrix.MultiplyPoint(worldOffset);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -81,7 +81,6 @@ namespace UniVRM10
|
||||
enum VRMSceneUI
|
||||
{
|
||||
Constraints,
|
||||
LookAt,
|
||||
SpringBone,
|
||||
}
|
||||
static VRMSceneUI s_ui = default;
|
||||
@@ -110,11 +109,6 @@ namespace UniVRM10
|
||||
Tools.hidden = false;
|
||||
break;
|
||||
|
||||
case VRMSceneUI.LookAt:
|
||||
Tools.hidden = true;
|
||||
LookAtEditor.Draw3D(Root, m_head);
|
||||
break;
|
||||
|
||||
case VRMSceneUI.SpringBone:
|
||||
Tools.hidden = true;
|
||||
SpringBoneEditor.Draw3D(Root, m_so);
|
||||
@@ -169,10 +163,6 @@ namespace UniVRM10
|
||||
m_scrollView.Draw(this.position.y, DrawConstraints, Repaint);
|
||||
break;
|
||||
|
||||
case VRMSceneUI.LookAt:
|
||||
LookAtEditor.Draw2D(Root);
|
||||
break;
|
||||
|
||||
case VRMSceneUI.SpringBone:
|
||||
SpringBoneEditor.Draw2D(Root, m_so);
|
||||
break;
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 8823eaceb68051c43be15ea92028d412
|
||||
guid: af5da07aebd9a47428d49b56b245b095
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
47
Assets/VRM10/Editor/EditorTool/VRM10ConstraintEditorTool.cs
Normal file
47
Assets/VRM10/Editor/EditorTool/VRM10ConstraintEditorTool.cs
Normal file
@@ -0,0 +1,47 @@
|
||||
using System;
|
||||
using UnityEngine;
|
||||
using UnityEditor;
|
||||
using UnityEditor.EditorTools;
|
||||
|
||||
|
||||
[EditorTool("vrm-1.0/Constraint", typeof(UniVRM10.VRM10Controller))]
|
||||
class VRM10ConstraintEditorTool : EditorTool
|
||||
{
|
||||
static GUIContent s_cachedIcon;
|
||||
// NOTE: as were caching this, unity will serialize it between compiles! so if we want to test out new looks,
|
||||
// just return the new GUIContent and bypass the cache until were happy with the icon...
|
||||
public override GUIContent toolbarIcon
|
||||
{
|
||||
get
|
||||
{
|
||||
if (s_cachedIcon == null)
|
||||
{
|
||||
s_cachedIcon = EditorGUIUtility.IconContent("RelativeJoint2D Icon", "|vrm-1.0 Constraint");
|
||||
}
|
||||
return s_cachedIcon;
|
||||
}
|
||||
}
|
||||
|
||||
// This is called for each window that your tool is active in. Put the functionality of your tool here.
|
||||
public override void OnToolGUI(EditorWindow window)
|
||||
{
|
||||
EditorGUI.BeginChangeCheck();
|
||||
|
||||
Vector3 position = Tools.handlePosition;
|
||||
|
||||
using (new Handles.DrawingScope(Color.green))
|
||||
{
|
||||
position = Handles.Slider(position, Vector3.right);
|
||||
}
|
||||
|
||||
if (EditorGUI.EndChangeCheck())
|
||||
{
|
||||
Vector3 delta = position - Tools.handlePosition;
|
||||
|
||||
Undo.RecordObjects(Selection.transforms, "Move Platform");
|
||||
|
||||
foreach (var transform in Selection.transforms)
|
||||
transform.position += delta;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,5 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 0f9ee1d04c43d8048a51e032b19a8ebd
|
||||
guid: 2ba15b8483408784a85713de9f2a4120
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
91
Assets/VRM10/Editor/EditorTool/VRM10LookAtEditorTool.cs
Normal file
91
Assets/VRM10/Editor/EditorTool/VRM10LookAtEditorTool.cs
Normal file
@@ -0,0 +1,91 @@
|
||||
using System;
|
||||
using UnityEngine;
|
||||
using UnityEditor;
|
||||
using UnityEditor.EditorTools;
|
||||
|
||||
|
||||
namespace UniVRM10
|
||||
{
|
||||
[EditorTool("vrm-1.0/LookAt", typeof(UniVRM10.VRM10Controller))]
|
||||
class VRM10LookAtEditorTool : EditorTool
|
||||
{
|
||||
static GUIContent s_cachedIcon;
|
||||
public override GUIContent toolbarIcon
|
||||
{
|
||||
get
|
||||
{
|
||||
if (s_cachedIcon == null)
|
||||
{
|
||||
s_cachedIcon = EditorGUIUtility.IconContent("d_BillboardRenderer Icon", "|vrm-1.0 LookAt");
|
||||
}
|
||||
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;
|
||||
}
|
||||
if (!root.DrawLookAtGizmo)
|
||||
{
|
||||
return;
|
||||
}
|
||||
var humanoid = root.GetComponent<UniHumanoid.Humanoid>();
|
||||
var head = humanoid.Head;
|
||||
if (head == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
{
|
||||
EditorGUI.BeginChangeCheck();
|
||||
|
||||
var worldOffset = head.localToWorldMatrix.MultiplyPoint(root.Vrm.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(root.Vrm, "LookAt.OffsetFromHead");
|
||||
|
||||
root.Vrm.LookAt.OffsetFromHead = head.worldToLocalMatrix.MultiplyPoint(worldOffset);
|
||||
}
|
||||
}
|
||||
|
||||
if (!Application.isPlaying)
|
||||
{
|
||||
// offset
|
||||
var p = root.Vrm.LookAt.OffsetFromHead;
|
||||
Handles.Label(head.position, $"fromHead: [{p.x:0.00}, {p.y:0.00}, {p.z:0.00}]");
|
||||
}
|
||||
else
|
||||
{
|
||||
root.Vrm.LookAt.OnSceneGUILookAt(head, root.LookAtTargetType, root.Gaze);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
11
Assets/VRM10/Editor/EditorTool/VRM10LookAtEditorTool.cs.meta
Normal file
11
Assets/VRM10/Editor/EditorTool/VRM10LookAtEditorTool.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: a780c0aef1cdb9a4895e352e39ad40b9
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
47
Assets/VRM10/Editor/EditorTool/VRM10SpringBoneEditorTool.cs
Normal file
47
Assets/VRM10/Editor/EditorTool/VRM10SpringBoneEditorTool.cs
Normal file
@@ -0,0 +1,47 @@
|
||||
using System;
|
||||
using UnityEngine;
|
||||
using UnityEditor;
|
||||
using UnityEditor.EditorTools;
|
||||
|
||||
|
||||
[EditorTool("vrm-1.0/SpringBone", typeof(UniVRM10.VRM10Controller))]
|
||||
class VRM10SpringBoneEditorTool : EditorTool
|
||||
{
|
||||
static GUIContent s_cachedIcon;
|
||||
// NOTE: as were caching this, unity will serialize it between compiles! so if we want to test out new looks,
|
||||
// just return the new GUIContent and bypass the cache until were happy with the icon...
|
||||
public override GUIContent toolbarIcon
|
||||
{
|
||||
get
|
||||
{
|
||||
if (s_cachedIcon == null)
|
||||
{
|
||||
s_cachedIcon = EditorGUIUtility.IconContent("SpringJoint Icon", "|vrm-1.0 SpringBone");
|
||||
}
|
||||
return s_cachedIcon;
|
||||
}
|
||||
}
|
||||
|
||||
// This is called for each window that your tool is active in. Put the functionality of your tool here.
|
||||
public override void OnToolGUI(EditorWindow window)
|
||||
{
|
||||
EditorGUI.BeginChangeCheck();
|
||||
|
||||
Vector3 position = Tools.handlePosition;
|
||||
|
||||
using (new Handles.DrawingScope(Color.green))
|
||||
{
|
||||
position = Handles.Slider(position, Vector3.right);
|
||||
}
|
||||
|
||||
if (EditorGUI.EndChangeCheck())
|
||||
{
|
||||
Vector3 delta = position - Tools.handlePosition;
|
||||
|
||||
Undo.RecordObjects(Selection.transforms, "Move Platform");
|
||||
|
||||
foreach (var transform in Selection.transforms)
|
||||
transform.position += delta;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 2df947254482d5b4d9b07c268a72db5d
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -6,7 +6,8 @@
|
||||
"GUID:5f875fdc81c40184c8333b9d63c6ddd5",
|
||||
"GUID:8d76e605759c3f64a957d63ef96ada7c",
|
||||
"GUID:da3e51d19d51a544fa14d43fee843098",
|
||||
"GUID:7da8a75dcade2144aab699032d7d7987"
|
||||
"GUID:7da8a75dcade2144aab699032d7d7987",
|
||||
"GUID:b7aa47b240b57de44a4b2021c143c9bf"
|
||||
],
|
||||
"includePlatforms": [
|
||||
"Editor"
|
||||
|
||||
Reference in New Issue
Block a user