Last active
February 14, 2024 05:38
-
-
Save TakaakiIchijo/0c55f518efc87c44a18f6ceb36d9d7cf to your computer and use it in GitHub Desktop.
A piece of R3 extensions for Netcode for GameObjects
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 Unity.Netcode; | |
namespace R3.Trigger | |
{ | |
public static class UnityNetcodeR3Extensions | |
{ | |
public static Observable<(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