{"__v":1,"_id":"57f4cd661592cb0e00761e68","category":{"__v":1,"_id":"56a0bd9f3697d80d002ac5e8","pages":["56a0bda03697d80d002ac5f4","56a0bda03697d80d002ac5f5","56a0bda03697d80d002ac5f6","56a0bda03697d80d002ac5f7","56a0bda03697d80d002ac5f8","56a0bda03697d80d002ac5f9","56a0bda03697d80d002ac5fa","56a0bda03697d80d002ac5fb","56a0bda03697d80d002ac5fc","56a0bda03697d80d002ac5fd","56a0bda03697d80d002ac5fe"],"project":"54774d9af3736008009e9e0e","version":"56a0bd9e3697d80d002ac5e7","sync":{"url":"","isSync":false},"reference":false,"createdAt":"2014-11-27T16:46:04.014Z","from_sync":false,"order":8,"slug":"libraries-quick-starts","title":"Libraries Quick Starts"},"parentDoc":null,"project":"54774d9af3736008009e9e0e","user":"548193732dca603300bf6ea1","version":{"__v":20,"_id":"56a0bd9e3697d80d002ac5e7","project":"54774d9af3736008009e9e0e","createdAt":"2016-01-21T11:14:38.131Z","releaseDate":"2016-01-21T11:14:38.131Z","categories":["56a0bd9f3697d80d002ac5e8","56a0bd9f3697d80d002ac5e9","56a0bd9f3697d80d002ac5ea","56a0bd9f3697d80d002ac5eb","56b098a43a5b810d00745e3f","56b098da8f7a4f0d0029dd10","56d5a8ecf612b80b00fb69cd","570989853ab43c0e0072b2d6","571006aa10300c0e007f6133","5735a52431a73b1700887ca0","5744b0529e045c0e00b7a7a2","5744b1d0b56d431700d8a4fb","5744b1fb55d65a0e00b436e1","5744b218f9c7411700ce560e","5744b220f9c7411700ce560f","5744b2259e045c0e00b7a7a7","5744b22cf8b79f0e00de6a2d","5744b23155d65a0e00b436e4","5744b242c758290e00fbc235","5744b2569e045c0e00b7a7a8","5756a3f2bb92962900dafe3d","57ee23e81e42900e0014a42f","581c822c98676e0f00d240ef"],"is_deprecated":false,"is_hidden":false,"is_beta":false,"is_stable":true,"codename":"Sockets","version_clean":"1.1.0","version":"1.1"},"updates":[],"next":{"pages":[],"description":""},"createdAt":"2016-10-05T09:52:38.450Z","link_external":false,"link_url":"","githubsync":"","sync_unique":"","hidden":false,"api":{"results":{"codes":[]},"settings":"","auth":"required","params":[],"url":""},"isReference":false,"order":6,"body":"## Chapter Contents:\n1. [Overview](#overview)\n2. [Installing the Syncano Unity Library](#installing-the-syncano-android-library)\n3. [Using the Syncano Library](#using-the-syncano-library)\n4. [Support](#section-support)\n5. [License](#section-license)\n[block:api-header]\n{\n  \"type\": \"basic\",\n  \"title\": \"Overview\"\n}\n[/block]\nThis guide will walk you through the installation steps of the Syncano Library for Unity, as well as give you a couple of usage examples.\n\nIf you don't have a Syncano account yet, you can read about how to create one [here](doc:getting-started-with-syncano). \n[block:api-header]\n{\n  \"type\": \"basic\",\n  \"title\": \"Installing the Syncano Unity Library\"\n}\n[/block]\n1. [Source](#section-source)\n2. [Unity3D Engine](#section-unity3d)\n3. [Create a New Unity Project](#section-create-a-new-unity-project)\n4. [Adding the Syncano Library to a Project](#section-adding-the-syncano-library-to-a-project)\n\nSource\n======\n\nSyncano Unity Library is available from our [GitHub](https://github.com/Syncano/syncano-unity/releases). Full source code can be downloaded from [Github](https://github.com/Syncano/syncano-unity/) \n\nUnity3D\n===========\n\nIf you don’t have Unity3D already, you can find the newest version [here](https://unity3d.com/get-unity/download).\n\nCreate a New Unity Project\n=====================\n\n1. Open Unity3D\n2. Choose **Projects -> New**\n3. Type in the project name and press **Create Project**. We’ll use **SyncanoProject** as an app name\n4. In **File -> Build Settings** you can choose proper platform for your project - we’ll just stick with default one\n\nAdding the Syncano Library to a Project\n===========================\n\n#### Downloading Unity Package\nThe Unity package can be downloaded from [our Github repo here](https://github.com/Syncano/syncano-unity/releases). All you need to do is to download it and open it in the Unity3D engine. The package can be imported by choosing **Assets -> Import Package -> Custom Package**.\n\n#### Using DLL\nThe compiled library can be downloaded from [releases page](https://github.com/Syncano/syncano-unity/releases). You also need to download Newtonsoft.Net dll from [here](https://github.com/SaladLab/Json.Net.Unity3D/releases). Place both dll files in one folder under the Assets directory.\n[block:api-header]\n{\n  \"type\": \"basic\",\n  \"title\": \"Using the Unity3D Library\"\n}\n[/block]\n1. [Importing the Syncano Library](#section-importing-the-syncano-library)\n2. [Synchronous and Asynchronous requests](#section-synchronous-and-asynchronous-requests)\n3. [Connecting to Syncano](#section-connecting-to-syncano)\n4. [Adding your Data Class](#section-adding-your-class)\n5. [Download the most recent Objects](#section-download-the-most-recent-objects)\n   a. [Synchronous](#section-synchronous)\n   b. [Asynchronous](#section-asynchronous)\n6. [Get a single Data Object](#section-get-a-single-data-object)\n7. [Creating a new Data Object](#section-creating-a-new-data-object)\n8. [Modify an Object](#section-modify-an-object)\n9. [Delete a Data Object](#section-delete-a-data-object)\n10. [Data Endpoints](#section-data-endpoints)\n11. [Script endpoints](#section-script-endpoints)\n12. [Synchronization and Real-Time Channels](#section-synchronization-and-real-time-channels)\n13. [Handling users](#section-handling-users)\n14. [Response codes and error messages](#section-response-codes-and-error-messages)\n\n\nImporting the Syncano Library\n====================\n\nWhen writing code that uses Syncano objects, the IDE will suggest proper modules to be imported in your file. In general, everything is placed under the **Syncano**.* namespace, but you should rely on the IDE suggestions to provide proper imports.\n\nSynchronous and Asynchronous requests\n================================\n\nGenerally, all requests are asynchronous. If you want to make a `synchronous` call you have to run it in an IEnumerator and wait until it has finished. For simplicity, further examples will show the asynchronous implementation.\n\nConnecting to Syncano\n=================\n\nCreate a `SyncanoClient` object and initialize it as follows, otherwise you will not be able to make any calls to the backend.\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"SyncanoClient syncano = SyncanoClient.Instance.Init(\\\"YOUR_API_KEY\\\", \\\"YOUR_INSTANCE_NAME\\\");\",\n      \"language\": \"csharp\"\n    }\n  ]\n}\n[/block]\n`SyncanoClient` is a Singleton that will be available everywhere once it has been initialized. It can be accessed through `SyncanoClient.Instance`.\n\nAdding your class\n=============\n[block:callout]\n{\n  \"type\": \"info\",\n  \"body\": \"Before you will use the Data Class in your app, remember that the Data Class should already exist in Syncano. You can add your Data Classes quickly by using our [Dashboard](https://dashboard.syncano.io/)!\\n\\nYou can read more about Data Classes [here](doc:classes-overview).\",\n  \"title\": \"Using Data Classes in Syncano\"\n}\n[/block]\nNow we will add the C# class you had implemented on Syncano. We will be using a simple Book Data Class which only has two attributes: \"title\" and \"subtitle\", both being of type \"string\".\n\nThe Schema for this class would look like this:\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"[\\n  {\\\"type\\\": \\\"string\\\",\\\"name\\\": \\\"title\\\"},\\n  {\\\"type\\\": \\\"string\\\",\\\"name\\\": \\\"subtitle\\\"}\\n]\",\n      \"language\": \"json\"\n    }\n  ]\n}\n[/block]\nOur C# class would look like:\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"using Newtonsoft.Json;\\nusing Syncano;\\n\\npublic class Book : SyncanoObject {\\n\\n\\tpublic const string FIELD_TITLE = \\\"title\\\";\\n\\tpublic const string FIELD_SUBTITLE = \\\"subtitle\\\";\\n\\n\\t[JsonProperty(FIELD_TITLE)]\\n\\tpublic string Title { get; set; }\\n\\n\\t[JsonProperty(FIELD_SUBTITLE)]\\n\\tpublic string Subtitle { get; set; }\\n}\",\n      \"language\": \"csharp\"\n    }\n  ]\n}\n[/block]\nAs you can see we are using Newtonsoft.Net Attributes to describe class properties. Attribute's overloaded constructor takes a string parameter to map property with class schema in Syncano. It means that you can name any attribute however you want and them map it through JsonProperty Attribute.\n\nField types and names should match those from the **schema**.\n\nOur class needs to inherit the `SyncanoObject` class. It will deliver standard fields such as:\n- id\n- created_at\n- updated_at\n- revision\n\nDownload the most recent Objects\n============================\n\n### Synchronous\n\nIf you need to wait for a result, you have to run your code in an IEnumerator and wait for a Coroutine to finish.\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"using UnityEngine;\\nusing System.Collections;\\nusing Syncano;\\n\\npublic class Main : MonoBehaviour {\\n\\t\\n\\tprivate SyncanoClient syncano;\\n\\n\\tIEnumerator Start () {\\n\\t\\tsyncano = SyncanoClient.Instance.Init(\\\"YOUR_API_KEY\\\", \\\"YOUR_INSTANCE_NAME\\\");\\n\\t\\tyield return StartCoroutine(GetListOfBooks());\\n\\t}\\n\\n\\tprivate IEnumerator GetListOfBooks() {\\n\\t\\tyield return syncano.Please().Get<Book>(OnGetBookSuccess, OnGetBookFailure);\\n\\t}\\n\\n\\tprivate void OnGetBookSuccess(ResponseGetList<Book> response) {\\n\\t\\tDebug.Log(\\\"success \\\" + response.Objects.Count);\\n\\t}\\n\\n\\tprivate void OnGetBookFailure(ResponseGetList<Book> response) {\\n\\t\\tDebug.Log(\\\"failure\\\");\\n\\t}\\n}\",\n      \"language\": \"csharp\"\n    }\n  ]\n}\n[/block]\n### Asynchronous\n\nWith the async request, you will get a page of most recent data objects in the background. Then, you will handle the UI update in a callback. The difference is that you don't need to wait until Coroutine ends.\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"using UnityEngine;\\nusing System.Collections;\\nusing Syncano;\\n\\npublic class Main : MonoBehaviour {\\n\\t\\n\\tprivate SyncanoClient syncano;\\n\\n\\tvoid Start () {\\n\\t\\tsyncano = SyncanoClient.Instance.Init(\\\"YOUR_API_KEY\\\", \\\"YOUR_INSTANCE_NAME\\\");\\n\\t\\tsyncano.Please().Get<Book>(OnGetBookSuccess, OnGetBookFailure);\\n\\t}\\n\\n\\tprivate void OnGetBookSuccess(ResponseGetList<Book> response)\\n\\t{\\n\\t\\tDebug.Log(\\\"success \\\" + response.Objects.Count);\\n\\t}\\n\\n\\tprivate void OnGetBookFailure(ResponseGetList<Book> response)\\n\\t{\\n\\t\\tDebug.Log(\\\"failure\\\");\\n\\t}\\n}\",\n      \"language\": \"csharp\"\n    }\n  ]\n}\n[/block]\nBoth cases require to provide callbacks for a successful call and failed one. You can also pass one generic callback to handle both cases.\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"using UnityEngine;\\nusing System.Collections;\\nusing Syncano;\\nusing Syncano.Data;\\n\\npublic class Main : MonoBehaviour {\\n\\t\\n\\tprivate SyncanoClient syncano;\\n\\n\\tvoid Start () {\\n\\t\\tsyncano = SyncanoClient.Instance.Init(\\\"YOUR_API_KEY\\\", \\\"YOUR_INSTANCE_NAME\\\");\\n\\t\\tsyncano.Please().Get<Book>(OnGetBookCallback);\\n\\t}\\n\\n\\tprivate void OnGetBookCallback(ResponseGetList<Book> response)\\n\\t{\\n\\t\\tif(response.IsSuccess)\\n\\t\\t{\\n\\t\\t\\tDebug.Log(\\\"success \\\" + response.Objects.Count);\\n\\t\\t}\\n\\n\\t\\telse\\n\\t\\t{\\n\\t\\t\\tif(response.IsSyncanoError)\\n\\t\\t\\t{\\n\\t\\t\\t\\tDebug.Log(response.syncanoError);\\n\\t\\t\\t}\\n\\n\\t\\t\\telse\\n\\t\\t\\t{\\n\\t\\t\\t\\tDebug.Log(response.webError);\\n\\t\\t\\t}\\n\\t\\t}\\n\\t}\\n}\",\n      \"language\": \"csharp\"\n    }\n  ]\n}\n[/block]\nGet a single Data Object\n===================\n\nNow, if you'd only like to get a single Data Object, you can get it by its `id`.\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"using UnityEngine;\\nusing System.Collections;\\nusing Syncano;\\nusing Syncano.Data;\\n\\npublic class Main : MonoBehaviour {\\n\\t\\n\\tprivate SyncanoClient syncano;\\n\\tprivate Book book;\\n\\n\\tvoid Start () {\\n    int id = 1;\\n\\t\\tsyncano = SyncanoClient.Instance.Init(\\\"YOUR_API_KEY\\\", \\\"YOUR_INSTANCE_NAME\\\");\\n\\t\\tsyncano.Please().Get<Book>(id, OnGetBookSuccess, OnGetBookFailure);\\n\\t}\\n\\n\\tprivate void OnGetBookSuccess(Response<Book> response)\\n\\t{\\n\\t\\tbook = response.Data;\\n\\t\\tDebug.Log(\\\"success \\\" + book.Title);\\n\\t}\\n\\n\\tprivate void OnGetBookFailure(Response<Book> response)\\n\\t{\\n\\t\\tDebug.Log(\\\"failure\\\");\\n\\t}\\n}\",\n      \"language\": \"csharp\"\n    }\n  ]\n}\n[/block]\nCreating a new Data Object\n=====================\n\nBelow, we create a Data Object and fill it with data. Then we save the object on Syncano. In the response, you will get a Data Object with fields `id`, `createdAt`, `updatedAt` and `revision`.\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"using UnityEngine;\\nusing System.Collections;\\nusing Syncano;\\nusing Syncano.Data;\\n\\npublic class Main : MonoBehaviour {\\n\\t\\n\\tprivate SyncanoClient syncano;\\n\\tBook book;\\n\\n\\tvoid Start () {\\n\\t\\tsyncano = SyncanoClient.Instance.Init(\\\"YOUR_API_KEY\\\", \\\"YOUR_INSTANCE_NAME\\\");\\n\\t\\tbook = new Book();\\n\\t\\tbook.Title = \\\"Title\\\";\\n\\t\\tbook.Subtitle = \\\"Subtitle\\\";\\n\\n\\t\\tsyncano.Please().Save<Book>(book, OnGetBookSuccess, OnGetBookFailure);\\n\\t}\\n\\n\\tprivate void OnGetBookSuccess(Response<Book> response)\\n\\t{\\n\\t\\tbook = response.Data;\\n\\t\\tDebug.Log(\\\"success \\\" + book.Title);\\n\\t}\\n\\n\\tprivate void OnGetBookFailure(Response<Book> response)\\n\\t{\\n\\t\\tDebug.Log(\\\"failure\\\");\\n\\t}\\n}\",\n      \"language\": \"csharp\"\n    }\n  ]\n}\n[/block]\nModify an Object\n==================\n\nDo it the same way as when creating an object. When an object's `id` is set, then library tries to update it. But when the `id` is `null`, it tries to create it.\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"using UnityEngine;\\nusing System.Collections;\\nusing Syncano;\\nusing Syncano.Data;\\n\\npublic class Main : MonoBehaviour {\\n\\t\\n\\tprivate SyncanoClient syncano;\\n\\tprivate Book book;\\n\\n\\tvoid Start () {\\n\\t\\tsyncano = SyncanoClient.Instance.Init(\\\"YOUR_API_KEY\\\", \\\"YOUR_INSTANCE_NAME\\\");\\n\\t\\tbook = new Book();\\n\\t\\tbook.Id = 170; //SOME EXISTING ID\\n\\t\\tbook.Subtitle = \\\"New Subtitle\\\";\\n\\n\\t\\tsyncano.Please().Save<Book>(book, OnGetBookSuccess, OnGetBookFailure);\\n\\t}\\n\\n\\tprivate void OnGetBookSuccess(Response<Book> response)\\n\\t{\\n\\t\\tbook = response.Data;\\n\\t\\tDebug.Log(\\\"success \\\" + book.Title);\\n\\t}\\n\\n\\tprivate void OnGetBookFailure(Response<Book> response)\\n\\t{\\n\\t\\tDebug.Log(\\\"failure\\\");\\n\\t}\\n}\",\n      \"language\": \"csharp\"\n    }\n  ]\n}\n[/block]\nDelete a Data Object\n================\n\nYou'll only need the Data Object `id` to delete it.\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"using UnityEngine;\\nusing System.Collections;\\nusing Syncano;\\nusing Syncano.Data;\\n\\npublic class Main : MonoBehaviour {\\n\\t\\n\\tprivate SyncanoClient syncano;\\n\\n\\tvoid Start () {\\n\\t\\tsyncano = SyncanoClient.Instance.Init(\\\"YOUR_API_KEY\\\", \\\"YOUR_INSTANCE_NAME\\\");\\n\\t\\tBook book = new Book();\\n\\t\\tbook.Id = 174;\\n\\t\\n\\t\\tsyncano.Please().Delete(book, OnDeleteBookSuccess, OnDeleteBookFailure);\\n\\t}\\n\\n\\tprivate void OnDeleteBookSuccess(Response<Book> response)\\n\\t{\\n\\t\\tDebug.Log(\\\"success\\\");\\n\\t}\\n\\n\\tprivate void OnDeleteBookFailure(Response<Book> response)\\n\\t{\\n\\t\\tDebug.Log(\\\"failure \\\" + response.syncanoError);\\n\\t}\\n}\",\n      \"language\": \"csharp\"\n    }\n  ]\n}\n[/block]\nScript Endpoints\n=============\n\nRead more about Script Endpoints in our [Developer Manual](doc:endpoints-scripts).\nHow to run a Script Endpoint:\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"using UnityEngine;\\nusing System.Collections;\\nusing Syncano;\\nusing Syncano.Data;\\n\\npublic class Main : MonoBehaviour {\\n\\t\\n\\tprivate SyncanoClient syncano;\\n\\n\\tvoid Start () {\\n\\t\\tsyncano = SyncanoClient.Instance.Init(\\\"YOUR_API_KEY\\\", \\\"YOUR_INSTANCE_NAME\\\");\\n\\t\\tsyncano.Please().RunScriptEndpointUrl(\\\"ENDPOINT_URL\\\", EndpointCallback);\\n\\t}\\n\\n\\tprivate void EndpointCallback(ScriptEndpoint response)\\n\\t{\\n\\t\\tif(response.IsSuccess)\\n\\t\\t{\\n\\t\\t\\tDebug.Log(\\\"success\\\");\\n\\t\\t}\\n\\n\\t\\telse\\n\\t\\t{\\n\\t\\t\\tDebug.Log(response.syncanoError);\\n\\t\\t}\\n\\t}\\n}\",\n      \"language\": \"csharp\"\n    }\n  ]\n}\n[/block]\n\nSynchronization and Real-Time Channels\n========================\n\nYou can read more about Real-Time Syncing and channels in the [Realtime communication](doc:realtime-communication) chapter.\n\nTo create a new channel you simply need to run CreateChannel method.\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"using UnityEngine;\\nusing System.Collections;\\nusing Syncano;\\nusing Syncano.Data;\\n\\npublic class Main : MonoBehaviour {\\n\\t\\n\\tprivate SyncanoClient syncano;\\n\\n\\tvoid Start () {\\n\\t\\tsyncano = SyncanoClient.Instance.Init(\\\"YOUR_API_KEY\\\", \\\"YOUR_INSTANCE_NAME\\\");\\n\\n\\t\\tChannel newChannel = new Channel(\\\"new_channel\\\");\\n\\t\\tsyncano.Please().CreateChannel(newChannel, OnResponseReturned);\\n\\t}\\n\\n\\tprivate void OnResponseReturned(Response<Channel> response)\\n\\t{\\n\\t\\tif(response.IsSuccess)\\n\\t\\t{\\n\\t\\t\\tDebug.Log(\\\"success\\\");\\n\\t\\t}\\n\\n\\t\\telse\\n\\t\\t{\\n\\t\\t\\tDebug.Log(\\\"failure\\\");\\n\\t\\t}\\n\\t}\\n}\",\n      \"language\": \"csharp\"\n    }\n  ]\n}\n[/block]\nTo receive real-time data from a channel, you need to start listening to a existing channel and provide appropriate callbacks.\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"using UnityEngine;\\nusing System.Collections;\\nusing Syncano;\\nusing Syncano.Data;\\n\\npublic class Main : MonoBehaviour {\\n\\t\\n\\tprivate SyncanoClient syncano;\\n\\n\\tvoid Start () {\\n\\t\\tsyncano = SyncanoClient.Instance.Init(\\\"YOUR_API_KEY\\\", \\\"YOUR_INSTANCE_NAME\\\");\\n    ChannelConnection cc = new ChannelConnection(this, OnChannelResponseSuccess, OnChannelResponseFailure);\\n\\t\\tcc.Start(\\\"test_channel\\\", 0);\\n\\t}\\n\\n\\tprivate void OnChannelResponseSuccess(Response<Notification> response)\\n\\t{\\n\\t\\tDebug.Log(response.Data.Result.Content);\\n\\t}\\n\\n\\tprivate void OnChannelResponseFailure(Response<Notification> response)\\n\\t{\\n\\t\\tDebug.Log(\\\"failure \\\" + response.syncanoError);\\n\\t}\\n\\n}\",\n      \"language\": \"csharp\"\n    }\n  ]\n}\n[/block]\nHandling users\n============\n\nTo find out more about the Users module on Syncano - read [User management](doc:user-management) chapter. Here, we'll quickly teach you how to create a new user, log the user in and get their profile data.\n\n### Register new user\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"using UnityEngine;\\nusing System.Collections;\\nusing Syncano;\\nusing Syncano.Data;\\n\\npublic class Main : MonoBehaviour {\\n\\t\\n\\tprivate SyncanoClient syncano;\\n\\n\\tvoid Start () {\\n\\t\\tsyncano = SyncanoClient.Instance.Init(\\\"YOUR_API_KEY\\\", \\\"YOUR_INSTANCE_NAME\\\");\\n    \\n\\t\\tUser<Profile> user =  new User<Profile>(\\\"username\\\", \\\"password\\\");\\n\\t\\tuser.Register(UserCreateCallback);\\n\\t}\\n\\n\\tprivate void UserCreateCallback(Response<User<Profile>> response)\\n\\t{\\n\\t\\tif(response.IsSuccess)\\n\\t\\t{\\n\\t\\t\\tDebug.Log(\\\"success\\\");\\n\\t\\t}\\n\\n\\t\\telse\\n\\t\\t{\\n\\t\\t\\tDebug.Log(\\\"failure\\\");\\n\\t\\t}\\n\\t}\\n}\",\n      \"language\": \"csharp\"\n    }\n  ]\n}\n[/block]\n### Log in user with password\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"using UnityEngine;\\nusing System.Collections;\\nusing Syncano;\\nusing Syncano.Data;\\n\\npublic class Main : MonoBehaviour {\\n\\t\\n\\tprivate SyncanoClient syncano;\\n\\n\\tvoid Start () {\\n    syncano = SyncanoClient.Instance.Init(\\\"YOUR_API_KEY\\\", \\\"YOUR_INSTANCE_NAME\\\");\\n\\n\\t\\tUser<Profile> user =  new User<Profile>(\\\"username\\\", \\\"password\\\");\\n\\t\\tuser.Login(UserCreateCallbackSuccess, UserCreateCallbackFail);\\n\\t}\\n\\n\\tprivate void UserCreateCallbackSuccess(Response<User<Profile>> response)\\n\\t{\\n\\t\\tDebug.Log(\\\"success\\\");\\n\\t}\\n\\n\\tprivate void UserCreateCallbackFail(Response<User<Profile>> response)\\n\\t{\\n\\t\\tDebug.Log(\\\"fail\\\");\\n\\t}\\n}\",\n      \"language\": \"csharp\"\n    }\n  ]\n}\n[/block]\n### Updating User\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"using UnityEngine;\\nusing System.Collections;\\nusing Syncano;\\nusing Syncano.Data;\\n\\npublic class Main : MonoBehaviour {\\n\\t\\n\\tprivate SyncanoClient syncano;\\n\\n\\tIEnumerator Start () {\\n    syncano = SyncanoClient.Instance.Init(\\\"YOUR_API_KEY\\\", \\\"YOUR_INSTANCE_NAME\\\");\\n\\n\\t\\tUser<Profile> user =  new User<Profile>(\\\"username\\\", \\\"password\\\");\\n\\n\\t\\tyield return user.Login(UserCallbackSuccess, UserCallbackFail); //Wait until we successfully login.\\n\\n\\t\\tuser.Password = \\\"new_password\\\"; //set new user name\\n\\t\\tuser.UserName = \\\"new_user_name\\\"; // set new password\\n\\t\\tuser.UpdateCustomUser(UserCallbackSuccess, UserCallbackFail);\\n\\t}\\n\\n\\tprivate void UserCallbackSuccess(Response<User<Profile>> response)\\n\\t{\\n\\t\\tDebug.Log(\\\"success\\\");\\n\\t}\\n\\n\\tprivate void UserCallbackFail(Response<User<Profile>> response)\\n\\t{\\n\\t\\tDebug.Log(\\\"fail\\\");\\n\\t}\\n}\",\n      \"language\": \"csharp\"\n    }\n  ]\n}\n[/block]\n### Subclassing user and user profile\n\nYou can also subclass AbstractUser and Profile class - this is really handy when you want to expand a user's profile and some extra properties like avatar for example. For more details on how this works, go to [User management](doc:user-management#user-profiles) and see below how to prepare your classes on Unity.\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"using UnityEngine;\\nusing System.Collections;\\nusing Newtonsoft.Json;\\n\\npublic class TestProfile : Profile {\\n  \\n\\t[JsonProperty(\\\"avatar\\\", NullValueHandling = NullValueHandling.Ignore)]\\n\\tpublic SyncanoFile Avatar { get; set; }\\n\\n\\tpublic TestProfile() { }\\n\\n\\tpublic TestProfile (SyncanoFile avatar)\\n\\t{\\n\\t\\tAvatar = avatar;\\n}\",\n      \"language\": \"csharp\"\n    }\n  ]\n}\n[/block]\nUpdate a user's avatar\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"User<TestProfile> user =  new User<TestProfile>(\\\"username\\\", \\\"password\\\");\\n\\nyield return user.Login(UserCallbackSuccess, UserCallbackFail); //Wait until we successfully login.\\n\\nSyncanoFile avatar = new SyncanoFile(AvatarImage.sprite.texture.EncodeToPNG());\\n\\nuser.Profile = new TestProfile(avatar);\\n\\nuser.UpdateCustomUser(UserCallbackSuccess, UserCallbackFail);\",\n      \"language\": \"csharp\"\n    }\n  ]\n}\n[/block]\nResponse codes and error messages\n============================\n\nIf your request fails, you can always check what the reason was by looking at the result code.\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"Book b = new Book();\\nsyncano.Please().Save(book, onSuccess, onError);\\n\\nprivate void onSuccess(Response<Book> response)\\n{\\n  Debug.Log(\\\"Success\\\");\\n}\\n\\nprivate void onError(Response<Book> response)\\n{\\n  response.webError; // no connection etc. errors\\n  response.syncanoError; // internal Syncano errors\\n\\n  response.responseCode; // request response code (201, 404, etc.)\\n}\",\n      \"language\": \"csharp\",\n      \"name\": \"Unity\"\n    }\n  ]\n}\n[/block]\nMore about error codes can be found [here](http://docs.syncano.com/v0.1.1/docs/errors).\n\nSupport\n======\n\nNow you’re ready to use Syncano in your Unity project. We really hope you will enjoy working with our platform. If you have any issues or suggestions, just let us know at support:::at:::syncano.com.\n\nLicense\n======\n\nSyncano’s Unity Library is available under the MIT license. See the LICENSE file inside library sources for more info.","excerpt":"Unity SDK Quick Start Guide","slug":"unity","type":"basic","title":"Unity"}

Unity

Unity SDK Quick Start Guide

## Chapter Contents: 1. [Overview](#overview) 2. [Installing the Syncano Unity Library](#installing-the-syncano-android-library) 3. [Using the Syncano Library](#using-the-syncano-library) 4. [Support](#section-support) 5. [License](#section-license) [block:api-header] { "type": "basic", "title": "Overview" } [/block] This guide will walk you through the installation steps of the Syncano Library for Unity, as well as give you a couple of usage examples. If you don't have a Syncano account yet, you can read about how to create one [here](doc:getting-started-with-syncano). [block:api-header] { "type": "basic", "title": "Installing the Syncano Unity Library" } [/block] 1. [Source](#section-source) 2. [Unity3D Engine](#section-unity3d) 3. [Create a New Unity Project](#section-create-a-new-unity-project) 4. [Adding the Syncano Library to a Project](#section-adding-the-syncano-library-to-a-project) Source ====== Syncano Unity Library is available from our [GitHub](https://github.com/Syncano/syncano-unity/releases). Full source code can be downloaded from [Github](https://github.com/Syncano/syncano-unity/) Unity3D =========== If you don’t have Unity3D already, you can find the newest version [here](https://unity3d.com/get-unity/download). Create a New Unity Project ===================== 1. Open Unity3D 2. Choose **Projects -> New** 3. Type in the project name and press **Create Project**. We’ll use **SyncanoProject** as an app name 4. In **File -> Build Settings** you can choose proper platform for your project - we’ll just stick with default one Adding the Syncano Library to a Project =========================== #### Downloading Unity Package The Unity package can be downloaded from [our Github repo here](https://github.com/Syncano/syncano-unity/releases). All you need to do is to download it and open it in the Unity3D engine. The package can be imported by choosing **Assets -> Import Package -> Custom Package**. #### Using DLL The compiled library can be downloaded from [releases page](https://github.com/Syncano/syncano-unity/releases). You also need to download Newtonsoft.Net dll from [here](https://github.com/SaladLab/Json.Net.Unity3D/releases). Place both dll files in one folder under the Assets directory. [block:api-header] { "type": "basic", "title": "Using the Unity3D Library" } [/block] 1. [Importing the Syncano Library](#section-importing-the-syncano-library) 2. [Synchronous and Asynchronous requests](#section-synchronous-and-asynchronous-requests) 3. [Connecting to Syncano](#section-connecting-to-syncano) 4. [Adding your Data Class](#section-adding-your-class) 5. [Download the most recent Objects](#section-download-the-most-recent-objects) a. [Synchronous](#section-synchronous) b. [Asynchronous](#section-asynchronous) 6. [Get a single Data Object](#section-get-a-single-data-object) 7. [Creating a new Data Object](#section-creating-a-new-data-object) 8. [Modify an Object](#section-modify-an-object) 9. [Delete a Data Object](#section-delete-a-data-object) 10. [Data Endpoints](#section-data-endpoints) 11. [Script endpoints](#section-script-endpoints) 12. [Synchronization and Real-Time Channels](#section-synchronization-and-real-time-channels) 13. [Handling users](#section-handling-users) 14. [Response codes and error messages](#section-response-codes-and-error-messages) Importing the Syncano Library ==================== When writing code that uses Syncano objects, the IDE will suggest proper modules to be imported in your file. In general, everything is placed under the **Syncano**.* namespace, but you should rely on the IDE suggestions to provide proper imports. Synchronous and Asynchronous requests ================================ Generally, all requests are asynchronous. If you want to make a `synchronous` call you have to run it in an IEnumerator and wait until it has finished. For simplicity, further examples will show the asynchronous implementation. Connecting to Syncano ================= Create a `SyncanoClient` object and initialize it as follows, otherwise you will not be able to make any calls to the backend. [block:code] { "codes": [ { "code": "SyncanoClient syncano = SyncanoClient.Instance.Init(\"YOUR_API_KEY\", \"YOUR_INSTANCE_NAME\");", "language": "csharp" } ] } [/block] `SyncanoClient` is a Singleton that will be available everywhere once it has been initialized. It can be accessed through `SyncanoClient.Instance`. Adding your class ============= [block:callout] { "type": "info", "body": "Before you will use the Data Class in your app, remember that the Data Class should already exist in Syncano. You can add your Data Classes quickly by using our [Dashboard](https://dashboard.syncano.io/)!\n\nYou can read more about Data Classes [here](doc:classes-overview).", "title": "Using Data Classes in Syncano" } [/block] Now we will add the C# class you had implemented on Syncano. We will be using a simple Book Data Class which only has two attributes: "title" and "subtitle", both being of type "string". The Schema for this class would look like this: [block:code] { "codes": [ { "code": "[\n {\"type\": \"string\",\"name\": \"title\"},\n {\"type\": \"string\",\"name\": \"subtitle\"}\n]", "language": "json" } ] } [/block] Our C# class would look like: [block:code] { "codes": [ { "code": "using Newtonsoft.Json;\nusing Syncano;\n\npublic class Book : SyncanoObject {\n\n\tpublic const string FIELD_TITLE = \"title\";\n\tpublic const string FIELD_SUBTITLE = \"subtitle\";\n\n\t[JsonProperty(FIELD_TITLE)]\n\tpublic string Title { get; set; }\n\n\t[JsonProperty(FIELD_SUBTITLE)]\n\tpublic string Subtitle { get; set; }\n}", "language": "csharp" } ] } [/block] As you can see we are using Newtonsoft.Net Attributes to describe class properties. Attribute's overloaded constructor takes a string parameter to map property with class schema in Syncano. It means that you can name any attribute however you want and them map it through JsonProperty Attribute. Field types and names should match those from the **schema**. Our class needs to inherit the `SyncanoObject` class. It will deliver standard fields such as: - id - created_at - updated_at - revision Download the most recent Objects ============================ ### Synchronous If you need to wait for a result, you have to run your code in an IEnumerator and wait for a Coroutine to finish. [block:code] { "codes": [ { "code": "using UnityEngine;\nusing System.Collections;\nusing Syncano;\n\npublic class Main : MonoBehaviour {\n\t\n\tprivate SyncanoClient syncano;\n\n\tIEnumerator Start () {\n\t\tsyncano = SyncanoClient.Instance.Init(\"YOUR_API_KEY\", \"YOUR_INSTANCE_NAME\");\n\t\tyield return StartCoroutine(GetListOfBooks());\n\t}\n\n\tprivate IEnumerator GetListOfBooks() {\n\t\tyield return syncano.Please().Get<Book>(OnGetBookSuccess, OnGetBookFailure);\n\t}\n\n\tprivate void OnGetBookSuccess(ResponseGetList<Book> response) {\n\t\tDebug.Log(\"success \" + response.Objects.Count);\n\t}\n\n\tprivate void OnGetBookFailure(ResponseGetList<Book> response) {\n\t\tDebug.Log(\"failure\");\n\t}\n}", "language": "csharp" } ] } [/block] ### Asynchronous With the async request, you will get a page of most recent data objects in the background. Then, you will handle the UI update in a callback. The difference is that you don't need to wait until Coroutine ends. [block:code] { "codes": [ { "code": "using UnityEngine;\nusing System.Collections;\nusing Syncano;\n\npublic class Main : MonoBehaviour {\n\t\n\tprivate SyncanoClient syncano;\n\n\tvoid Start () {\n\t\tsyncano = SyncanoClient.Instance.Init(\"YOUR_API_KEY\", \"YOUR_INSTANCE_NAME\");\n\t\tsyncano.Please().Get<Book>(OnGetBookSuccess, OnGetBookFailure);\n\t}\n\n\tprivate void OnGetBookSuccess(ResponseGetList<Book> response)\n\t{\n\t\tDebug.Log(\"success \" + response.Objects.Count);\n\t}\n\n\tprivate void OnGetBookFailure(ResponseGetList<Book> response)\n\t{\n\t\tDebug.Log(\"failure\");\n\t}\n}", "language": "csharp" } ] } [/block] Both cases require to provide callbacks for a successful call and failed one. You can also pass one generic callback to handle both cases. [block:code] { "codes": [ { "code": "using UnityEngine;\nusing System.Collections;\nusing Syncano;\nusing Syncano.Data;\n\npublic class Main : MonoBehaviour {\n\t\n\tprivate SyncanoClient syncano;\n\n\tvoid Start () {\n\t\tsyncano = SyncanoClient.Instance.Init(\"YOUR_API_KEY\", \"YOUR_INSTANCE_NAME\");\n\t\tsyncano.Please().Get<Book>(OnGetBookCallback);\n\t}\n\n\tprivate void OnGetBookCallback(ResponseGetList<Book> response)\n\t{\n\t\tif(response.IsSuccess)\n\t\t{\n\t\t\tDebug.Log(\"success \" + response.Objects.Count);\n\t\t}\n\n\t\telse\n\t\t{\n\t\t\tif(response.IsSyncanoError)\n\t\t\t{\n\t\t\t\tDebug.Log(response.syncanoError);\n\t\t\t}\n\n\t\t\telse\n\t\t\t{\n\t\t\t\tDebug.Log(response.webError);\n\t\t\t}\n\t\t}\n\t}\n}", "language": "csharp" } ] } [/block] Get a single Data Object =================== Now, if you'd only like to get a single Data Object, you can get it by its `id`. [block:code] { "codes": [ { "code": "using UnityEngine;\nusing System.Collections;\nusing Syncano;\nusing Syncano.Data;\n\npublic class Main : MonoBehaviour {\n\t\n\tprivate SyncanoClient syncano;\n\tprivate Book book;\n\n\tvoid Start () {\n int id = 1;\n\t\tsyncano = SyncanoClient.Instance.Init(\"YOUR_API_KEY\", \"YOUR_INSTANCE_NAME\");\n\t\tsyncano.Please().Get<Book>(id, OnGetBookSuccess, OnGetBookFailure);\n\t}\n\n\tprivate void OnGetBookSuccess(Response<Book> response)\n\t{\n\t\tbook = response.Data;\n\t\tDebug.Log(\"success \" + book.Title);\n\t}\n\n\tprivate void OnGetBookFailure(Response<Book> response)\n\t{\n\t\tDebug.Log(\"failure\");\n\t}\n}", "language": "csharp" } ] } [/block] Creating a new Data Object ===================== Below, we create a Data Object and fill it with data. Then we save the object on Syncano. In the response, you will get a Data Object with fields `id`, `createdAt`, `updatedAt` and `revision`. [block:code] { "codes": [ { "code": "using UnityEngine;\nusing System.Collections;\nusing Syncano;\nusing Syncano.Data;\n\npublic class Main : MonoBehaviour {\n\t\n\tprivate SyncanoClient syncano;\n\tBook book;\n\n\tvoid Start () {\n\t\tsyncano = SyncanoClient.Instance.Init(\"YOUR_API_KEY\", \"YOUR_INSTANCE_NAME\");\n\t\tbook = new Book();\n\t\tbook.Title = \"Title\";\n\t\tbook.Subtitle = \"Subtitle\";\n\n\t\tsyncano.Please().Save<Book>(book, OnGetBookSuccess, OnGetBookFailure);\n\t}\n\n\tprivate void OnGetBookSuccess(Response<Book> response)\n\t{\n\t\tbook = response.Data;\n\t\tDebug.Log(\"success \" + book.Title);\n\t}\n\n\tprivate void OnGetBookFailure(Response<Book> response)\n\t{\n\t\tDebug.Log(\"failure\");\n\t}\n}", "language": "csharp" } ] } [/block] Modify an Object ================== Do it the same way as when creating an object. When an object's `id` is set, then library tries to update it. But when the `id` is `null`, it tries to create it. [block:code] { "codes": [ { "code": "using UnityEngine;\nusing System.Collections;\nusing Syncano;\nusing Syncano.Data;\n\npublic class Main : MonoBehaviour {\n\t\n\tprivate SyncanoClient syncano;\n\tprivate Book book;\n\n\tvoid Start () {\n\t\tsyncano = SyncanoClient.Instance.Init(\"YOUR_API_KEY\", \"YOUR_INSTANCE_NAME\");\n\t\tbook = new Book();\n\t\tbook.Id = 170; //SOME EXISTING ID\n\t\tbook.Subtitle = \"New Subtitle\";\n\n\t\tsyncano.Please().Save<Book>(book, OnGetBookSuccess, OnGetBookFailure);\n\t}\n\n\tprivate void OnGetBookSuccess(Response<Book> response)\n\t{\n\t\tbook = response.Data;\n\t\tDebug.Log(\"success \" + book.Title);\n\t}\n\n\tprivate void OnGetBookFailure(Response<Book> response)\n\t{\n\t\tDebug.Log(\"failure\");\n\t}\n}", "language": "csharp" } ] } [/block] Delete a Data Object ================ You'll only need the Data Object `id` to delete it. [block:code] { "codes": [ { "code": "using UnityEngine;\nusing System.Collections;\nusing Syncano;\nusing Syncano.Data;\n\npublic class Main : MonoBehaviour {\n\t\n\tprivate SyncanoClient syncano;\n\n\tvoid Start () {\n\t\tsyncano = SyncanoClient.Instance.Init(\"YOUR_API_KEY\", \"YOUR_INSTANCE_NAME\");\n\t\tBook book = new Book();\n\t\tbook.Id = 174;\n\t\n\t\tsyncano.Please().Delete(book, OnDeleteBookSuccess, OnDeleteBookFailure);\n\t}\n\n\tprivate void OnDeleteBookSuccess(Response<Book> response)\n\t{\n\t\tDebug.Log(\"success\");\n\t}\n\n\tprivate void OnDeleteBookFailure(Response<Book> response)\n\t{\n\t\tDebug.Log(\"failure \" + response.syncanoError);\n\t}\n}", "language": "csharp" } ] } [/block] Script Endpoints ============= Read more about Script Endpoints in our [Developer Manual](doc:endpoints-scripts). How to run a Script Endpoint: [block:code] { "codes": [ { "code": "using UnityEngine;\nusing System.Collections;\nusing Syncano;\nusing Syncano.Data;\n\npublic class Main : MonoBehaviour {\n\t\n\tprivate SyncanoClient syncano;\n\n\tvoid Start () {\n\t\tsyncano = SyncanoClient.Instance.Init(\"YOUR_API_KEY\", \"YOUR_INSTANCE_NAME\");\n\t\tsyncano.Please().RunScriptEndpointUrl(\"ENDPOINT_URL\", EndpointCallback);\n\t}\n\n\tprivate void EndpointCallback(ScriptEndpoint response)\n\t{\n\t\tif(response.IsSuccess)\n\t\t{\n\t\t\tDebug.Log(\"success\");\n\t\t}\n\n\t\telse\n\t\t{\n\t\t\tDebug.Log(response.syncanoError);\n\t\t}\n\t}\n}", "language": "csharp" } ] } [/block] Synchronization and Real-Time Channels ======================== You can read more about Real-Time Syncing and channels in the [Realtime communication](doc:realtime-communication) chapter. To create a new channel you simply need to run CreateChannel method. [block:code] { "codes": [ { "code": "using UnityEngine;\nusing System.Collections;\nusing Syncano;\nusing Syncano.Data;\n\npublic class Main : MonoBehaviour {\n\t\n\tprivate SyncanoClient syncano;\n\n\tvoid Start () {\n\t\tsyncano = SyncanoClient.Instance.Init(\"YOUR_API_KEY\", \"YOUR_INSTANCE_NAME\");\n\n\t\tChannel newChannel = new Channel(\"new_channel\");\n\t\tsyncano.Please().CreateChannel(newChannel, OnResponseReturned);\n\t}\n\n\tprivate void OnResponseReturned(Response<Channel> response)\n\t{\n\t\tif(response.IsSuccess)\n\t\t{\n\t\t\tDebug.Log(\"success\");\n\t\t}\n\n\t\telse\n\t\t{\n\t\t\tDebug.Log(\"failure\");\n\t\t}\n\t}\n}", "language": "csharp" } ] } [/block] To receive real-time data from a channel, you need to start listening to a existing channel and provide appropriate callbacks. [block:code] { "codes": [ { "code": "using UnityEngine;\nusing System.Collections;\nusing Syncano;\nusing Syncano.Data;\n\npublic class Main : MonoBehaviour {\n\t\n\tprivate SyncanoClient syncano;\n\n\tvoid Start () {\n\t\tsyncano = SyncanoClient.Instance.Init(\"YOUR_API_KEY\", \"YOUR_INSTANCE_NAME\");\n ChannelConnection cc = new ChannelConnection(this, OnChannelResponseSuccess, OnChannelResponseFailure);\n\t\tcc.Start(\"test_channel\", 0);\n\t}\n\n\tprivate void OnChannelResponseSuccess(Response<Notification> response)\n\t{\n\t\tDebug.Log(response.Data.Result.Content);\n\t}\n\n\tprivate void OnChannelResponseFailure(Response<Notification> response)\n\t{\n\t\tDebug.Log(\"failure \" + response.syncanoError);\n\t}\n\n}", "language": "csharp" } ] } [/block] Handling users ============ To find out more about the Users module on Syncano - read [User management](doc:user-management) chapter. Here, we'll quickly teach you how to create a new user, log the user in and get their profile data. ### Register new user [block:code] { "codes": [ { "code": "using UnityEngine;\nusing System.Collections;\nusing Syncano;\nusing Syncano.Data;\n\npublic class Main : MonoBehaviour {\n\t\n\tprivate SyncanoClient syncano;\n\n\tvoid Start () {\n\t\tsyncano = SyncanoClient.Instance.Init(\"YOUR_API_KEY\", \"YOUR_INSTANCE_NAME\");\n \n\t\tUser<Profile> user = new User<Profile>(\"username\", \"password\");\n\t\tuser.Register(UserCreateCallback);\n\t}\n\n\tprivate void UserCreateCallback(Response<User<Profile>> response)\n\t{\n\t\tif(response.IsSuccess)\n\t\t{\n\t\t\tDebug.Log(\"success\");\n\t\t}\n\n\t\telse\n\t\t{\n\t\t\tDebug.Log(\"failure\");\n\t\t}\n\t}\n}", "language": "csharp" } ] } [/block] ### Log in user with password [block:code] { "codes": [ { "code": "using UnityEngine;\nusing System.Collections;\nusing Syncano;\nusing Syncano.Data;\n\npublic class Main : MonoBehaviour {\n\t\n\tprivate SyncanoClient syncano;\n\n\tvoid Start () {\n syncano = SyncanoClient.Instance.Init(\"YOUR_API_KEY\", \"YOUR_INSTANCE_NAME\");\n\n\t\tUser<Profile> user = new User<Profile>(\"username\", \"password\");\n\t\tuser.Login(UserCreateCallbackSuccess, UserCreateCallbackFail);\n\t}\n\n\tprivate void UserCreateCallbackSuccess(Response<User<Profile>> response)\n\t{\n\t\tDebug.Log(\"success\");\n\t}\n\n\tprivate void UserCreateCallbackFail(Response<User<Profile>> response)\n\t{\n\t\tDebug.Log(\"fail\");\n\t}\n}", "language": "csharp" } ] } [/block] ### Updating User [block:code] { "codes": [ { "code": "using UnityEngine;\nusing System.Collections;\nusing Syncano;\nusing Syncano.Data;\n\npublic class Main : MonoBehaviour {\n\t\n\tprivate SyncanoClient syncano;\n\n\tIEnumerator Start () {\n syncano = SyncanoClient.Instance.Init(\"YOUR_API_KEY\", \"YOUR_INSTANCE_NAME\");\n\n\t\tUser<Profile> user = new User<Profile>(\"username\", \"password\");\n\n\t\tyield return user.Login(UserCallbackSuccess, UserCallbackFail); //Wait until we successfully login.\n\n\t\tuser.Password = \"new_password\"; //set new user name\n\t\tuser.UserName = \"new_user_name\"; // set new password\n\t\tuser.UpdateCustomUser(UserCallbackSuccess, UserCallbackFail);\n\t}\n\n\tprivate void UserCallbackSuccess(Response<User<Profile>> response)\n\t{\n\t\tDebug.Log(\"success\");\n\t}\n\n\tprivate void UserCallbackFail(Response<User<Profile>> response)\n\t{\n\t\tDebug.Log(\"fail\");\n\t}\n}", "language": "csharp" } ] } [/block] ### Subclassing user and user profile You can also subclass AbstractUser and Profile class - this is really handy when you want to expand a user's profile and some extra properties like avatar for example. For more details on how this works, go to [User management](doc:user-management#user-profiles) and see below how to prepare your classes on Unity. [block:code] { "codes": [ { "code": "using UnityEngine;\nusing System.Collections;\nusing Newtonsoft.Json;\n\npublic class TestProfile : Profile {\n \n\t[JsonProperty(\"avatar\", NullValueHandling = NullValueHandling.Ignore)]\n\tpublic SyncanoFile Avatar { get; set; }\n\n\tpublic TestProfile() { }\n\n\tpublic TestProfile (SyncanoFile avatar)\n\t{\n\t\tAvatar = avatar;\n}", "language": "csharp" } ] } [/block] Update a user's avatar [block:code] { "codes": [ { "code": "User<TestProfile> user = new User<TestProfile>(\"username\", \"password\");\n\nyield return user.Login(UserCallbackSuccess, UserCallbackFail); //Wait until we successfully login.\n\nSyncanoFile avatar = new SyncanoFile(AvatarImage.sprite.texture.EncodeToPNG());\n\nuser.Profile = new TestProfile(avatar);\n\nuser.UpdateCustomUser(UserCallbackSuccess, UserCallbackFail);", "language": "csharp" } ] } [/block] Response codes and error messages ============================ If your request fails, you can always check what the reason was by looking at the result code. [block:code] { "codes": [ { "code": "Book b = new Book();\nsyncano.Please().Save(book, onSuccess, onError);\n\nprivate void onSuccess(Response<Book> response)\n{\n Debug.Log(\"Success\");\n}\n\nprivate void onError(Response<Book> response)\n{\n response.webError; // no connection etc. errors\n response.syncanoError; // internal Syncano errors\n\n response.responseCode; // request response code (201, 404, etc.)\n}", "language": "csharp", "name": "Unity" } ] } [/block] More about error codes can be found [here](http://docs.syncano.com/v0.1.1/docs/errors). Support ====== Now you’re ready to use Syncano in your Unity project. We really hope you will enjoy working with our platform. If you have any issues or suggestions, just let us know at support@syncano.com. License ====== Syncano’s Unity Library is available under the MIT license. See the LICENSE file inside library sources for more info.