using System; namespace UniRx.Diagnostics { public static class ObservableDebugExtensions { /// /// Debug helper of observbale stream. Works for only DEBUG symbol. /// public static IObservable Debug(this IObservable source, string label = null) { #if DEBUG var l = (label == null) ? "" : "[" + label + "]"; return source.Materialize() .Do(x => UnityEngine.Debug.Log(l + x.ToString())) .Dematerialize() .DoOnCancel(() => UnityEngine.Debug.Log(l + "OnCancel")) .DoOnSubscribe(() => UnityEngine.Debug.Log(l + "OnSubscribe")); #else return source; #endif } /// /// Debug helper of observbale stream. Works for only DEBUG symbol. /// public static IObservable Debug(this IObservable source, UniRx.Diagnostics.Logger logger) { #if DEBUG return source.Materialize() .Do(x => logger.Debug(x.ToString())) .Dematerialize() .DoOnCancel(() => logger.Debug("OnCancel")) .DoOnSubscribe(() => logger.Debug("OnSubscribe")); #else return source; #endif } } }