Пример #1
0
        void UnbindProject()
        {
            if (EditorUtility.DisplayDialog(L10n.Tr(k_UnlinkProjectDialogTitle),
                                            L10n.Tr(k_UnlinkProjectDialogMessage),
                                            L10n.Tr(k_Yes),
                                            L10n.Tr(k_No)))
            {
                ServicesRepository.DisableAllServices(shouldUpdateApiFlag: false);

                string cachedProjectName = UnityConnect.instance.projectInfo.projectName;
                UnityConnect.instance.UnbindProject();
                EditorAnalytics.SendProjectServiceBindingEvent(new ProjectBindManager.ProjectBindState()
                {
                    bound = false, projectName = cachedProjectName
                });
                NotificationManager.instance.Publish(Notification.Topic.ProjectBind, Notification.Severity.Info, L10n.Tr(k_ProjectUnlinkSuccessMessage));
                ReinitializeSettings();
            }
        }
Пример #2
0
        void CreateOperationOnCompleted(AsyncOperation obj)
        {
            if (m_CurrentRequest == null)
            {
                //If we lost our m_CurrentRequest request reference, we can't risk doing anything.
                return;
            }

            if (ServicesUtils.IsUnityWebRequestReadyForJsonExtract(m_CurrentRequest))
            {
                var jsonParser = new JSONParser(m_CurrentRequest.downloadHandler.text);
                var json       = jsonParser.Parse();
                var abort      = false;
                try
                {
                    var projectInfo = ExtractProjectInfoFromJson(json);
                    try
                    {
                        ServicesRepository.DisableAllServices(shouldUpdateApiFlag: false);
                        //Only register before creation. Remove first in case it was already added.
                        //TODO: Review to avoid dependency on project refreshed
                        UnityConnect.instance.ProjectStateChanged -= OnProjectStateChangedAfterCreation;
                        UnityConnect.instance.ProjectStateChanged += OnProjectStateChangedAfterCreation;
                        BindProject(projectInfo);
                    }
                    catch (Exception ex)
                    {
                        if (exceptionCallback != null)
                        {
                            exceptionCallback.Invoke(ex);
                            abort = true;
                        }
                        else
                        {
                            //If there is no exception callback, we have to at least log it
                            Debug.LogException(ex);
                        }
                    }
                    if (!abort)
                    {
                        createButtonCallback?.Invoke(projectInfo);
                    }
                }
                finally
                {
                    m_CurrentRequest?.Dispose();
                    m_CurrentRequest = null;
                }
            }
            else if (m_CurrentRequest.responseCode == k_HttpStatusCodeUnprocessableEntity)
            {
                m_CurrentRequest?.Dispose();
                m_CurrentRequest = null;
                m_CreateIteration++;
                RequestCreateOperation();
            }
            else
            {
                try
                {
                    var ex = new UnityConnectWebRequestException(L10n.Tr(k_CouldNotCreateProjectMessage))
                    {
                        error           = m_CurrentRequest.error,
                        method          = m_CurrentRequest.method,
                        timeout         = m_CurrentRequest.timeout,
                        url             = m_CurrentRequest.url,
                        responseHeaders = m_CurrentRequest.GetResponseHeaders(),
                        responseCode    = m_CurrentRequest.responseCode,
                        isHttpError     = (m_CurrentRequest.result == UnityWebRequest.Result.ProtocolError),
                        isNetworkError  = (m_CurrentRequest.result == UnityWebRequest.Result.ConnectionError),
                    };
                    if (exceptionCallback != null)
                    {
                        exceptionCallback.Invoke(ex);
                    }
                    else
                    {
                        //If there is no exception callback, we have to at least log it
                        Debug.LogException(ex);
                    }
                }
                finally
                {
                    m_CurrentRequest?.Dispose();
                    m_CurrentRequest = null;
                }
            }
        }
Пример #3
0
        void CreateOperationOnCompleted(AsyncOperation obj)
        {
            if (m_CurrentRequest == null)
            {
                //If we lost our m_CurrentRequest request reference, we can't risk doing anything.
                return;
            }

            if (m_CurrentRequest.result != UnityWebRequest.Result.ProtocolError)
            {
                var jsonParser = new JSONParser(m_CurrentRequest.downloadHandler.text);
                var json       = jsonParser.Parse();
                var abort      = false;
                try
                {
                    var projectInfo = ExtractProjectInfoFromJson(json);
                    try
                    {
                        ServicesRepository.DisableAllServices();
                        BindProject(projectInfo);
                    }
                    catch (Exception ex)
                    {
                        if (exceptionCallback != null)
                        {
                            exceptionCallback.Invoke(ex);
                            abort = true;
                        }
                        else
                        {
                            //If there is no exception callback, we have to at least log it
                            Debug.LogException(ex);
                        }
                    }
                    if (!abort)
                    {
                        createButtonCallback?.Invoke(projectInfo);
                    }
                }
                finally
                {
                    m_CurrentRequest?.Dispose();
                    m_CurrentRequest = null;
                }
            }
            else if (m_CurrentRequest.responseCode == k_HttpStatusCodeUnprocessableEntity)
            {
                m_CurrentRequest?.Dispose();
                m_CurrentRequest = null;
                m_CreateIteration++;
                RequestCreateOperation();
            }
            else
            {
                try
                {
                    var ex = new UnityConnectWebRequestException(L10n.Tr(k_CouldNotCreateProjectMessage))
                    {
                        error           = m_CurrentRequest.error,
                        method          = m_CurrentRequest.method,
                        timeout         = m_CurrentRequest.timeout,
                        url             = m_CurrentRequest.url,
                        responseHeaders = m_CurrentRequest.GetResponseHeaders(),
                        responseCode    = m_CurrentRequest.responseCode,
                        isHttpError     = (m_CurrentRequest.result == UnityWebRequest.Result.ProtocolError),
                        isNetworkError  = (m_CurrentRequest.result == UnityWebRequest.Result.ConnectionError),
                    };
                    if (exceptionCallback != null)
                    {
                        exceptionCallback.Invoke(ex);
                    }
                    else
                    {
                        //If there is no exception callback, we have to at least log it
                        Debug.LogException(ex);
                    }
                }
                finally
                {
                    m_CurrentRequest?.Dispose();
                    m_CurrentRequest = null;
                }
            }
        }