Beispiel #1
0
        protected void PlayToState(State state)
        {
            // set the animation time that we want to play to
            targetAnimationEndTime = GetNormalizedTimeForState(state);

            // note that the normalizedTime always resets to zero after finishing the clip.
            // so if switch was at Up and it was already done playing, its normalizedTime is
            // 0f, even though the Up state corresponds to a time of 1f. so, for this special
            // case, force it to 1f.
            if (CurrentState == State.Up &&
                animationState.normalizedTime == 0f &&
                !SwitchAnimation.isPlaying)
            {
                animationState.normalizedTime = 1f;
            }

            // move either up or down depending on where the switch is right now
            animationState.speed =
                Mathf.Sign(targetAnimationEndTime - animationState.normalizedTime) * 2f;

            // play animation and actuate switch
            SwitchAnimation.Play(animationName);
            SetState(state);

            // play sound effect if available
            if (SoundEffect != null)
            {
                SoundEffect.Play();
            }
        }
Beispiel #2
0
        protected void GoToState(State state)
        {
            SetState(state);

            // switch to animation state instantly
            animationState.normalizedTime = GetNormalizedTimeForState(state);
            animationState.speed          = 0f;
            SwitchAnimation.Play(animationName);
        }
Beispiel #3
0
 public static string GetCssClass(this SwitchAnimation animation)
 {
     return(animation switch
     {
         SwitchAnimation.Flip => "switch-icon-flip",
         SwitchAnimation.Fade => "switch-icon-fade",
         SwitchAnimation.Scale => "switch-icon-scale",
         SwitchAnimation.SlideUp => "switch-icon-slide-up",
         SwitchAnimation.SlideLeft => "switch-icon-slide-left",
         SwitchAnimation.SlideDown => "switch-icon-slide-down",
         SwitchAnimation.SlideRight => "switch-icon-slide-right",
         _ => "",
     });
Beispiel #4
0
        public override void Update()
        {
            bool isAnimationPlaying = SwitchAnimation.isPlaying;

            if (SwitchAnimation.isPlaying &&
                ((animationState.speed > 0f && animationState.normalizedTime >= targetAnimationEndTime) ||
                 (animationState.speed < 0f && animationState.normalizedTime <= targetAnimationEndTime)))
            {
                Utils.Log("Stopped anim at " + animationState.normalizedTime.ToString("F2"));
                SwitchAnimation.Stop();
            }

            // check if animation finished playing
            if (!isAnimationPlaying && isAnimationPlayingPrev)
            {
                ExecuteSignal();
            }

            // keep track of whether animation was playing
            isAnimationPlayingPrev = isAnimationPlaying;
        }