Created
October 5, 2023 08:16
-
-
Save aleverdes/adfdb2fbd3b8c6db63a849a8b5cf92d2 to your computer and use it in GitHub Desktop.
ReactiveProperty<T> for Unity
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using UnityEngine; | |
namespace SunnyverseGames | |
{ | |
[Serializable] | |
public sealed class ReactiveProperty<T> | |
{ | |
[SerializeField] private T _value; | |
public T Value | |
{ | |
get => _value; | |
set | |
{ | |
if (Equals(value, _value)) | |
{ | |
return; | |
} | |
_value = value; | |
ValueChanged?.Invoke(value); | |
} | |
} | |
public event Action<T> ValueChanged; | |
public void SetWithoutNotify(T value) | |
{ | |
_value = value; | |
} | |
public static implicit operator T(ReactiveProperty<T> reactiveProperty) => reactiveProperty.Value; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment