Last active
January 5, 2024 03:27
-
-
Save TakaakiIchijo/da9dbf704b7398828887139c7513f948 to your computer and use it in GitHub Desktop.
A piece of UniRx extensions for Netcode for GameObjects
This file contains hidden or 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 Unity.Netcode; | |
namespace UniRx | |
{ | |
public static class UnityNetcodeUniRxExtensions | |
{ | |
public static IObservable<(T previousValue, T newValue)> AsObservable<T>(this NetworkVariable<T> networkVariable) | |
{ | |
return Observable.FromEvent<NetworkVariable<T>.OnValueChangedDelegate, (T, T)>( | |
h => (previousValue, newValue) => h((previousValue, newValue)), | |
h => networkVariable.OnValueChanged += h, | |
h => networkVariable.OnValueChanged -= h); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment