Пример #1
0
    IEnumerator Blink()
    {
        if (_VisibleController != null)
        {
            _VisibleController.AddPushKey(_BlinkKeyCode);
            float blinkTime = Random.Range(_MinBlinkTime, _MaxBlinkTime);
            yield return(new WaitForSeconds(blinkTime));

            _VisibleController.RemovePushKey(_BlinkKeyCode);
        }
        else
        {
            yield return(null);
        }
    }
Пример #2
0
    void Update()
    {
        if (context == null)
        {
            return;
        }

        var frame = context.GetCurrentPhonemeFrame();

        if (frame == null)
        {
            return;
        }

        transitionTimer += Time.deltaTime;

        // 設定したフレームレートへUpdate関数を低下させる
        frameRateTimer += Time.deltaTime;
        if (frameRateTimer < 1.0f / frameRate)
        {
            return;
        }
        frameRateTimer -= 1.0f / frameRate;

        foreach (var key in _Keys)
        {
            if (_VisibleController)
            {
                _VisibleController.RemovePushKey(key);
            }
        }

        // 最大の重みを持つ音素を探す
        var maxVisemeIndex  = 0;
        var maxVisemeWeight = 0.0f;

        // 子音は無視する
        for (var i = (int)OVRLipSync.Viseme.aa; i < frame.Visemes.Length; i++)
        {
            var weight = frame.Visemes[i];
            if (i == (int)OVRLipSync.Viseme.E)
            {
                weight *= eRate;
            }
            //Debug.Log((OVRLipSync.Viseme)i + " = " + weight);
            if (weight > maxVisemeWeight)
            {
                maxVisemeWeight = weight;
                maxVisemeIndex  = i;
            }
        }

        // 音素の重みが小さすぎる場合は口を閉じる
        if (maxVisemeWeight * 100.0f < weightThreashold)
        {
            transitionTimer = 0.0f;
            return;
        }

        // 音素の切り替わりでタイマーをリセットする
        if (previousViseme != (OVRLipSync.Viseme)maxVisemeIndex)
        {
            transitionTimer = 0.0f;
            previousViseme  = (OVRLipSync.Viseme)maxVisemeIndex;
        }

        var visemeIndex = maxVisemeIndex - (int)OVRLipSync.Viseme.aa;

        if (visemeIndex >= 0 && visemeIndex < _Keys.Length)
        {
            if (_VisibleController)
            {
                _VisibleController.AddPushKey(_Keys[visemeIndex]);
            }
        }
    }