示例#1
0
        // ------------ private functions below ----------------------


        // Coroutine for getting a match info response
        private IEnumerator ProcessMatchResponse <JSONRESPONSE, USERRESPONSEDELEGATETYPE>(UnityWebRequest client, InternalResponseDelegate <JSONRESPONSE, USERRESPONSEDELEGATETYPE> internalCallback, USERRESPONSEDELEGATETYPE userCallback) where JSONRESPONSE : Response, new()
        {
            // wait for request to complete
            yield return(client.SendWebRequest());

            JSONRESPONSE jsonInterface = new JSONRESPONSE();

            if (!(client.isNetworkError || client.isHttpError))
            {
                try
                {
                    JsonUtility.FromJsonOverwrite(client.downloadHandler.text, jsonInterface);
                }
                catch (ArgumentException exception)
                {
                    jsonInterface.SetFailure(UnityString.Format("ArgumentException:[{0}] ", exception.ToString()));
                }
            }
            else
            {
                jsonInterface.SetFailure(UnityString.Format("Request error:[{0}] Raw response:[{1}]", client.error, client.downloadHandler.text));
            }

            client.Dispose();

            internalCallback(jsonInterface, userCallback);
        }
示例#2
0
        private IEnumerator ProcessMatchResponse <JSONRESPONSE, USERRESPONSEDELEGATETYPE>(WWW client, InternalResponseDelegate <JSONRESPONSE, USERRESPONSEDELEGATETYPE> internalCallback, USERRESPONSEDELEGATETYPE userCallback) where JSONRESPONSE : Response, new()
        {
            yield return(client);

            JSONRESPONSE jsonInterface = new JSONRESPONSE();

            if (string.IsNullOrEmpty(client.error))
            {
                if (SimpleJson.SimpleJson.TryDeserializeObject(client.text, out object obj))
                {
                    IDictionary <string, object> dictionary = obj as IDictionary <string, object>;
                    if (dictionary != null)
                    {
                        try
                        {
                            jsonInterface.Parse(obj);
                        }
                        catch (FormatException ex)
                        {
                            jsonInterface.SetFailure(UnityString.Format("FormatException:[{0}] ", ex.ToString()));
                        }
                    }
                }
            }
            else
            {
                jsonInterface.SetFailure(UnityString.Format("Request error:[{0}] Raw response:[{1}]", client.error, client.text));
            }
            client.Dispose();
            internalCallback(jsonInterface, userCallback);
        }
        // ------------ private functions below ----------------------


        // Coroutine for getting a match info response
        private IEnumerator ProcessMatchResponse <JSONRESPONSE, USERRESPONSEDELEGATETYPE>(UnityWebRequest client, InternalResponseDelegate <JSONRESPONSE, USERRESPONSEDELEGATETYPE> internalCallback, USERRESPONSEDELEGATETYPE userCallback) where JSONRESPONSE : Response, new()
        {
            // wait for request to complete
            yield return(client.SendWebRequest());

            JSONRESPONSE jsonInterface = new JSONRESPONSE();

            if (!(client.isNetworkError || client.isHttpError))
            {
                object o;
                if (SimpleJson.SimpleJson.TryDeserializeObject(client.downloadHandler.text, out o))
                {
                    IDictionary <string, object> dictJsonObj = o as IDictionary <string, object>;
                    if (null != dictJsonObj)
                    {
                        // Catch exception and error handling below will print out some debug info
                        // Callback will be called properly with failure info
                        try
                        {
                            jsonInterface.Parse(o);
                        }
                        catch (FormatException exception)
                        {
                            jsonInterface.SetFailure(UnityString.Format("FormatException:[{0}] ", exception.ToString()));
                        }
                    }
                }
            }
            else
            {
                jsonInterface.SetFailure(UnityString.Format("Request error:[{0}] Raw response:[{1}]", client.error, client.downloadHandler.text));
            }

            client.Dispose();

            internalCallback(jsonInterface, userCallback);
        }
示例#4
0
 private IEnumerator ProcessMatchResponse <JSONRESPONSE, USERRESPONSEDELEGATETYPE>(WWW client, InternalResponseDelegate <JSONRESPONSE, USERRESPONSEDELEGATETYPE> internalCallback, USERRESPONSEDELEGATETYPE userCallback) where JSONRESPONSE : Response, new() =>
示例#5
0
 private IEnumerator ProcessMatchResponse <JSONRESPONSE, USERRESPONSEDELEGATETYPE>(WWW client, InternalResponseDelegate <JSONRESPONSE, USERRESPONSEDELEGATETYPE> internalCallback, USERRESPONSEDELEGATETYPE userCallback) where JSONRESPONSE : Response, new()
 {
     return(new < ProcessMatchResponse > c__Iterator0 <JSONRESPONSE, USERRESPONSEDELEGATETYPE> {
         client = client, internalCallback = internalCallback, userCallback = userCallback, <$> client = client, <$> internalCallback = internalCallback, <$> userCallback = userCallback
     });