/// <summary> /// Create a new library. /// </summary> /// <param name = "libName">Name of the library.</param> /// <param name="callback">Callback function for data handling.</param> public void CreateLibrary(string libName, CreateLibraryCallback callback) { if (createLibraryCoroutine != null) { return; } createLibraryCoroutine = StartCoroutine(CreateLibraryLoop(libName, callback)); }
IEnumerator CreateLibraryLoop(string libName, CreateLibraryCallback callback) { WWWForm form = new WWWForm(); form.AddField("request", "create_library"); form.AddField("token", token); form.AddField("library_name", libName); // Create a download object WWW request = new WWW(apiUrl, form); // Wait until the download is done yield return(request); if (!string.IsNullOrEmpty(request.error)) { Debug.Log("Unable to create library: " + request.error); callback(false, false, 0); } else { Debug.Log(request.text); JSONNode root = JSON.Parse(request.text); if (root["success"] != null && root["success"].AsBool) { callback(true, true, root["id"]); } else { callback(true, false, 0); } } createLibraryCoroutine = null; }