Açıklama Yok
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

Observable.cs 1.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. using System;
  2. using System.Collections.Generic;
  3. namespace UnityEngine.Rendering
  4. {
  5. /// <summary>
  6. /// Represents an observable value of type T. Subscribers can be notified when the value changes.
  7. /// </summary>
  8. /// <typeparam name="T">The type of the value.</typeparam>
  9. public struct Observable<T>
  10. {
  11. /// <summary>
  12. /// Event that is triggered when the value changes.
  13. /// </summary>
  14. public event Action<T> onValueChanged;
  15. private T m_Value;
  16. /// <summary>
  17. /// The current value.
  18. /// </summary>
  19. public T value
  20. {
  21. get => m_Value;
  22. set
  23. {
  24. // Only invoke the event if the new value is different from the current value
  25. if (!EqualityComparer<T>.Default.Equals(value, m_Value))
  26. {
  27. m_Value = value;
  28. // Notify subscribers when the value changes
  29. onValueChanged?.Invoke(value);
  30. }
  31. }
  32. }
  33. /// <summary>
  34. /// Constructor with value
  35. /// </summary>
  36. /// <param name="newValue">The new value to be assigned.</param>
  37. public Observable(T newValue)
  38. {
  39. m_Value = newValue;
  40. onValueChanged = null;
  41. }
  42. }
  43. }