### Getting a Registered Plugin Source: https://github.com/playfab/csharpsdk/blob/master/PluginManager.md Example of how to retrieve a currently set plugin for a specific contract from the PluginManager. ```csharp var currentTransportClient = PluginManager.GetPlugin(PluginContract.PlayFab_Transport); ``` -------------------------------- ### Xamarin App.cs - Initial Setup and PlayFab Login Source: https://github.com/playfab/csharpsdk/blob/master/XamarinGettingStarted.md This code snippet replaces the default App.cs content in a Xamarin project to initialize the UI, set up PlayFab settings, and initiate a login process. It uses a timer for thread-safe UI updates. ```C# using System; using System.Threading.Tasks; using PlayFab; using PlayFab.ClientModels; using Xamarin.Forms; namespace GettingStartedXamarin { public class App : Application { private readonly Label _myLabel; private string _myLabelText = "Logging into PlayFab..."; public App() { _myLabel = new Label { HorizontalTextAlignment = TextAlignment.Center, Text = _myLabelText }; // The root page of your application MainPage = new ContentPage { Content = new StackLayout { VerticalOptions = LayoutOptions.Center, Children = { _myLabel } } }; LogIntoPlayFab(); Device.StartTimer(TimeSpan.FromMilliseconds(16), Tick); } private bool Tick() { lock (_myLabelText) { _myLabel.Text = _myLabelText; } return true; } private void LogIntoPlayFab() { PlayFabSettings.TitleId = "144"; var request = new LoginWithCustomIDRequest { CustomId = "GettingStartedGuide", CreateAccount = true }; var loginTask = PlayFabClientAPI.LoginWithCustomIDAsync(request); loginTask.ContinueWith(OnLoginComplete); } private void OnLoginComplete(Task> task) { var newLabel = "Unknown failure"; if (task.Result.Result != null) { newLabel = "Congratulations, you made your first successful API call!"; } if (task.Result.Error != null) { newLabel = "Something went wrong with your first API call.\n" + "Here's some debug information:\n" + task.Result.Error.GenerateErrorReport(); } lock (_myLabelText) { _myLabelText = newLabel; } } } } ``` -------------------------------- ### Custom JSON Serializer Implementation Source: https://github.com/playfab/csharpsdk/blob/master/PluginManager.md Example implementation of a custom JSON serializer plugin. This class must implement the ISerializerPlugin interface. ```csharp public class MyJsonSerializer : ISerializerPlugin { public T DeserializeObject(string serialized) { // custom implementation throw new NotImplementedException(); } public T DeserializeObject(string serialized, object serializerStrategy) { // custom implementation throw new NotImplementedException(); } public object DeserializeObject(string serialized) { // custom implementation throw new NotImplementedException(); } public string SerializeObject(object obj) { // custom implementation throw new NotImplementedException(); } public string SerializeObject(object obj, object serializerStrategy) { // custom implementation throw new NotImplementedException(); } } ``` -------------------------------- ### Custom Network Transport Client Implementation Source: https://github.com/playfab/csharpsdk/blob/master/PluginManager.md Example implementation of a custom network transport client plugin. This class must implement the ITransportPlugin interface. ```csharp public class MyNetworkTransportClient : ITransportPlugin { public Task DoPost(string urlPath, object request, Dictionary headers) { // custom implementation throw new NotImplementedException(); } } ``` -------------------------------- ### Basic Login with Custom ID Source: https://github.com/playfab/csharpsdk/blob/master/CSharpGettingStarted.md This snippet demonstrates how to initialize PlayFab settings, create a login request with a custom ID, and initiate the asynchronous login call. It's a foundational step for most PlayFab integrations. ```csharp PlayFabSettings.TitleId = "xxxx"; var request = new LoginWithCustomIDRequest { CustomId = "GettingStartedGuide", CreateAccount = true }; var loginTask = PlayFabClientAPI.LoginWithCustomIDAsync(request); ``` -------------------------------- ### Setting Custom Plugins with PluginManager Source: https://github.com/playfab/csharpsdk/blob/master/PluginManager.md Demonstrates how to set custom serializer and transport plugins using the PluginManager before initializing PlayFab services. ```csharp static void Main(string[] args) { PlayFabSettings.TitleId = "144"; // Please change this value to your own titleId from PlayFab Game Manager // We recommend using the Polly wrapped transport client as this // will help your services follow better fault tolerance practices // and proper retrying logic against the PlayFab services. For more // information, see the PlayFabPollyHttp class summary. PluginManager.SetPlugin(new PlayFabPollyHttp(), PluginContract.PlayFab_Transport); // Optionally set your own custom JSON serializer PluginManager.SetPlugin(new MyJsonSerializer(), PluginContract.PlayFab_Serializer); // Optionally set your own custom HTTP network client PluginManager.SetPlugin(new MyNetworkTransportClient(), PluginContract.PlayFab_Transport); // ... } ``` -------------------------------- ### Basic C# PlayFab Login API Call Source: https://github.com/playfab/csharpsdk/blob/master/CSharpGettingStarted.md This snippet demonstrates how to set up your PlayFab title ID, make an asynchronous login call using a custom ID, and handle the result. It's suitable for admin tools where synchronous calls are acceptable, but highlights the async nature for game development. ```C# using System; using System.Threading; using System.Threading.Tasks; using PlayFab; using PlayFab.ClientModels; public static class Program { private static bool _running = true; static void Main(string[] args) { PlayFabSettings.staticSettings.TitleId = "144"; // Please change this value to your own titleId from PlayFab Game Manager var request = new LoginWithCustomIDRequest { CustomId = "GettingStartedGuide", CreateAccount = true }; var loginTask = PlayFabClientAPI.LoginWithCustomIDAsync(request); // If you want a synchronous ressult, you can call loginTask.Wait() - Note, this will halt the program until the function returns while (_running) { if (loginTask.IsCompleted) // You would probably want a more sophisticated way of tracking pending async API calls in a real game { OnLoginComplete(loginTask); } // Presumably this would be your main game loop, doing other things Thread.Sleep(1); } Console.WriteLine("Done! Press any key to close"); Console.ReadKey(); // This halts the program and waits for the user } private static void OnLoginComplete(Task> taskResult) { var apiError = taskResult.Result.Error; var apiResult = taskResult.Result.Result; if (apiError != null) { Console.ForegroundColor = ConsoleColor.Red; // Make the error more visible Console.WriteLine("Something went wrong with your first API call. :("); Console.WriteLine("Here's some debug information:"); Console.WriteLine(PlayFabUtil.GenerateErrorReport(apiError)); Console.ForegroundColor = ConsoleColor.Gray; // Reset to normal } else if (apiResult != null) { Console.WriteLine("Congratulations, you made your first successful API call!"); } _running = false; // Because this is just an example, successful login triggers the end of the program } } ``` -------------------------------- ### Handling Login Response Source: https://github.com/playfab/csharpsdk/blob/master/CSharpGettingStarted.md This code shows how to process the result of an asynchronous login operation. It checks for API errors and extracts the result if the call was successful. Always handle potential errors. ```csharp var apiResult = taskResult.Result.Result; var apiError = taskResult.Result.Error; ``` -------------------------------- ### Custom Serializer and Transport Plugin Interfaces Source: https://github.com/playfab/csharpsdk/blob/master/PluginManager.md Defines the interfaces for custom JSON serializer and network transport plugins supported by the PlayFab SDK. ```csharp PlayFab.ISerializerPlugin // - allows to provide a custom JSON serializer PlayFab.ITransportPlugin // - allows to provide a custom network HTTP client ``` -------------------------------- ### Generated Resource Class Structure Source: https://github.com/playfab/csharpsdk/blob/master/XamarinTestRunner/XamarinTestRunner/XamarinTestRunner.Android/Resources/AboutResources.txt This C# class is automatically generated by the Xamarin build system. It provides static tokens to reference Android resources like drawables, layouts, and strings. ```csharp public class Resource { public class drawable { public const int icon = 0x123; } public class layout { public const int main = 0x456; } public class strings { public const int first_string = 0xabc; public const int second_string = 0xbcd; } } ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.