Пример #1
0
        /// <summary>
        /// Fetches the given library in the database. Does nothing if there is
        /// already a request under way.
        /// </summary>
        /// <param name = "f">Floor to update.</param>
        /// <param name="callback">Callback function for data handling.</param>
        public void UpdateFloor(Floor f, UpdateFloorCallback callback)
        {
            if (updateFloorCoroutine != null)
            {
                return;
            }

            updateFloorCoroutine = StartCoroutine(UpdateFloorLoop(f, callback));
        }
Пример #2
0
        IEnumerator UpdateFloorLoop(Floor f, UpdateFloorCallback callback)
        {
            WWWForm form = new WWWForm();

            form.AddField("request", "update_floor");
            form.AddField("floor", f.ToJSON().ToString());
            form.AddField("token", token);

            // 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 update floor: " + request.error);
                callback(false, false);
            }
            else
            {
                Debug.Log(request.text);
                JSONNode root = JSON.Parse(request.text);

                if (root["success"] != null && root["success"].AsBool)
                {
                    callback(true, true);
                }
                else
                {
                    callback(true, false);
                }
            }

            updateFloorCoroutine = null;
        }