示例#1
0
    public async Task PlayActionAnimation_Animator(int actionId, AnimActionType animActionType, float playSpeedMultiplier)
    {
        // If animator is not null, play the action animation
        ActionAnimation actionAnimation;
        AnimationClip   clip;
        float           triggerDuration;
        float           extraDuration;
        AudioClip       audioClip;

        if (GameInstance.ActionAnimations.TryGetValue(actionId, out actionAnimation) &&
            actionAnimation.GetData(this, out clip, out triggerDuration, out extraDuration, out audioClip))
        {
            CacheAnimator.SetBool(ANIM_DO_ACTION, false);
            CacheAnimatorController[ANIM_STATE_ACTION_CLIP] = clip;
            if (audioClip != null)
            {
                AudioSource.PlayClipAtPoint(audioClip, CacheTransform.position, AudioManager.Singleton == null ? 1f : AudioManager.Singleton.sfxVolumeSetting.Level);
            }
            CacheAnimator.SetFloat(ANIM_ACTION_CLIP_MULTIPLIER, playSpeedMultiplier);
            CacheAnimator.SetBool(ANIM_DO_ACTION, true);
            // Waits by current transition + clip duration before end animation
            int waitDelay = (int)(1000 * (CacheAnimator.GetAnimatorTransitionInfo(0).duration + (clip.length / playSpeedMultiplier)));
            await Task.Delay(waitDelay);

            CacheAnimator.SetBool(ANIM_DO_ACTION, false);
            // Waits by current transition + extra duration before end playing animation state
            waitDelay = (int)(1000 * (CacheAnimator.GetAnimatorTransitionInfo(0).duration + (extraDuration / playSpeedMultiplier)));
            await Task.Delay(waitDelay);
        }
    }
示例#2
0
        private IEnumerator PlayActionAnimation_Animator(AnimActionType animActionType, int dataId, int index, float playSpeedMultiplier)
        {
            // If animator is not null, play the action animation
            tempActionAnimation = GetActionAnimation(animActionType, dataId, index);
            if (tempActionAnimation != null && tempActionAnimation.clip != null)
            {
                CacheAnimator.SetBool(ANIM_DO_ACTION, false);
                CacheAnimatorController[ANIM_STATE_ACTION_CLIP] = tempActionAnimation.clip;
                var audioClip = tempActionAnimation.GetRandomAudioClip();
                if (audioClip != null)
                {
                    AudioSource.PlayClipAtPoint(audioClip, CacheTransform.position, AudioManager.Singleton == null ? 1f : AudioManager.Singleton.sfxVolumeSetting.Level);
                }
                CacheAnimator.SetFloat(ANIM_ACTION_CLIP_MULTIPLIER, playSpeedMultiplier);
                CacheAnimator.SetBool(ANIM_DO_ACTION, true);
                // Waits by current transition + clip duration before end animation
                yield return(new WaitForSecondsRealtime(CacheAnimator.GetAnimatorTransitionInfo(0).duration + (tempActionAnimation.GetClipLength() / playSpeedMultiplier)));

                CacheAnimator.SetBool(ANIM_DO_ACTION, false);
                // Waits by current transition + extra duration before end playing animation state
                yield return(new WaitForSecondsRealtime(CacheAnimator.GetAnimatorTransitionInfo(0).duration + (tempActionAnimation.GetExtraDuration() / playSpeedMultiplier)));
            }
        }