Skip to content

Instantly share code, notes, and snippets.

@GCodergr
Last active November 27, 2022 16:54
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save GCodergr/b7cd99444ed3d2f37d28788c39ef2067 to your computer and use it in GitHub Desktop.
Save GCodergr/b7cd99444ed3d2f37d28788c39ef2067 to your computer and use it in GitHub Desktop.
UniRx SubscribeToText support for TextMeshPro
using System;
using TMPro;
namespace UniRx.Extensions
{
public static class UnityUIExtensions
{
public static IDisposable SubscribeToText(this IObservable<string> source, TextMeshProUGUI text)
{
return source.SubscribeWithState(text, (x, t) => t.text = x);
}
public static IDisposable SubscribeToText<T>(this IObservable<T> source, TextMeshProUGUI text)
{
return source.SubscribeWithState(text, (x, t) => t.text = x.ToString());
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment