public void UpdatePerFrame(float deltaTime)
        {
            float currentFrame = _prevFrame + (deltaTime * _frameRate);

            _timeline.Execute(_prevFrame, currentFrame);
            _prevFrame = currentFrame;
        }
Exemple #2
0
        public virtual void UpdatePerFrame(float deltaTime)
        {
            // 再生中でなく、「もう一回」がないなら、抜ける
            if (!_isPlaying)
            {
                return;
            }

            if (_lastAppliedFrame != _frame)
            {
                _lastAppliedFrame = _frame;
                Vector2 tmpVector2;
                // 計算するよ
                if (_scaleCurves != null)
                {
                    foreach (var curve in _scaleCurves)
                    {
                        // スケールは1値の場合と2値の場合がある
                        if (curve.type == AfterEffectsCurveSet.ValueType.Vector2)
                        {
                            _resource.GetVector2(out tmpVector2, curve.index, _frame);
                            curve.transform.localScale = new Vector3(tmpVector2.x, tmpVector2.y, 1f);
                        }
                        else
                        {
                            var v = _resource.GetFloat(curve.index, _frame);
                            curve.transform.localScale = new Vector3(v, v, 1f);
                        }
                    }
                }

                if (_rotationCurves != null)
                {
                    foreach (var curve in _rotationCurves)
                    {
                        float v = _resource.GetFloat(curve.index, _frame);
                        curve.transform.localRotation = Quaternion.Euler(0f, 0f, -v);                         //角度逆
                    }
                }

                if (_graphicPositionCurves != null)
                {
                    foreach (var curve in _graphicPositionCurves)
                    {
                        _resource.GetVector2(out tmpVector2, curve.index, _frame);
                        tmpVector2.y = -tmpVector2.y;                         // Yは反転。下プラス。
                        curve.transform.anchoredPosition = tmpVector2;
                    }
                }

                if (_graphicSizeCurves != null)
                {
                    foreach (var curve in _graphicSizeCurves)
                    {
                        _resource.GetVector2(out tmpVector2, curve.index, _frame);
                        curve.transform.sizeDelta = tmpVector2;
                    }
                }

                if (_spriteRendererPositionCurves != null)
                {
                    foreach (var curve in _spriteRendererPositionCurves)
                    {
                        _resource.GetVector2(out tmpVector2, curve.index, _frame);
                        // zはそのまま保つ
                        var p = curve.transform.localPosition;
                        p.x = tmpVector2.x;
                        p.y = -tmpVector2.y;                         //yは反転。下プラス。
                        curve.transform.localPosition = p;
                    }
                }

                if (_graphicOpacityCurves != null)
                {
                    foreach (var curve in _graphicOpacityCurves)
                    {
                        float v = _resource.GetFloat(curve.index, _frame);
                        var   c = curve.graphic.color;
                        c.a = v;
                        curve.graphic.color = c;
                    }
                }

                if (_canvasGroupOpacityCurves != null)
                {
                    foreach (var curve in _canvasGroupOpacityCurves)
                    {
                        float v = _resource.GetFloat(curve.index, _frame);
                        curve.canvasGroup.alpha = v;
                    }
                }

                if (_spriteRendererOpacityCurves != null)
                {
                    foreach (var curve in _spriteRendererOpacityCurves)
                    {
                        float v = _resource.GetFloat(curve.index, _frame);
                        var   c = curve.spriteRenderer.color;
                        c.a = v;
                        curve.spriteRenderer.color = c;
                    }
                }

                if (_graphicVisibilityCurves != null)
                {
                    foreach (var curve in _graphicVisibilityCurves)
                    {
                        var v = _resource.GetBool(curve.index, _frame);
                        curve.graphic.enabled = v;
                    }
                }

                if (_spriteRendererVisibilityCurves != null)
                {
                    foreach (var curve in _spriteRendererVisibilityCurves)
                    {
                        var v = _resource.GetBool(curve.index, _frame);
                        curve.spriteRenderer.enabled = v;
                    }
                }

                if (_gameObjectVisibilityCurves != null)
                {
                    foreach (var curve in _gameObjectVisibilityCurves)
                    {
                        var v   = _resource.GetBool(curve.index, _frame);
                        var obj = curve.gameObject;
                        if (v)
                        {
                            if (obj.activeSelf == false)
                            {
                                curve.gameObject.SetActive(true);
                            }
                        }
                        else
                        {
                            if (obj.activeSelf)
                            {
                                curve.gameObject.SetActive(false);
                            }
                        }
                    }
                }
            }

            if (_nextIsEnd)              //最終フレーム反映終了。完全に止める
            {
                _isPlaying = false;
                _nextIsEnd = false;
                if (_onEnd != null)
                {
                    _onEnd();
                }
            }
            else
            {
                var oldFrame = _frame;
                _frame += deltaTime * _resource.frameRate * speed;
                if (_callbackTimeline != null)
                {
                    _callbackTimeline.Execute(oldFrame, _frame);
                }

                // ループ処理
                float loopEnd = _cut.loopStart + _cut.loopDuration;
                while ((_frame > loopEnd) && (_currentLoopCount < _cut.loopCount))
                {
                    _frame -= _cut.loopDuration;                     //startに戻すわけではない。
                    if (_onLoop != null)
                    {
                        _onLoop();
                    }
                    _currentLoopCount++;
                }

                // 終了判定
                float end = _cut.start + _cut.duration;
                if (_frame > end)                 // ピッタリは終わらせない。最終フレームでspeed0で滞留、みたいなのを許す。
                {
                    bool nextExist = false;
                    if (_cut.nextCutName != null)                     // 自動遷移が設定されている
                    {
                        var cut = _resource.FindCut(_cut.nextCutName);
                        if (cut != null)
                        {
                            _cut              = cut;
                            _frame            = _cut.start + (_frame - end);                  // 余り分進めておく
                            _currentLoopCount = 0;
                            nextExist         = true;
                        }
                        else
                        {
                            Debug.LogError("auto transition failed. " + _cut.nextCutName + " is not found.");
                        }
                    }

                    if (!nextExist)
                    {
                        _nextIsEnd = true;
                        _frame     = end - _endTimeEpsilon;                     // 最終時刻寸前に合わせる
                    }
                }
            }
        }