private static bool ShowEdExUpgrade()
        {
            if (string.IsNullOrEmpty(latestEdExVersion) || latestEdExVersion == "Unknown")
            {
                return(false);
            }
            var edexVer = PlayFabEditorHelper.GetApiVersion(ApiCategory.editorextensions);

            if (string.IsNullOrEmpty(edexVer) || edexVer == "Unknown")
            {
                return(true);
            }

            string[] currrent = edexVer.Split('.');
            if (currrent.Length != 3)
            {
                return(true);
            }

            string[] latest = latestEdExVersion.Split('.');
            return(latest.Length != 3 ||
                   int.Parse(latest[0]) > int.Parse(currrent[0]) ||
                   int.Parse(latest[1]) > int.Parse(currrent[1]) ||
                   int.Parse(latest[2]) > int.Parse(currrent[2]));
        }
 private static void OnLoginButtonClicked()
 {
     PlayFabEditorApi.Login(new LoginRequest()
     {
         DeveloperToolProductName    = PlayFabEditorHelper.EDEX_NAME,
         DeveloperToolProductVersion = PlayFabEditorHelper.GetApiVersion(ApiCategory.editorextensions),
         Email    = _userEmail,
         Password = _userPass
     }, (result) =>
     {
         PlayFabEditorPrefsSO.Instance.DevAccountToken = result.DeveloperClientToken;
         PlayFabEditorPrefsSO.Instance.DevAccountEmail = _userEmail;
         PlayFabEditorDataService.RefreshStudiosList();
         PlayFabEditor.RaiseStateUpdate(PlayFabEditor.EdExStates.OnLogin);
         PlayFabEditorPrefsSO.Save();
     }, (error) =>
     {
         if ((int)error.Error == 1246 || error.ErrorMessage.Contains("TwoFactor"))
         {
             // pop 2FA dialog
             PlayFabEditor.RaiseStateUpdate(PlayFabEditor.EdExStates.OnWarning, "This account requires 2-Factor Authentication.");
             activeState = PanelDisplayStates.TwoFactorPrompt;
         }
         else
         {
             PlayFabEditorHelper.SharedErrorCallback(error);
         }
     });
 }
        private static void OnRegisterClicked()
        {
            if (_userPass != _userPass2)
            {
                Debug.LogError("PlayFab developer account passwords must match.");
                return;
            }

            PlayFabEditorApi.RegisterAccount(new RegisterAccountRequest()
            {
                DeveloperToolProductName    = PlayFabEditorHelper.EDEX_NAME,
                DeveloperToolProductVersion = PlayFabEditorHelper.GetApiVersion(ApiCategory.editorextensions),
                Email      = _userEmail,
                Password   = _userPass,
                StudioName = _studio
            }, (result) =>
            {
                PlayFabEditorPrefsSO.Instance.DevAccountToken = result.DeveloperClientToken;
                PlayFabEditorPrefsSO.Instance.DevAccountEmail = _userEmail;

                PlayFabEditorDataService.RefreshStudiosList();

                PlayFabEditor.RaiseStateUpdate(PlayFabEditor.EdExStates.OnLogin);
                PlayFabEditorPrefsSO.Save();
            }, PlayFabEditorHelper.SharedErrorCallback);
        }
        private static void DisplayHelpMenu()
        {
            using (new UnityVertical(PlayFabEditorHelper.uiStyle.GetStyle("gpStyleGray1")))
            {
                using (new UnityHorizontal(PlayFabEditorHelper.uiStyle.GetStyle("gpStyleClear")))
                {
                    GUILayout.FlexibleSpace();
                    EditorGUILayout.LabelField("PlayFab Editor Extensions: " + PlayFabEditorHelper.GetApiVersion(ApiCategory.editorextensions), PlayFabEditorHelper.uiStyle.GetStyle("versionText"));
                    GUILayout.FlexibleSpace();
                }

                //TODO Add plugin upgrade option here (if available);
                if (ShowEdExUpgrade())
                {
                    using (new UnityHorizontal())
                    {
                        GUILayout.FlexibleSpace();
                        if (GUILayout.Button("UPGRADE EDEX", PlayFabEditorHelper.uiStyle.GetStyle("textButtonOr")))
                        {
                            UpgradeEdEx();
                        }
                        GUILayout.FlexibleSpace();
                    }
                }

                using (new UnityHorizontal())
                {
                    GUILayout.FlexibleSpace();
                    if (GUILayout.Button("VIEW DOCUMENTATION", PlayFabEditorHelper.uiStyle.GetStyle("textButton")))
                    {
                        Application.OpenURL(Strings.GitUrls.Build(ApiCategory.editorextensions).Replace(".git", ""));
                    }
                    GUILayout.FlexibleSpace();
                }

                using (new UnityHorizontal())
                {
                    GUILayout.FlexibleSpace();
                    if (GUILayout.Button("REPORT ISSUES", PlayFabEditorHelper.uiStyle.GetStyle("textButton")))
                    {
                        Application.OpenURL(Strings.GitUrls.Build(ApiCategory.editorextensions).Replace(".git", "") + "/issues");
                    }
                    GUILayout.FlexibleSpace();
                }

                using (new UnityHorizontal())
                {
                    GUILayout.FlexibleSpace();
                    if (GUILayout.Button("UNINSTALL ", PlayFabEditorHelper.uiStyle.GetStyle("textButton")))
                    {
                        RemoveEdEx();
                    }
                    GUILayout.FlexibleSpace();
                }
            }
        }
        internal static void MakeApiCall <TRequestType, TResultType>(string api, string apiEndpoint, TRequestType request, Action <TResultType> resultCallback, Action <EditorModels.PlayFabError> errorCallback) where TResultType : class
        {
            var url = apiEndpoint + api;
            var req = JsonWrapper.SerializeObject(request, PlayFabEditorUtil.ApiSerializerStrategy);
            //Set headers
            var headers = new Dictionary <string, string>
            {
                { "Content-Type", "application/json" },
                { "X-ReportErrorAsSuccess", "true" },
                { "X-PlayFabSDK", PlayFabEditorHelper.EDEX_NAME + "_" + PlayFabEditorHelper.GetApiVersion(ApiCategory.editorextensions) }
            };

            if (api.Contains("/Server/") || api.Contains("/Admin/"))
            {
                if (PlayFabEditorDataService.ActiveTitle == null || string.IsNullOrEmpty(PlayFabEditorDataService.ActiveTitle.SecretKey))
                {
                    PlayFabEditorDataService.RefreshStudiosList();
                    return;
                }

                headers.Add("X-SecretKey", PlayFabEditorDataService.ActiveTitle.SecretKey);
            }

            //Encode Payload
            var payload = System.Text.Encoding.UTF8.GetBytes(req.Trim());

#if UNITY_2018_2_OR_NEWER
            var www = new UnityWebRequest(url)
            {
                uploadHandler   = new UploadHandlerRaw(payload),
                downloadHandler = new DownloadHandlerBuffer(),
                method          = "POST"
            };

            foreach (var header in headers)
            {
                if (!string.IsNullOrEmpty(header.Key) && !string.IsNullOrEmpty(header.Value))
                {
                    www.SetRequestHeader(header.Key, header.Value);
                }
                else
                {
                    UnityEngine.Debug.LogWarning("Null header");
                }
            }


            PlayFabEditor.RaiseStateUpdate(PlayFabEditor.EdExStates.OnHttpReq, api, PlayFabEditorHelper.MSG_SPIN_BLOCK);
            EditorCoroutine.Start(Post(www, (response) => { OnWwwSuccess(api, resultCallback, errorCallback, response); }, (error) => { OnWwwError(errorCallback, error); }), www);
#else
            var www = new WWW(url, payload, headers);
            PlayFabEditor.RaiseStateUpdate(PlayFabEditor.EdExStates.OnHttpReq, api, PlayFabEditorHelper.MSG_SPIN_BLOCK);
            EditorCoroutine.Start(Post(www, (response) => { OnWwwSuccess(api, resultCallback, errorCallback, response); }, (error) => { OnWwwError(errorCallback, error); }), www);
#endif
        }
 private static void OnContinueButtonClicked()
 {
     PlayFabEditorApi.Login(new LoginRequest()
     {
         DeveloperToolProductName    = PlayFabEditorHelper.EDEX_NAME,
         DeveloperToolProductVersion = PlayFabEditorHelper.GetApiVersion(ApiCategory.editorextensions),
         TwoFactorAuth = _2FaCode,
         Email         = _userEmail,
         Password      = _userPass
     }, (result) =>
     {
         PlayFabEditorPrefsSO.Instance.DevAccountToken = result.DeveloperClientToken;
         PlayFabEditorPrefsSO.Instance.DevAccountEmail = _userEmail;
         PlayFabEditorDataService.RefreshStudiosList();
         PlayFabEditor.RaiseStateUpdate(PlayFabEditor.EdExStates.OnLogin);
         PlayFabEditorPrefsSO.Save();
     }, PlayFabEditorHelper.SharedErrorCallback);
 }
Exemplo n.º 7
0
 public static void CheckIfInstalledAndVersion()
 {
     installedSdkVersion = PlayFabEditorHelper.GetApiVersion(ApiCategory.sdk);
     //Debug.Log($"installedSdkVersion: {installedSdkVersion}");
     isInstalled = installedSdkVersion != null;
 }