using System;
using System.Collections.Generic;
namespace UnityEngine.Rendering
{
///
/// Represents an observable value of type T. Subscribers can be notified when the value changes.
///
/// The type of the value.
public struct Observable
{
///
/// Event that is triggered when the value changes.
///
public event Action onValueChanged;
private T m_Value;
///
/// The current value.
///
public T value
{
get => m_Value;
set
{
// Only invoke the event if the new value is different from the current value
if (!EqualityComparer.Default.Equals(value, m_Value))
{
m_Value = value;
// Notify subscribers when the value changes
onValueChanged?.Invoke(value);
}
}
}
///
/// Constructor with value
///
/// The new value to be assigned.
public Observable(T newValue)
{
m_Value = newValue;
onValueChanged = null;
}
}
}