/**
 * Copyright(c) Live2D Inc. All rights reserved.
 *
 * Use of this source code is governed by the Live2D Open Software license
 * that can be found at https://www.live2d.com/eula/live2d-open-software-license-agreement_en.html.
 */
using UnityEngine;
namespace Live2D.Cubism.Framework.MouthMovement
{
    /// 
    /// Automatic mouth movement.
    /// 
    public sealed class CubismAutoMouthInput : MonoBehaviour
    {
        /// 
        /// Timescale.
        /// 
        [SerializeField]
        public float Timescale = 10f;
        /// 
        /// Target controller.
        /// 
        private CubismMouthController Controller { get; set; }
        /// 
        /// Current time.
        /// 
        private float T { get; set; }
        /// 
        /// Resets the input.
        /// 
        public void Reset()
        {
            T = 0f;
        }
        #region Unity Event Handling
        /// 
        /// Called by Unity. Initializes input.
        /// 
        private void Start()
        {
            Controller = GetComponent();
        }
        /// 
        /// Called by Unity. Updates controller.
        /// 
        /// 
        /// Make sure this method is called after any animations are evaluated.
        /// 
        private void LateUpdate()
        {
            // Fail silently.
            if (Controller == null)
            {
                return;
            }
            // Progress time.
            T += (Time.deltaTime * Timescale);
            // Evaluate.
            Controller.MouthOpening = Mathf.Abs(Mathf.Sin(T));
        }
        #endregion
    }
}