Ejemplo n.º 1
0
        protected virtual void Apply()
        {
            float timeScale = this.timeScale;

            if (animator != null)
            {
                animator.speed = animatorSpeed * timeScale;

                // Unity 5.1:
                // animator.SetFloat("TimeScale", timeScale);
            }

            if (animation != null)
            {
                foreach (AnimationState animationState in animation)
                {
                    animationState.speed = animationSpeed * timeScale;
                }
            }

            if (particleSystem != null)
            {
                // Not needed anymore with manual simulation
                // particleSystem.playbackSpeed = particleSpeed * timeScale;
            }

            if (audioSource != null)
            {
                audioSource.pitch = audioSpeed * timeScale;
            }

            if (navigator != null)
            {
                navigator.speed        = navigationSpeed * timeScale;
                navigator.angularSpeed = navigationAngularSpeed * timeScale;
            }

            if (windZone != null)
            {
                WindZoneSpeeds speeds = windZoneSpeeds;

                windZone.windTurbulence     = speeds.turbulence * timeScale * Mathf.Abs(timeScale);
                windZone.windPulseFrequency = speeds.pulseFrequency * timeScale;
                windZone.windPulseMagnitude = speeds.pulseMagnitude * Mathf.Sign(timeScale);
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// The components used by the timeline are cached for performance optimization. If you add or remove the Animator, Animation, ParticleSystem, NavMeshAgent, AudioSource or WindZone on the GameObject, you need to call this method to update the timeline accordingly.
        /// </summary>
        public virtual void CacheComponents()
        {
            // For each component, we first check whether it was
            // present on the GameObject before this call. If it
            // wasn't and now is, we copy its properties. This way,
            // if we call CacheComponents after already having the component,
            // the properties won't be overwritten.

            // Animator

            bool hadAnimator = animator != null;

            animator = GetComponent <Animator>();

            if (!hadAnimator && animator != null)
            {
                animatorSpeed = animator.speed;
            }

            // Animation

            bool hadAnimation = animation != null;

            animation = GetComponent <Animation>();

            if (!hadAnimation && animation != null)
            {
                // Animations can have different speeds per state, but Chronos
                // doesn't support that yet. Warn if different speeds are found.

                float firstAnimationStateSpeed = 1;
                bool  found = false;

                foreach (AnimationState animationState in animation)
                {
                    if (found && firstAnimationStateSpeed != animationState.speed)
                    {
                        Debug.LogWarning("Different animation speeds per state are not supported.");
                    }

                    firstAnimationStateSpeed = animationState.speed;
                    found = true;
                }

                animationSpeed = firstAnimationStateSpeed;
            }

            // Particle System

            bool hadParticleSystem = particleSystem != null;

            particleSystem = GetComponent <ParticleSystem>();

            if (!hadParticleSystem && particleSystem != null)
            {
                particleSpeed = particleSystem.playbackSpeed;
                particleSeed  = (uint)Random.Range(0, int.MaxValue);
            }

            // Audio Source

            bool hadAudioSource = audioSource != null;

            audioSource = GetComponent <AudioSource>();

            if (!hadAudioSource && audioSource != null)
            {
                audioSpeed = audioSource.pitch;
            }

            // Navigator

            bool hadNavigator = navigator != null;

            navigator = GetComponent <UnityEngine.AI.NavMeshAgent>();

            if (!hadNavigator && navigator != null)
            {
                navigationSpeed        = navigator.speed;
                navigationAngularSpeed = navigator.angularSpeed;
            }

            // WindZone

            bool hadWindZone = windZone != null;

            windZone = GetComponent <WindZone>();

            if (!hadWindZone && windZone != null)
            {
                windZoneSpeeds = new WindZoneSpeeds()
                {
                    main           = windZone.windMain,
                    turbulence     = windZone.windTurbulence,
                    pulseFrequency = windZone.windPulseFrequency,
                    pulseMagnitude = windZone.windPulseMagnitude
                };
            }
        }