private IEnumerator TestAnimationRunner()
        {
            _updateFrame = 0;
            UpdateSprite(_updateFrame);
            UnscaledTimer timer = new UnscaledTimer();

            timer.StartNewTime(_animation.FrameTime * _animation.GetFrame(0).Length);
            while (_looping)
            {
                if (!_looping)
                {
                    break;
                }
                if (timer.IsActive)
                {
                    yield return(null);
                }
                _updateFrame++;
                var frame = _animation.GetFrame(_updateFrame);
                if (frame == null)
                {
                    _updateFrame = 0;
                    frame        = _animation.GetFrame(_updateFrame);
                }
                timer.StartNewTime(_animation.FrameTime * frame.Length);
                UpdateSprite(_updateFrame);
                yield return(null);
            }
        }
Beispiel #2
0
        //public static void TestAnimationEvent(int entityId, string clip) {
        //    var entity = EntityController.GetEntity(entityId);
        //    if (entity == null) {
        //        return;
        //    }
        //    var handle = new TestReceiver<AnimatorEvent>();
        //    entity.AddObserver(handle);
        //    entity.Post(new PlayAnimation(entity, clip, new AnimatorEvent(entity, clip, true, true)));
        //    handle.OnDel += receiver => entity.RemoveObserver(handle);
        //}

        private static IEnumerator RunTimerTest(float length)
        {
            var watch = new System.Diagnostics.Stopwatch();

            watch.Start();
            var timer = new UnscaledTimer(length);

            timer.StartTimer();
            var startTime = TimeManager.TimeUnscaled;

            while (timer.IsActive)
            {
                yield return(null);
            }
            watch.Stop();
            Debug.LogFormat("Stop Watch Seconds {0} Ms {1} Manual {2} Timer {3}", watch.Elapsed.TotalSeconds, watch.Elapsed.Milliseconds, TimeManager.TimeUnscaled - startTime, length);
        }
        private IEnumerator PlayAnimation(ClipAnimator animator, AnimationClipState state)
        {
            if (!Application.isPlaying)
            {
                AnimationMode.StartAnimationMode();
            }
            int limiter = 0;

            _animationTime    = 0;
            _canPlay          = true;
            _currentAnimation = state;
            _currentFrame     = 0;
            UnscaledTimer normalLimited = null;
            int           lastFrame     = 999;
            var           weaponTrails  = animator.GetComponentInChildren <WeaponModel>(true);

            while (limiter < 99999)
            {
                limiter++;
                if (_currentAnimation == null || !_canPlay)
                {
                    break;
                }
                switch (_playType)
                {
                case PlayType.Percent:
                    _animationTime = _forceTime;
                    break;

                case PlayType.Normal:
                case PlayType.Limited:
                case PlayType.NormalLimited:
                    _animationTime += TimeManager.DeltaUnscaled * state.PlaySpeedMultiplier;
                    break;

                case PlayType.Frame:
                    //_animationTime = state.ConvertFrameToAnimationTime(_currentFrame);
                    _currentFrame = _forceFrame;
                    break;
                }
                switch (_playType)
                {
                case PlayType.Limited:
                case PlayType.Percent:
                case PlayType.Normal:
                case PlayType.NormalLimited:
                    if (_animationTime > state.ClipLength)
                    {
                        _animationTime -= state.ClipLength;
                    }
                    _currentFrame = _currentAnimation.CalculateCurrentFrame(_animationTime);
                    switch (_playType)
                    {
                    case PlayType.Percent:
                    case PlayType.Limited:
                        if (_currentFrame < 0)
                        {
                            _animationTime = 0;
                            continue;
                        }
                        break;
                    }
                    break;
                }
                switch (_playType)
                {
                default:
                    if (_currentFrame != lastFrame)
                    {
                        _currentAnimation.Play(animator.Animator, _currentAnimation.ConvertFrameToAnimationTime(_currentFrame));
                        if (weaponTrails != null)
                        {
                            if (state.Events[_currentFrame] == AnimationEvents.FxOn)
                            {
                                weaponTrails.SetFx(true);
                            }
                            else if (state.Events[_currentFrame] == AnimationEvents.FxOff)
                            {
                                weaponTrails.SetFx(false);
                            }
                        }
                    }
                    break;

                case PlayType.Normal:
                    _currentAnimation.Play(animator.Animator, _animationTime);
                    break;

                case PlayType.NormalLimited:
                    if (normalLimited == null)
                    {
                        normalLimited = new UnscaledTimer(1 / state.Fps);
                    }
                    if (!normalLimited.IsActive)
                    {
                        _currentAnimation.Play(animator.Animator, _animationTime);
                        normalLimited.StartNewTime(1 / state.Fps);
                    }
                    break;
                }
                lastFrame = _currentFrame;
                SceneView.RepaintAll();
                yield return(null);
            }
            if (!Application.isPlaying)
            {
                AnimationMode.StopAnimationMode();
            }
            _currentAnimation = null;
        }
Beispiel #4
0
 public RuntimeNode(DummyStateNode node, RuntimeStateGraph graph) : base(node, graph)
 {
     _exitNode = GetOriginalNodeExit();
     _timer    = new UnscaledTimer(node._timer);
 }