Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save TakaakiIchijo/0c55f518efc87c44a18f6ceb36d9d7cf to your computer and use it in GitHub Desktop.
Save TakaakiIchijo/0c55f518efc87c44a18f6ceb36d9d7cf to your computer and use it in GitHub Desktop.
A piece of R3 extensions for Netcode for GameObjects
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