diff --git a/Scripts/LookAt/VRMLookAtBlendShapeApplyer.cs b/Scripts/LookAt/VRMLookAtBlendShapeApplyer.cs index be90dba13..a53ba3061 100644 --- a/Scripts/LookAt/VRMLookAtBlendShapeApplyer.cs +++ b/Scripts/LookAt/VRMLookAtBlendShapeApplyer.cs @@ -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(); m_propxy = GetComponent(); - } - - 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) diff --git a/Scripts/LookAt/VRMLookAtBoneApplyer.cs b/Scripts/LookAt/VRMLookAtBoneApplyer.cs index c634fccbd..d6588820e 100644 --- a/Scripts/LookAt/VRMLookAtBoneApplyer.cs +++ b/Scripts/LookAt/VRMLookAtBoneApplyer.cs @@ -53,27 +53,18 @@ namespace VRM VRMLookAtHead m_head; - void Update() + void Start() { + m_head = GetComponent(); if (m_head == null) { - m_head = GetComponent(); - 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 diff --git a/Scripts/LookAt/VRMLookAtHead.cs b/Scripts/LookAt/VRMLookAtHead.cs index 356239fe2..82bfc983a 100644 --- a/Scripts/LookAt/VRMLookAtHead.cs +++ b/Scripts/LookAt/VRMLookAtHead.cs @@ -103,9 +103,7 @@ namespace VRM case LookAtType.BlendShape: { var applyer = gameObject.AddComponent(); - applyer.Horizontal.Apply(gltfFirstPerson.lookAtHorizontalOuter); - applyer.VerticalDown.Apply(gltfFirstPerson.lookAtVerticalDown); - applyer.VerticalUp.Apply(gltfFirstPerson.lookAtVerticalUp); + applyer.OnImported(context); } break; }