question

tmichael avatar image
tmichael asked

UniRx and PlayFab

So, I found out about PlayFab from the GDC talk (http://gdcvault.com/play/1023486/) and in the talk ya'll talked about using UniRx with PlayFab... but unfortunately, the code supplied was incomplete and I'm having a hard time making it work.

I've been programming for a long time, but I'm new to C# and Rx so there's a lot I'm trying to learn at once with this... so forgive me if the answer is obvious.

In the talk, there's this code:

		PlayFabClientAPI.LoginWithCustomID(
			request, 
			(e) => _EventStream(new LoginEvent(e)),
			(err) => _EventStream(new LoginEvent(err))
		);

But there's nothing about how to create the LoginEvent class... and I cannot figure out what the type of e and err is. Everything I've found seems to be implicitly typed and when I look at the source, the potential results appear to be a wide number of completely unique classes.

So... how in the world do I create a constructor for the LoginEvent class when I don't know what the type of the result is? Or what is it that I'm missing here?

Thanks!

,

At the PlayFab GDC talk(http://gdcvault.com/play/1023486/), ya'll discussed using UniRx with PlayFab. Unfortunately, the code displayed was incomplete as it didn't describe how to make the events.

I've been programming a long time, but there's a lot of new concepts being introduced to me with C# and UniRx, so forgive me if the answer is obvious.

I have a class that includes the code from the talk:

	private Action<IPlayFabEvent> _EventStream = delegate {};
	
	public IObservable<T> EventStream<T>() where T : IPlayFabEvent
	{
		return Observable.FromEvent<IPlayFabEvent>(
			h => _EventStream += h,
			h => _EventStream -= h
		).OfType<IPlayFabEvent,T>();
	}

and that compiles fine... but then when I get to the part that looks like this:

		PlayFabClientAPI.LoginWithCustomID(
			request, 
			(e) => _EventStream(new LoginEvent(e)),
			(err) => _EventStream(new LoginEvent(err))
		);

I cannot for the life of me figure out what type e and err are. It seems like all the examples are implicit and looking at the playfab API source, it seems like the result could be any number of totally unique classes.

I have no idea how to create a LoginEvent class with a constructor that will accept an implicit argument... if that's even what I need to be doing? Can anyone help me?

1 comment
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

tmichael avatar image tmichael commented ·

So, I submitted this question once... but I wasn't logged in so when I hit the button, it looked like the post was lost... so I rewrote it... and now it seems that when I submitted that post, it submitted both posts as if they were the same post and now I can't figure out how to edit a post.

0 Likes 0 ·
brendan avatar image
brendan answered

You should be able to edit it now. The issue is that all new users start with 0 reputation, so your questions go to a moderation queue, where you can't really change them. This is so that we don't get spammers attempting to use our forums for download links and the like (a common issue).

Specific to your question, e and err are the input variables to a lambda expression (the => operator in C# - not specific to UniRx). In this case, that's the way the success and failure return operations are being handled for the LoginWithCustomId call.

What I would recommend, since you're new to both, is starting with just straight C# first, using our samples (https://github.com/PlayFab/PlayFab-Samples). You can always add Reactive Extensions for Unity and lambda operators later on, once you've had a chance to play around with the language.

10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

tmichael avatar image
tmichael answered

Nevermind, I figured it out... "PlayFab.ClientModels.LoginResult"

10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

tmichael avatar image
tmichael answered

I think I just needed a break. I was able to figure it all out with:

		PlayFabClientAPI.LoginWithCustomID(
			request, 
			(e) => Debug.Log("SUCCESS = " + e.GetType()),
			(err) => Debug.Log("Error = " + err.GetType())
		);

and then create a constructor for each possible result

10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Write an Answer

Hint: Notify or tag a user in this post by typing @username.

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.