コード例 #1
0
ファイル: UIManager.cs プロジェクト: 4026/ace-the-chase
 public void AddAnimationToQueue(QueuedAnimation queuedAnim)
 {
     queuedAnim.AnimationEndedTrigger = OnAnimationEnded;
     AnimationQueue.Add(queuedAnim);
     if (AnimationQueue.Count == 1)
     {
         AnimationQueue[0].Run();
     }
 }
コード例 #2
0
    private bool HandleGameActionAnimation()
    {
        foreach (GameActionUsedEventData gameActionEvent in PresentationEvents.GameActionEvents.SinceLastPresUpdate)
        {
            if (gameActionEvent.GameActionContext.LastPhysicalInstigator == SimEntity && gameActionEvent.GameActionContext.Action != Entity.Null && !_hasTriggeredAnAnimation)
            {
                TriggerAnimationInteruptionOnStateChange();

                _hasTriggeredAnAnimation = true;
                _lastTransitionTime      = SimWorld.Time.ElapsedTime;

                // GAME ACTION AUTH & ANIMATION TRIGGER
                SimWorld.TryGetComponent(gameActionEvent.GameActionContext.Action, out SimAssetId instigatorAssetId);
                GameObject instigatorPrefab = PresentationHelpers.FindSimAssetPrefab(instigatorAssetId);
                if (instigatorPrefab.TryGetComponent(out GameActionAuth gameActionAuth))
                {
                    _currentAnimation = gameActionAuth.Animation;

                    // add additionnal animation to play in queue (skip the first we'll play)
                    if (gameActionAuth.Animation != null)
                    {
                        for (int i = 1; i < gameActionEvent.GameActionResult.Count; i++)
                        {
                            // ANIMATION DATA
                            List <KeyValuePair <string, object> > currentAnimationData = new List <KeyValuePair <string, object> >();
                            currentAnimationData.Add(new KeyValuePair <string, object>("GameActionContext", gameActionEvent.GameActionContext));

                            switch (i)
                            {
                            case 1:
                                currentAnimationData.Add(new KeyValuePair <string, object>("GameActionContextResult", gameActionEvent.GameActionResult.DataElement_1));
                                break;

                            case 2:
                                currentAnimationData.Add(new KeyValuePair <string, object>("GameActionContextResult", gameActionEvent.GameActionResult.DataElement_2));
                                break;

                            case 3:
                                currentAnimationData.Add(new KeyValuePair <string, object>("GameActionContextResult", gameActionEvent.GameActionResult.DataElement_3));
                                break;

                            default:
                                break;
                            }

                            _queuedAnimations.Add(new QueuedAnimation()
                            {
                                Data = currentAnimationData, Definition = _currentAnimation, HasPlayed = false
                            });
                        }

                        // ANIMATION DATA
                        List <KeyValuePair <string, object> > animationData = new List <KeyValuePair <string, object> >();
                        animationData.Add(new KeyValuePair <string, object>("GameActionContext", gameActionEvent.GameActionContext));
                        animationData.Add(new KeyValuePair <string, object>("GameActionContextResult", gameActionEvent.GameActionResult.DataElement_0));

                        _currentAnimation.TriggerAnimation(SimEntity, _spriteStartPos, _bone, animationData);
                    }
                }

                _previousState = AnimationType.GameAction;
            }
        }

        if (!_hasTriggeredAnAnimation)
        {
            // find queued animation to play
            QueuedAnimation animationToPlay = null;
            for (int i = 0; i < _queuedAnimations.Count; i++)
            {
                if (!_queuedAnimations[i].HasPlayed)
                {
                    animationToPlay = _queuedAnimations[i];
                    _queuedAnimations[i].HasPlayed = true;
                    break;
                }
            }

            if (animationToPlay != null)
            {
                TriggerAnimationInteruptionOnStateChange();

                _hasTriggeredAnAnimation = true;
                _lastTransitionTime      = SimWorld.Time.ElapsedTime;

                _currentAnimation = animationToPlay.Definition ?? FindAnimation(AnimationType.GameAction);
                _currentAnimation.TriggerAnimation(SimEntity, _spriteStartPos, _bone, animationToPlay.Data);

                _previousState = AnimationType.GameAction;
            }
            else
            {
                _queuedAnimations.Clear();
            }
        }

        return(_hasTriggeredAnAnimation);
    }