Exemple #1
0
        /// <summary>
        /// Constantly shakes the camera until it's explicitly told to stop
        /// </summary>
        /// <param name="preset">The preset that contains all the constant shake parameters</param>
        public void ConstantShake(ConstantShakePreset preset)
        {
            if (CurrentConstantShakePreset != null)
            {
                StopConstantShaking(0);
            }

            CurrentConstantShakePreset = preset;

            _isConstantShaking = true;

            _constantShakePositions = new Vector3[preset.Layers.Count];

            for (int i = 0; i < preset.Layers.Count; i++)
            {
                StartCoroutine(CalculateConstantShakePosition(
                                   i,
                                   preset.Layers[i].Frequency.x,
                                   preset.Layers[i].Frequency.y,
                                   preset.Layers[i].AmplitudeHorizontal,
                                   preset.Layers[i].AmplitudeVertical,
                                   preset.Layers[i].AmplitudeDepth));
            }

            StartCoroutine(ConstantShakeRoutine(preset.Intensity));
        }
        /// <summary>
        /// Stops constant shakes
        /// </summary>
        /// <param name="duration">How long it takes to stop the constant shake</param>
        public void StopConstantShaking(float duration = .3f)
        {
            CurrentConstantShakePreset = null;

            _isConstantShaking = false;

            if (duration > 0f)
            {
                StartCoroutine(StopConstantShakeRoutine(duration));
            }
            else
            {
                StopAllCoroutines();
                _constantShakePosition = Vector3.zero;
                _influences.Clear();
                _influences.Add(_constantShakePosition);
            }
        }
 void OnEnable()
 {
     _preset = (ConstantShakePreset)target;
 }