public static void ListenForDecision()
 {
     DecisionRequestService.OnDecisionReceived -= TestResponseCaching;
     DecisionRequestService.OnDecisionReceived += TestResponseCaching;
     webResponse  = null;
     testComplete = false;
 }
 static void TestResponseCaching(TutorialWebResponse response)
 {
     Debug.Log("TestResponseCaching");
     Debug.Log(response);
     webResponse  = response;
     testComplete = true;
 }
Exemplo n.º 3
0
        /// <summary>
        /// Request to fetch a value from Unity Analytics Services to show or skip tutorial for this user.
        /// Returns an int val from the Unity Tutorial Manager Decision Engine to show or skip tutorial for the user.
        /// If the request fails the user will be shown the tutorial by default.
        /// </summary>
        private static void CallTutorialManagerService(DeviceInfo data)
        {
            var json = JsonUtility.ToJson(data);

            webHandlerGO = new GameObject();
            var webHandler = webHandlerGO.AddComponent <TutorialManagerWebHandler>();

            webHandler.PostRequestReturned += (webRequest) =>
            {
                var  response = new TutorialWebResponse();
                bool isError  = false;
#if UNITY_2017_1_OR_NEWER
                isError = webRequest.isHttpError || webRequest.isNetworkError;
#else
                isError = webRequest.responseCode >= 400 || webRequest.isError;
#endif
                if (isError)
                {
                    Debug.LogWarningFormat("Error received from server: {0}: {1}. Defaulting to true.", webRequest.responseCode, webRequest.error);
                }
                else
                {
                    try
                    {
                        // If web request was successful then proceed with tutorial manager decision
                        string text           = webRequest.downloadHandler.text;
                        var    parsedResponse = JsonUtility.FromJson <TutorialWebResponse>(text);
                        response = parsedResponse;
                    }
                    catch (System.Exception ex)
                    {
                        Debug.LogWarningFormat("Tutorial Manager response parsing error: {0}. Defaulting to true.", ex);
                    }
                }
                GameObject.Destroy(webHandlerGO);
                //TODO: fire an event here
                if (OnDecisionReceived != null)
                {
                    OnDecisionReceived(response);
                }
            };
            webHandler.PostJson(adaptiveOnboardingUrl, json);
        }