Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- using UnityEngine.PostProcessing;
- public class BloomTrigger : MonoBehaviour
- {
- public float Duration;
- public Vector2 IntensityRamp;
- public Vector2 ThresholdRamp;
- public Vector2 RadiusRamp;
- private bool _enabled;
- private float _intensity, _threshold, _radius;
- private bool _isRunning = false;
- public void Activate()
- {
- StartCoroutine(Activate_Async());
- }
- private IEnumerator Activate_Async()
- {
- _isRunning = true;
- BloomModel bloom = GameState.Player.PostProcessing.bloom;
- BloomModel.Settings settings = bloom.settings;
- // Save these values before modifying them, so we can revert them when we are done.
- _intensity = settings.bloom.intensity;
- _threshold = settings.bloom.threshold;
- _radius = settings.bloom.radius;
- _enabled = bloom.enabled;
- bloom.enabled = true;
- float timer = 0;
- while(timer < Duration)
- {
- timer += Time.deltaTime;
- settings.bloom.intensity = Mathf.Lerp(IntensityRamp.x, IntensityRamp.y, timer / Duration);
- settings.bloom.threshold = Mathf.Lerp(ThresholdRamp.x, ThresholdRamp.y, timer / Duration);
- settings.bloom.radius = Mathf.Lerp(RadiusRamp.x, RadiusRamp.y, timer / Duration);
- bloom.settings = settings;
- yield return null;
- }
- ResetValues();
- _isRunning = false;
- }
- private void OnDestroy()
- {
- if (_isRunning)
- {
- ResetValues();
- }
- }
- private void ResetValues()
- {
- BloomModel bloom = GameState.Player.PostProcessing.bloom;
- BloomModel.Settings settings = bloom.settings;
- bloom.enabled = _enabled;
- settings.bloom.intensity = _intensity;
- settings.bloom.threshold = _threshold;
- settings.bloom.radius = _radius;
- bloom.settings = settings;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement