add IVRMComponent to VRMLookAtBlendShapeApplyer

This commit is contained in:
ousttrue
2018-04-20 10:12:05 +09:00
parent 3dd41ce271
commit 80e699ba2b
3 changed files with 19 additions and 31 deletions

View File

@@ -4,7 +4,7 @@ using UnityEngine;
namespace VRM
{
public class VRMLookAtBlendShapeApplyer : MonoBehaviour
public class VRMLookAtBlendShapeApplyer : MonoBehaviour, IVRMComponent
{
public bool DrawGizmo = true;
@@ -17,17 +17,21 @@ namespace VRM
[SerializeField]
public CurveMapper VerticalUp = new CurveMapper(90.0f, 1.0f);
public void OnImported(VRMImporterContext context)
{
var gltfFirstPerson = context.VRM.extensions.VRM.firstPerson;
Horizontal.Apply(gltfFirstPerson.lookAtHorizontalOuter);
VerticalDown.Apply(gltfFirstPerson.lookAtVerticalDown);
VerticalUp.Apply(gltfFirstPerson.lookAtVerticalUp);
}
VRMLookAtHead m_head;
VRMBlendShapeProxy m_propxy;
private void Awake()
private void Start()
{
m_head = GetComponent<VRMLookAtHead>();
m_propxy = GetComponent<VRMBlendShapeProxy>();
}
private void OnEnable()
{
if (m_head == null)
{
enabled = false;
@@ -36,11 +40,6 @@ namespace VRM
m_head.YawPitchChanged += ApplyRotations;
}
private void OnDisable()
{
m_head.YawPitchChanged -= ApplyRotations;
}
void ApplyRotations(float yaw, float pitch)
{
if (yaw < 0)

View File

@@ -53,27 +53,18 @@ namespace VRM
VRMLookAtHead m_head;
void Update()
void Start()
{
m_head = GetComponent<VRMLookAtHead>();
if (m_head == null)
{
m_head = GetComponent<VRMLookAtHead>();
if (m_head == null)
{
enabled = false;
Debug.LogError("[VRMLookAtBoneApplyer]VRMLookAtHead not found");
return;
}
m_head.YawPitchChanged += ApplyRotations;
LeftEye.Setup();
RightEye.Setup();
enabled = false;
Debug.LogError("[VRMLookAtBoneApplyer]VRMLookAtHead not found");
return;
}
}
private void OnDisable()
{
m_head.YawPitchChanged -= ApplyRotations;
m_head = null;
m_head.YawPitchChanged += ApplyRotations;
LeftEye.Setup();
RightEye.Setup();
}
#region Gizmo

View File

@@ -103,9 +103,7 @@ namespace VRM
case LookAtType.BlendShape:
{
var applyer = gameObject.AddComponent<VRMLookAtBlendShapeApplyer>();
applyer.Horizontal.Apply(gltfFirstPerson.lookAtHorizontalOuter);
applyer.VerticalDown.Apply(gltfFirstPerson.lookAtVerticalDown);
applyer.VerticalUp.Apply(gltfFirstPerson.lookAtVerticalUp);
applyer.OnImported(context);
}
break;
}