using System.Collections; using UnityEngine; using UnityEngine.Rendering; namespace UnityEngine.Rendering { [CurrentPipelineHelpURL("Volumes")] [ExecuteAlways] [AddComponentMenu("Miscellaneous/Volume Weight Animator")] public class VolumeWeightAnimator : MonoBehaviour { [SerializeField] private Volume m_Volume; [SerializeField] private float m_AnimationDuration = 5.0f; [SerializeField] private AnimationCurve m_WeightCurve = AnimationCurve.Linear(0, 0, 1, 1); [SerializeField] private float m_Speed = 1.0f; private bool wasEnabled = false; private void Start() { if (m_Volume != null) { m_Volume.weight = 0; wasEnabled = m_Volume.enabled; } else { Debug.LogWarning("Volume is not assigned."); } } private void Update() { if (m_Volume != null) { if (m_Volume.enabled && !wasEnabled) { // Volume został włączony, uruchamiamy animację StartCoroutine(AnimateWeight()); } wasEnabled = m_Volume.enabled; } } private IEnumerator AnimateWeight() { float elapsedTime = 0f; m_Volume.weight = 1; // Ustawienie wagi na 1 przy włączaniu Volume while (elapsedTime < m_AnimationDuration) { float t = elapsedTime / m_AnimationDuration; float curveValue = m_WeightCurve.Evaluate(t); m_Volume.weight = curveValue; // Używamy bezpośrednio wartości z krzywej elapsedTime += Time.deltaTime * m_Speed; yield return null; } // Po zakończeniu animacji wyłączamy Volume m_Volume.enabled = false; } } }