using UnityEngine; using System.Collections; using UnityEngine.Rendering; public class PostProcessController : MonoBehaviour { public Volume volume; // Publiczna referencja do komponentu Volume public float duration = 1f; // Publiczna warto�� okre�laj�ca czas p�ynnej zmiany wagi private Coroutine currentCoroutine; // Referencja do aktualnie dzia�aj�cej coroutiny private void Awake() { // Je�li Volume nie zosta� przypisany w inspektorze, pr�bujemy go znale�� na tym samym obiekcie if (volume == null) { volume = GetComponent(); if (volume == null) { Debug.LogError("Brak komponentu Volume na obiekcie!"); } } } // Funkcja p�ynnie w��cza efekt post-processingu (od 0 do 1) w czasie ustawionym w duration public void EnablePostProcessing() { if (volume != null) { // Je�li ju� jest jaka� coroutina w trakcie, zatrzymujemy j� if (currentCoroutine != null) { StopCoroutine(currentCoroutine); } currentCoroutine = StartCoroutine(ChangeWeightOverTime(0f, 1f, duration)); } } // Funkcja p�ynnie wy��cza efekt post-processingu (od 1 do 0) w czasie ustawionym w duration public void DisablePostProcessing() { if (volume != null) { // Je�li ju� jest jaka� coroutina w trakcie, zatrzymujemy j� if (currentCoroutine != null) { StopCoroutine(currentCoroutine); } if (!gameObject.activeSelf) gameObject.SetActive(true); currentCoroutine = StartCoroutine(ChangeWeightOverTime(1f, 0f, duration)); } } // Coroutine do p�ynnej zmiany wagi Volume private IEnumerator ChangeWeightOverTime(float startWeight, float endWeight, float duration) { float elapsed = 0f; while (elapsed < duration) { // Interpolacja mi�dzy startWeight a endWeight volume.weight = Mathf.Lerp(startWeight, endWeight, elapsed / duration); elapsed += Time.deltaTime; yield return null; // Czekamy do nast�pnej klatki } // Upewniamy si�, �e waga jest ustawiona na ko�cow� warto�� po zako�czeniu interpolacji volume.weight = endWeight; currentCoroutine = null; } // Funkcja ustawia okre�lon� wag� efektu post-processingu natychmiast (od 0.0 do 1.0) public void SetPostProcessingWeight(float newWeight) { if (volume != null) { volume.weight = Mathf.Clamp01(newWeight); } } }