- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- using UnityEngine.Rendering.PostProcessing;
- public class PostProcessingController : MonoBehaviour
- {
- PostProcessVolume ppv;
- Bloom bloom;
- Grain grain;
- ColorGrading colorGrading;
- LensDistortion lensDistortion;
- Vignette vignette;
- DepthOfField depthOfField;
- PlayerController playerController;
- [SerializeField] private float maxDistance;
- private List<float> originalValues;
- void Start()
- {
- ppv = GetComponent<PostProcessVolume>();
- ppv.profile.TryGetSettings(out bloom);
- ppv.profile.TryGetSettings(out grain);
- ppv.profile.TryGetSettings(out colorGrading);
- ppv.profile.TryGetSettings(out vignette);
- ppv.profile.TryGetSettings(out depthOfField);
- ppv.profile.TryGetSettings(out lensDistortion);
- playerController = GameObject.FindGameObjectWithTag("Player").GetComponent<PlayerController>();
- }
- void Update()
- {
- UpdatePostProcessing(Vector3.Distance(playerController.transpassedCoordinate, playerController.transform.position));
- }
- public void UpdatePostProcessing(float distance)
- {
- if (playerController.transpassedCoordinate != Vector3.zero)
- {
- if (distance < maxDistance)
- {
- bloom.dirtIntensity.value = 30 * distance / maxDistance;
- grain.intensity.value = 1 * distance / maxDistance;
- lensDistortion.intensity.value = 40 * distance / maxDistance;
- vignette.intensity.value = 0.7f * distance / maxDistance;
- if (depthOfField.focusDistance.value <= 10 && distance != 0)
- depthOfField.focusDistance.value = maxDistance / distance;
- else depthOfField.focusDistance.value = 10;
- }
- }
- }
- }