public static void RemoveEdEx(bool clearPrefs = true, bool prompt = true)
        {
            if (prompt)
            {
                if (!EditorUtility.DisplayDialog("Confirm Editor Extensions Removal", "This action will remove PlayFab Editor Extensions from the current project.", "Confirm", "Cancel"))
                {
                    return;
                }
            }

            try
            {
                PlayFabEditor.window.Close();
                var edExRoot = new DirectoryInfo(PlayFabEditorHelper.EDITOR_ROOT);

                FileUtil.DeleteFileOrDirectory(edExRoot.Parent.FullName);

                if (clearPrefs)
                {
                    PlayFabEditorDataService.RemoveEditorPrefs();
                }


                AssetDatabase.Refresh();
            }
            catch (Exception ex)
            {
                RaiseStateUpdate(EdExStates.OnError, ex.Message);
            }
        }
Beispiel #2
0
        private static void OnContinueButtonClicked()
        {
            PlayFabEditorApi.Login(new LoginRequest()
            {
                DeveloperToolProductName    = PlayFabEditorHelper.EDEX_NAME,
                DeveloperToolProductVersion = PlayFabEditorHelper.EDEX_VERSION,
                TwoFactorAuth = _2faCode,
                Email         = _userEmail,
                Password      = _userPass
            }, (result) =>
            {
                PlayFabEditorDataService.accountDetails.devToken = result.DeveloperClientToken;
                PlayFabEditorDataService.accountDetails.email    = _userEmail;


                PlayFabEditorApi.GetStudios(new GetStudiosRequest(), (getStudioResult) =>
                {
                    PlayFabEditorDataService.accountDetails.studios = getStudioResult.Studios.ToList();
                    PlayFabEditorDataService.SaveAccountDetails();
                }, PlayFabEditorHelper.SharedErrorCallback);

                PlayFabEditor.RaiseStateUpdate(PlayFabEditor.EdExStates.OnLogin);
                PlayFabEditorDataService.SaveAccountDetails();
                PlayFabEditorMenu._menuState = PlayFabEditorMenu.MenuStates.Sdks;
            }, PlayFabEditorHelper.SharedErrorCallback);
        }
Beispiel #3
0
        private static void OnRegisterClicked()
        {
            if (_userPass != _userPass2)
            {
                Debug.LogError("PlayFab developer account passwords must match.");
                return;
            }


            PlayFabEditorApi.RegisterAccouint(new RegisterAccountRequest()
            {
                DeveloperToolProductName    = PlayFabEditorHelper.EDEX_NAME,
                DeveloperToolProductVersion = PlayFabEditorHelper.EDEX_VERSION,
                Email      = _userEmail,
                Password   = _userPass,
                StudioName = _studio
            }, (result) =>
            {
                PlayFabEditorDataService.accountDetails.devToken = result.DeveloperClientToken;
                PlayFabEditorDataService.accountDetails.email    = _userEmail;

                PlayFabEditorApi.GetStudios(new GetStudiosRequest(), (getStudioResult) =>
                {
                    PlayFabEditorDataService.accountDetails.studios = getStudioResult.Studios.ToList();
                    PlayFabEditorDataService.SaveAccountDetails();
                }, PlayFabEditorHelper.SharedErrorCallback);

                PlayFabEditor.RaiseStateUpdate(PlayFabEditor.EdExStates.OnLogin);
                PlayFabEditorDataService.SaveAccountDetails();
                PlayFabEditorMenu._menuState = PlayFabEditorMenu.MenuStates.Sdks;
            }, PlayFabEditorHelper.SharedErrorCallback);
        }
Beispiel #4
0
        public static void Logout()
        {
            PlayFabEditor.RaiseStateUpdate(PlayFabEditor.EdExStates.OnLogout);

            PlayFabEditorApi.Logout(new LogoutRequest()
            {
                DeveloperClientToken = PlayFabEditorDataService.accountDetails.devToken
            }, null, PlayFabEditorHelper.SharedErrorCallback);

            _userPass = string.Empty;

            _userPass2 = string.Empty;


            activeState = PanelDisplayStates.Login;

            PlayFabEditorDataService.accountDetails.studios.Clear();

            PlayFabEditorDataService.accountDetails.devToken = string.Empty;

            PlayFabEditorDataService.SaveAccountDetails();

            PlayFabEditorDataService.envDetails.titleData.Clear();
            PlayFabEditorDataService.SaveEnvDetails();
        }
Beispiel #5
0
        public static void OnSettingsClicked()
        {
            _menuState = MenuStates.Settings;

            PlayFabEditor.RaiseStateUpdate(PlayFabEditor.EdExStates.OnMenuItemClicked, MenuStates.Settings.ToString());
            PlayFabEditorDataService.editorSettings.currentMainMenu = (int)MenuStates.Settings;
            PlayFabEditorDataService.SaveEditorSettings();
        }
        public static void After()
        {
            if (PlayFabEditorDataService.envDetails.isAdminApiEnabled && !buildTargets.Contains(PlayFabEditorHelper.ADMIN_API))
            {
                var str = AddToBuildTarget(buildTargets, PlayFabEditorHelper.ADMIN_API);
                PlayerSettings.SetScriptingDefineSymbolsForGroup(EditorUserBuildSettings.selectedBuildTargetGroup, str);
                PlayFabEditorDataService.SaveEnvDetails();
            }
            else if (!PlayFabEditorDataService.envDetails.isAdminApiEnabled && buildTargets.Contains(PlayFabEditorHelper.ADMIN_API))
            {
                var str = RemoveToBuildTarget(buildTargets, PlayFabEditorHelper.ADMIN_API);
                PlayerSettings.SetScriptingDefineSymbolsForGroup(EditorUserBuildSettings.selectedBuildTargetGroup, str);
                PlayFabEditorDataService.SaveEnvDetails();
            }

            if (PlayFabEditorDataService.envDetails.isServerApiEnabled && !buildTargets.Contains(PlayFabEditorHelper.SERVER_API))
            {
                var str = AddToBuildTarget(buildTargets, PlayFabEditorHelper.SERVER_API);
                PlayerSettings.SetScriptingDefineSymbolsForGroup(EditorUserBuildSettings.selectedBuildTargetGroup, str);
                PlayFabEditorDataService.SaveEnvDetails();
            }
            else if (!PlayFabEditorDataService.envDetails.isServerApiEnabled && buildTargets.Contains(PlayFabEditorHelper.SERVER_API))
            {
                var str = RemoveToBuildTarget(buildTargets, PlayFabEditorHelper.SERVER_API);
                PlayerSettings.SetScriptingDefineSymbolsForGroup(EditorUserBuildSettings.selectedBuildTargetGroup, str);
                PlayFabEditorDataService.SaveEnvDetails();
            }

            if (PlayFabEditorDataService.envDetails.isDebugRequestTimesEnabled && !buildTargets.Contains(PlayFabEditorHelper.DEBUG_REQUEST_TIMING))
            {
                var str = AddToBuildTarget(buildTargets, PlayFabEditorHelper.DEBUG_REQUEST_TIMING);
                PlayerSettings.SetScriptingDefineSymbolsForGroup(EditorUserBuildSettings.selectedBuildTargetGroup, str);
                PlayFabEditorDataService.SaveEnvDetails();
            }
            else if (!PlayFabEditorDataService.envDetails.isDebugRequestTimesEnabled && buildTargets.Contains(PlayFabEditorHelper.DEBUG_REQUEST_TIMING))
            {
                var str = RemoveToBuildTarget(buildTargets, PlayFabEditorHelper.DEBUG_REQUEST_TIMING);
                PlayerSettings.SetScriptingDefineSymbolsForGroup(EditorUserBuildSettings.selectedBuildTargetGroup, str);
                PlayFabEditorDataService.SaveEnvDetails();
            }

            if (!PlayFabEditorDataService.envDetails.isClientApiEnabled && !buildTargets.Contains(PlayFabEditorHelper.CLIENT_API))
            {
                Debug.Log(PlayFabEditorHelper.CLIENT_API + ":" + buildTargets.Contains(PlayFabEditorHelper.CLIENT_API));
                var str = AddToBuildTarget(buildTargets, PlayFabEditorHelper.CLIENT_API);
                PlayerSettings.SetScriptingDefineSymbolsForGroup(EditorUserBuildSettings.selectedBuildTargetGroup, str);
                PlayFabEditorDataService.SaveEnvDetails();
            }
            else if (PlayFabEditorDataService.envDetails.isClientApiEnabled && buildTargets.Contains(PlayFabEditorHelper.CLIENT_API))
            {
                Debug.Log(PlayFabEditorHelper.CLIENT_API + "- Removed");
                var str = RemoveToBuildTarget(buildTargets, PlayFabEditorHelper.CLIENT_API);
                PlayerSettings.SetScriptingDefineSymbolsForGroup(EditorUserBuildSettings.selectedBuildTargetGroup, str);
                PlayFabEditorDataService.SaveEnvDetails();
            }
        }
        private static void OnSaveSettings()
        {
            // make assessments on the override at studio positon 0
            if (PlayFabEditorSDKTools.IsInstalled && PlayFabEditorSDKTools.isSdkSupported)
            {
                if (_foundUnknownTitleId || _selectedStudioIndex == 0)
                {
                    if (PlayFabEditorDataService.envDetails.selectedTitleId != _TitleId)
                    {
                        PlayFabEditorDataService.envDetails.titleData.Clear();
                        if (PlayFabEditorDataMenu.tdViewer != null)
                        {
                            PlayFabEditorDataMenu.tdViewer.items.Clear();
                        }
                    }

                    PlayFabEditorDataService.envDetails.selectedTitleId = _TitleId;
                }
                else
                {
                    // if we switched titles clear titledata
                    if (PlayFabEditorDataService.envDetails.selectedTitleId != GetSelectedTitleIdFromOptions())
                    {
                        PlayFabEditorDataService.envDetails.titleData.Clear();
                        if (PlayFabEditorDataMenu.tdViewer != null)
                        {
                            PlayFabEditorDataMenu.tdViewer.items.Clear();
                        }
                    }

                    PlayFabEditorDataService.envDetails.selectedTitleId = GetSelectedTitleIdFromOptions();
                }


                PlayFabEditorDataService.envDetails.selectedStudio = studioOptions[_selectedStudioIndex];


                #if ENABLE_PLAYFABADMIN_API || ENABLE_PLAYFABSERVER_API
                PlayFabEditorDataService.envDetails.developerSecretKey = _DeveloperSecretKey;
                #endif

                PlayFabEditorDataService.envDetails.compressApiData = _CompressApiData;
                PlayFabEditorDataService.envDetails.keepAlive       = _KeepAlive;
                PlayFabEditorDataService.envDetails.webRequestType  = _RequestType;
                PlayFabEditorDataService.envDetails.timeOut         = _RequestTimeOut;

                PlayFabEditorDataService.SaveEnvDetails();

                PlayFabEditor.RaiseStateUpdate(PlayFabEditor.EdExStates.OnSuccess);
            }
            else
            {
                PlayFabEditor.RaiseStateUpdate(PlayFabEditor.EdExStates.OnError, "SDK is unsupported or not installed");
            }
        }
        public static void ImportLatestSDK()
        {
            PlayFabEditorHttp.MakeDownloadCall("https://api.playfab.com/sdks/download/unity-via-edex", (fileName) =>
            {
                Debug.Log("PlayFab SDK Install: Complete");
                AssetDatabase.ImportPackage(fileName, false);

                PlayFabEditorDataService.envDetails.sdkPath = PlayFabEditorHelper.DEFAULT_SDK_LOCATION;
                PlayFabEditorDataService.SaveEnvDetails();
            });
        }
Beispiel #9
0
        void OnDisable()
        {
            // clean up objects:
            PlayFabEditorDataService.editorSettings.isEdExShown = false;
            PlayFabEditorDataService.SaveEditorSettings();

            if (IsEventHandlerRegistered(StateUpdateHandler))
            {
                EdExStateUpdate -= StateUpdateHandler;
            }
        }
 public static void RefreshStudiosList()
 {
     _isFetchingStudios = true;
     PlayFabEditorApi.GetStudios(new PlayFab.Editor.EditorModels.GetStudiosRequest(), (getStudioResult) =>
     {
         _isFetchingStudios = false;
         _isSettingsSet     = false;
         studioOptions      = null;
         PlayFabEditorDataService.accountDetails.studios = getStudioResult.Studios.ToList();
         PlayFabEditorDataService.SaveAccountDetails();
     }, PlayFabEditorHelper.SharedErrorCallback);
 }
Beispiel #11
0
        static IEnumerator OpenPlayServices()
        {
            yield return(new WaitForSeconds(1f));

            if (!Application.isPlaying)
            {
                PlayFabServices();
            }

            PlayFabEditorDataService.editorSettings.isEdExShown = true;
            PlayFabEditorDataService.SaveEditorSettings();
        }
Beispiel #12
0
        public static void OnLogoutClicked()
        {
            _menuState = MenuStates.Logout;

            PlayFabEditor.RaiseStateUpdate(PlayFabEditor.EdExStates.OnMenuItemClicked, MenuStates.Logout.ToString());

            PlayFabEditorAuthenticate.Logout();


            _menuState = MenuStates.Sdks;

            PlayFabEditorDataService.editorSettings.currentMainMenu = (int)MenuStates.Sdks;
            PlayFabEditorDataService.SaveEditorSettings();
        }
Beispiel #13
0
        static PlayFabEditorHelper()
        {
            // scan for changes to the editor folder / structure.
            if (uiStyle == null)
            {
                string[] rootFiles     = new string[0];
                bool     relocatedEdEx = false;

                try
                {
                    EDEX_ROOT = PlayFabEditorDataService.envDetails.edexPath ?? EDEX_ROOT;
                    rootFiles = Directory.GetDirectories(EDEX_ROOT);

                    uiStyle = GetUiStyle();
                }
                catch
                {
                    if (rootFiles.Length == 0)
                    {
                        // this probably means the editor folder was moved.
                        //see if we can locate the moved root
                        // and reload the assets

                        var movedRootFiles = Directory.GetFiles(Application.dataPath, PLAYFAB_EDEX_MAINFILE, SearchOption.AllDirectories);
                        if (movedRootFiles.Length > 0)
                        {
                            relocatedEdEx = true;
                            EDEX_ROOT     = movedRootFiles[0].Substring(0, movedRootFiles[0].IndexOf(PLAYFAB_EDEX_MAINFILE) - 1);
                            PlayFabEditorDataService.envDetails.edexPath = EDEX_ROOT;
                            PlayFabEditorDataService.SaveEnvDetails();

                            uiStyle = GetUiStyle();
                        }
                    }
                }
                finally
                {
                    if (relocatedEdEx && rootFiles.Length == 0)
                    {
                        Debug.Log(string.Format("Found new EdEx root: {0}", EDEX_ROOT));
                    }
                    else if (rootFiles.Length == 0)
                    {
                        Debug.Log("Could not relocate the PlayFab Editor Extension");
                        EDEX_ROOT = string.Empty;
                    }
                }
            }
        }
        public void RefreshRecords()
        {
            Action <PlayFab.Editor.EditorModels.GetTitleDataResult> cb = (result) => {
                items.Clear();
                showSave = false;
                foreach (var kvp in result.Data)
                {
                    items.Add(new KvpItem(kvp.Key, kvp.Value));
                }

                PlayFabEditorDataService.envDetails.titleInternalData = result.Data;
                PlayFabEditorDataService.SaveEnvDetails();
            };

            PlayFabEditorApi.GetTitleInternalData(cb, PlayFabEditorHelper.SharedErrorCallback);
        }
Beispiel #15
0
        public void RefreshRecords()
        {
            //BaseUiAnimationController.StartAlphaFade(1, 0, listDisplay);

            Action <PlayFab.Editor.EditorModels.GetTitleDataResult> cb = (result) => {
                items.Clear();
                showSave = false;
                foreach (var kvp in result.Data)
                {
                    items.Add(new KvpItem(kvp.Key, kvp.Value));
                }

                PlayFabEditorDataService.envDetails.titleData = result.Data;
                PlayFabEditorDataService.SaveEnvDetails();
            };

            PlayFabEditorApi.GetTitleData(cb, PlayFabEditorHelper.SharedErrorCallback);
        }
        private static void GetLatestSdkVersion()
        {
            //TODO start back here
            DateTime threshold = PlayFabEditorDataService.editorSettings.lastSdkVersionCheck != DateTime.MinValue ? PlayFabEditorDataService.editorSettings.lastSdkVersionCheck.AddHours(1) : DateTime.MinValue;

            if (DateTime.Today > threshold)
            {
                PlayFabEditorHttp.MakeGitHubApiCall("https://api.github.com/repos/PlayFab/UnitySDK/git/refs/tags", (version) =>
                {
                    latestSdkVersion = version ?? "Unknown";
                    PlayFabEditorDataService.editorSettings.lastSdkVersionCheck = DateTime.UtcNow;
                    PlayFabEditorDataService.editorSettings.latestSdkVersion    = latestSdkVersion;
                    PlayFabEditorDataService.SaveEditorSettings();
                });
            }
            else
            {
                latestSdkVersion = PlayFabEditorDataService.editorSettings.latestSdkVersion;
            }
        }
        public static void GetCloudScriptRevision()
        {
            // empty request object gets latest versions
            PlayFabEditorApi.GetCloudScriptRevision(new EditorModels.GetCloudScriptRevisionRequest(), (GetCloudScriptRevisionResult result) => {
                var csPath = PlayFabEditorHelper.CLOUDSCRIPT_PATH;

                try
                {
                    System.IO.File.WriteAllText(csPath, result.Files.First().FileContents);
                    Debug.Log("CloudScript uploaded successfully!");
                    PlayFabEditorDataService.envDetails.localCloudScriptPath = csPath;
                    PlayFabEditorDataService.SaveEnvDetails();
                }
                catch (Exception ex)
                {
                    PlayFabEditor.RaiseStateUpdate(PlayFabEditor.EdExStates.OnError, ex.Message);
                    return;
                }
            }, PlayFabEditorHelper.SharedErrorCallback);
        }
        public static void SelectLocalFile()
        {
            string starterPath     = File.Exists(PlayFabEditorDataService.envDetails.localCloudScriptPath) ? Application.dataPath : PlayFabEditorDataService.envDetails.localCloudScriptPath;
            string cloudScriptPath = string.Empty;

            try
            {
                cloudScriptPath = EditorUtility.OpenFilePanel("Select your Cloud Script file", starterPath, "js");
            }
            catch (Exception ex)
            {
                PlayFabEditor.RaiseStateUpdate(PlayFabEditor.EdExStates.OnError, ex.Message);
            }

            if (!string.IsNullOrEmpty(cloudScriptPath))
            {
                PlayFabEditorDataService.envDetails.localCloudScriptPath = cloudScriptPath;
                PlayFabEditorDataService.SaveEnvDetails();
            }
        }
        public static void SetSettingsProperties()
        {
            if (PlayFabEditorSDKTools.IsInstalled && !_isSettingsSet)
            {
                if (!string.IsNullOrEmpty(PlayFabEditorDataService.envDetails.selectedTitleId))
                {
                    // exists in user's titles?
                    if (!PlayFabEditorDataService.DoesTitleExistInStudios(PlayFabEditorDataService.envDetails.selectedTitleId))
                    {
                        string msg = string.Format("A title id ({0}) that does not belong to one of your studios has been selected. You can update this value on the PROJECT SETTINGS tab within the PlayFab Editor Extensions.", PlayFabEditorDataService.envDetails.selectedTitleId);
                        PlayFabEditor.RaiseStateUpdate(PlayFabEditor.EdExStates.OnWarning, msg);
                        _foundUnknownTitleId     = true;
                        _prevSelectedStudioIndex = 0;
                        _selectedStudioIndex     = 0;

                        _TitleId = PlayFabEditorDataService.envDetails.selectedTitleId;

                        #if ENABLE_PLAYFABADMIN_API || ENABLE_PLAYFABSERVER_API
                        _DeveloperSecretKey = PlayFabEditorDataService.envDetails.developerSecretKey;
                        #endif
                    }
                    else
                    {
                        _foundUnknownTitleId = false;
                    }
                }

                if (studioOptions == null || (studioOptions.Length == 0 && PlayFabEditorDataService.accountDetails.studios.Count > 0))
                {
                    BuildDropDownLists();
                }

                _RequestTimeOut = PlayFabEditorDataService.envDetails.timeOut;
                _KeepAlive      = PlayFabEditorDataService.envDetails.keepAlive;

                _isSettingsSet = true;
            }
        }
Beispiel #20
0
        private static void OnLoginButtonClicked()
        {
            PlayFabEditorApi.Login(new LoginRequest()
            {
                DeveloperToolProductName    = PlayFabEditorHelper.EDEX_NAME,
                DeveloperToolProductVersion = PlayFabEditorHelper.EDEX_VERSION,
                Email    = _userEmail,
                Password = _userPass
            }, (result) =>
            {
                PlayFabEditorDataService.accountDetails.devToken = result.DeveloperClientToken;
                PlayFabEditorDataService.accountDetails.email    = _userEmail;

                PlayFabEditorApi.GetStudios(new GetStudiosRequest(), (getStudioResult) =>
                {
                    PlayFabEditorDataService.accountDetails.studios = getStudioResult.Studios.ToList();
                    PlayFabEditorDataService.SaveAccountDetails();
                }, PlayFabEditorHelper.SharedErrorCallback);

                PlayFabEditor.RaiseStateUpdate(PlayFabEditor.EdExStates.OnLogin);
                PlayFabEditorDataService.SaveAccountDetails();
                PlayFabEditorMenu._menuState = PlayFabEditorMenu.MenuStates.Sdks;
            }, (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);
                }
            });
        }
        public static void DrawToolsPanel()
        {
            scrollPos   = GUILayout.BeginScrollView(scrollPos, PlayFabEditorHelper.uiStyle.GetStyle("gpStyleGray1"));
            buttonWidth = EditorGUIUtility.currentViewWidth > 400 ? EditorGUIUtility.currentViewWidth / 2 : 200;


            GUILayout.BeginHorizontal(PlayFabEditorHelper.uiStyle.GetStyle("gpStyleClear"));
            GUILayout.Label("CLOUD SCRIPT:", PlayFabEditorHelper.uiStyle.GetStyle("labelStyle"));
            GUILayout.Space(10);
            if (GUILayout.Button("IMPORT", PlayFabEditorHelper.uiStyle.GetStyle("textButton"), GUILayout.MinHeight(30)))
            {
                ImportCloudScript();
            }
            GUILayout.Space(10);
            if (File.Exists(PlayFabEditorDataService.envDetails.localCloudScriptPath))
            {
                if (GUILayout.Button("REMOVE", PlayFabEditorHelper.uiStyle.GetStyle("textButton"), GUILayout.MinHeight(30)))
                {
                    PlayFabEditorDataService.envDetails.localCloudScriptPath = string.Empty;
                    PlayFabEditorDataService.SaveEnvDetails();
                }
                GUILayout.Space(10);
                if (GUILayout.Button("EDIT", PlayFabEditorHelper.uiStyle.GetStyle("textButton"), GUILayout.MinHeight(30)))
                {
                    EditorUtility.OpenWithDefaultApp(PlayFabEditorDataService.envDetails.localCloudScriptPath);
                }
            }
            GUILayout.EndHorizontal();


            if (File.Exists(PlayFabEditorDataService.envDetails.localCloudScriptPath))
            {
                var path      = File.Exists(PlayFabEditorDataService.envDetails.localCloudScriptPath) ? PlayFabEditorDataService.envDetails.localCloudScriptPath : PlayFabEditorHelper.CLOUDSCRIPT_PATH;
                var shortPath = "..." + path.Substring(path.LastIndexOf('/'));

                GUILayout.BeginHorizontal(PlayFabEditorHelper.uiStyle.GetStyle("gpStyleClear"));

                GUILayout.FlexibleSpace();

                if (GUILayout.Button(shortPath, PlayFabEditorHelper.uiStyle.GetStyle("textButton"), GUILayout.MinWidth(110), GUILayout.MinHeight(20)))
                {
                    EditorUtility.RevealInFinder(path);
                }
//                            GUILayout.Space(10);
//                            if (GUILayout.Button("EDIT LOCALLY", PlayFabEditorHelper.uiStyle.GetStyle("textButton"), GUILayout.MinWidth(90), GUILayout.MinHeight(20)))
//                            {
//                                EditorUtility.OpenWithDefaultApp(path);
//                            }
                GUILayout.FlexibleSpace();

                GUILayout.EndHorizontal();

                GUILayout.BeginHorizontal(PlayFabEditorHelper.uiStyle.GetStyle("gpStyleClear"));
                GUILayout.FlexibleSpace();
                if (GUILayout.Button("SAVE TO PLAYFAB", PlayFabEditorHelper.uiStyle.GetStyle("Button"), GUILayout.MinHeight(32), GUILayout.Width(buttonWidth)))
                {
                    if (EditorUtility.DisplayDialog("Deployment Confirmation", "This action will upload your local Cloud Script changes to PlayFab?", "Continue", "Cancel"))
                    {
                        BeginCloudScriptUpload();
                    }
                }
                GUILayout.FlexibleSpace();
                GUILayout.EndHorizontal();
            }
            else
            {
                GUILayout.BeginHorizontal(PlayFabEditorHelper.uiStyle.GetStyle("gpStyleClear"));
                GUILayout.FlexibleSpace();
                GUILayout.Label("No Cloud Script files added. Import your file to get started.", PlayFabEditorHelper.uiStyle.GetStyle("orTxt"));
                GUILayout.FlexibleSpace();
                GUILayout.EndHorizontal();
            }

            GUILayout.EndScrollView();
        }
Beispiel #22
0
        void OnGUI()
        {
            try
            {
                GUI.skin = PlayFabEditorHelper.uiStyle;

                GUILayout.BeginVertical();

                //Run all updaters prior to drawing;
                PlayFabEditorSettings.Update();

                PlayFabEditorHeader.DrawHeader();


                GUI.enabled = blockingRequests.Count > 0 || EditorApplication.isCompiling ? false : true;

                if (PlayFabEditorDataService.isDataLoaded)
                {
                    if (PlayFabEditorAuthenticate.IsAuthenticated())
                    {
                        //Try catching to avoid Draw errors that do not actually impact the functionality
                        try
                        {
                            PlayFabEditorMenu.DrawMenu();

                            switch (PlayFabEditorMenu._menuState)
                            {
                            case PlayFabEditorMenu.MenuStates.Sdks:
                                PlayFabEditorSDKTools.DrawSdkPanel();
                                break;

                            case PlayFabEditorMenu.MenuStates.Settings:
                                PlayFabEditorSettings.DrawSettingsPanel();
                                PlayFabEditorSettings.After();
                                break;

                            case PlayFabEditorMenu.MenuStates.Help:
                                PlayFabEditorHelpMenu.DrawHelpPanel();
                                break;

                            case PlayFabEditorMenu.MenuStates.Data:
                                PlayFabEditorDataMenu.DrawDataPanel();
                                break;

                            default:
                                break;
                            }
                        }
                        catch //(Exception ex)
                        {
                            //RaiseStateUpdate(EdExStates.OnError, ex.Message);
                        }
                    }
                    else
                    {
                        PlayFabEditorAuthenticate.DrawAuthPanels();
                    }

                    GUILayout.BeginVertical(PlayFabEditorHelper.uiStyle.GetStyle("gpStyleGray1"), GUILayout.ExpandHeight(true), GUILayout.ExpandWidth(true));
                    GUILayout.FlexibleSpace();
                    GUILayout.EndVertical();


                    // help tag at the bottom of the help menu.
                    if (PlayFabEditorMenu._menuState == PlayFabEditorMenu.MenuStates.Help)
                    {
                        GUILayout.BeginVertical(PlayFabEditorHelper.uiStyle.GetStyle("gpStyleGray1"));
                        GUILayout.BeginHorizontal(PlayFabEditorHelper.uiStyle.GetStyle("gpStyleClear"));
                        GUILayout.FlexibleSpace();
                        EditorGUILayout.LabelField(string.Format("PlayFab Editor Extensions: {0}", PlayFabEditorHelper.EDEX_VERSION), PlayFabEditorHelper.uiStyle.GetStyle("versionText"));
                        GUILayout.FlexibleSpace();
                        GUILayout.EndHorizontal();

                        //TODO Add plugin upgrade option here (if available);


                        GUILayout.BeginHorizontal();
                        GUILayout.FlexibleSpace();
                        if (GUILayout.Button("VIEW DOCUMENTATION", PlayFabEditorHelper.uiStyle.GetStyle("textButton")))
                        {
                            Application.OpenURL("https://github.com/PlayFab/UnityEditorExtensions");
                        }
                        GUILayout.FlexibleSpace();
                        GUILayout.EndHorizontal();

                        GUILayout.BeginHorizontal();
                        GUILayout.FlexibleSpace();
                        if (GUILayout.Button("REPORT ISSUES", PlayFabEditorHelper.uiStyle.GetStyle("textButton")))
                        {
                            Application.OpenURL("https://github.com/PlayFab/UnityEditorExtensions/issues");
                        }
                        GUILayout.FlexibleSpace();
                        GUILayout.EndHorizontal();

                        if (!string.IsNullOrEmpty(PlayFabEditorHelper.EDITOR_ROOT))
                        {
                            GUILayout.BeginHorizontal();
                            GUILayout.FlexibleSpace();
                            if (GUILayout.Button("UNINSTALL ", PlayFabEditorHelper.uiStyle.GetStyle("textButton")))
                            {
                                if (EditorUtility.DisplayDialog("Confirm Editor Extensions Removal", "This action will remove PlayFab Editor Extensions from the current project.", "Confirm", "Cancel"))
                                {
                                    try
                                    {
                                        PlayFabEditor.window.Close();
                                        var edExRoot = new DirectoryInfo(PlayFabEditorHelper.EDITOR_ROOT);

                                        FileUtil.DeleteFileOrDirectory(edExRoot.Parent.FullName);
                                        PlayFabEditorDataService.RemoveEditorPrefs();


                                        AssetDatabase.Refresh();
                                    }
                                    catch (Exception ex)
                                    {
                                        RaiseStateUpdate(EdExStates.OnError, ex.Message);
                                        PlayFabServices();
                                    }
                                }
                            }
                            GUILayout.FlexibleSpace();
                            GUILayout.EndHorizontal();
                            GUILayout.EndVertical();
                        }
                    }

                    GUILayout.EndVertical();

                    PruneBlockingRequests();

                    try
                    {
                        Repaint();
                    }
                    catch //(Exception ex)
                    {
                        //RaiseStateUpdate(EdExStates.OnError, ex.Message);
                    }
                }
            }
            catch //(Exception ex)
            {
                //RaiseStateUpdate(EdExStates.OnError, ex.Message);
            }
        }
        public static void DrawSdkPanel()
        {
            if (!isInitialized)
            {
                //SDK is installed.
                isInstalled = IsInstalled;
                CheckSdkVersion();
                isInitialized = true;
                GetLatestSdkVersion();
                sdkFolder = FindSdkAsset();

                if (sdkFolder != null)
                {
                    PlayFabEditorDataService.envDetails.sdkPath = AssetDatabase.GetAssetPath(sdkFolder);
                    PlayFabEditorDataService.SaveEnvDetails();
                }
            }


            if (isInstalled)
            {
                // cant find the sdk, but we suspect its in the project (either in-full or in-part)
                isObjectFieldActive = sdkFolder == null ? true : false;

                if (_previoussSdkFolderPath != sdkFolder)
                {
                    // something changed, better save the result.
                    _previoussSdkFolderPath = sdkFolder;

                    PlayFabEditorDataService.envDetails.sdkPath = (AssetDatabase.GetAssetPath(sdkFolder));
                    PlayFabEditorDataService.SaveEnvDetails();

                    isObjectFieldActive = false;
                }

                GUIStyle labelStyle = new GUIStyle(PlayFabEditorHelper.uiStyle.GetStyle("titleLabel"));


                GUILayout.BeginVertical(PlayFabEditorHelper.uiStyle.GetStyle("gpStyleGray1"));
                GUILayout.Label(string.Format("SDK {0} is installed", string.IsNullOrEmpty(installedSdkVersion) ? "Unknown" : installedSdkVersion), labelStyle, GUILayout.MinWidth(EditorGUIUtility.currentViewWidth));

                if (!isObjectFieldActive)
                {
                    GUI.enabled = false;
                }
                else
                {
                    GUILayout.Label("An SDK was detected, but we were unable to find the directory. Drag-and-drop the top-level PlayFab SDK folder below.", PlayFabEditorHelper.uiStyle.GetStyle("orTxt"));
                }

                GUILayout.BeginHorizontal(PlayFabEditorHelper.uiStyle.GetStyle("gpStyleClear"));
                GUILayout.FlexibleSpace();
                sdkFolder = EditorGUILayout.ObjectField(sdkFolder, typeof(UnityEngine.Object), false, GUILayout.MaxWidth(200));
                GUILayout.FlexibleSpace();
                GUILayout.EndHorizontal();

                if (!isObjectFieldActive)
                {
                    // this is a hack to prevent our "block while loading technique" from breaking up at this point.
                    GUI.enabled = EditorApplication.isCompiling || PlayFabEditor.blockingRequests.Count > 0 ? false : true;
                }

                if (isSdkSupported == true && sdkFolder != null)
                {
                    GUILayout.BeginHorizontal(PlayFabEditorHelper.uiStyle.GetStyle("gpStyleClear"));

                    GUILayout.FlexibleSpace();

                    if (GUILayout.Button("REMOVE SDK", PlayFabEditorHelper.uiStyle.GetStyle("textButton"), GUILayout.MinHeight(32), GUILayout.MinWidth(200)))
                    {
                        RemoveSDK();
                    }

                    GUILayout.FlexibleSpace();
                    GUILayout.EndHorizontal();
                }

                GUILayout.EndVertical();

                if (sdkFolder != null)
                {
                    //TODO START BACK HERE...

                    GUILayout.BeginVertical(PlayFabEditorHelper.uiStyle.GetStyle("gpStyleGray1"));
                    isSdkSupported = false;
                    string[] versionNumber = !string.IsNullOrEmpty(installedSdkVersion) ? installedSdkVersion.Split('.') : new string[0];

                    int numerical = 0;
                    if (string.IsNullOrEmpty(installedSdkVersion) || versionNumber == null || versionNumber.Length == 0 || (versionNumber.Length > 0 && int.TryParse(versionNumber[0], out numerical) && numerical < 2))
                    {
                        //older version of the SDK
                        GUILayout.BeginHorizontal(PlayFabEditorHelper.uiStyle.GetStyle("gpStyleClear"));
                        GUILayout.Label("Most of the Editor Extensions depend on SDK versions >2.0. Consider upgrading to the get most features.", PlayFabEditorHelper.uiStyle.GetStyle("orTxt"));
                        GUILayout.EndHorizontal();

                        GUILayout.BeginHorizontal(PlayFabEditorHelper.uiStyle.GetStyle("gpStyleClear"));
                        GUILayout.FlexibleSpace();
                        if (GUILayout.Button("READ THE UPGRADE GUIDE", PlayFabEditorHelper.uiStyle.GetStyle("textButton"), GUILayout.MinHeight(32)))
                        {
                            Application.OpenURL("https://github.com/PlayFab/UnitySDK/blob/master/UPGRADE.md");
                        }
                        GUILayout.FlexibleSpace();
                        GUILayout.EndHorizontal();
                    }
                    else if (numerical >= 2)
                    {
                        isSdkSupported = true;
                    }

                    GUILayout.BeginHorizontal(PlayFabEditorHelper.uiStyle.GetStyle("gpStyleClear"));

                    if (ShowSDKUpgrade() && isSdkSupported)
                    {
                        GUILayout.FlexibleSpace();
                        if (GUILayout.Button("Upgrade to " + latestSdkVersion, PlayFabEditorHelper.uiStyle.GetStyle("Button"), GUILayout.MinHeight(32)))
                        {
                            UpgradeSdk();
                        }
                        GUILayout.FlexibleSpace();
                    }
                    else if (isSdkSupported)
                    {
                        GUILayout.FlexibleSpace();
                        GUILayout.Label("You have the latest SDK!", labelStyle, GUILayout.MinHeight(32));
                        GUILayout.FlexibleSpace();
                    }

                    GUILayout.EndHorizontal();


                    GUILayout.EndVertical();
                }

                if (isSdkSupported && string.IsNullOrEmpty(PlayFabEditorDataService.envDetails.selectedTitleId))
                {
                    GUILayout.BeginVertical(PlayFabEditorHelper.uiStyle.GetStyle("gpStyleGray1"));
                    GUILayout.Label("Before making PlayFab API calls, the SDK must be configured to your PlayFab Title.", PlayFabEditorHelper.uiStyle.GetStyle("orTxt"));
                    GUILayout.BeginHorizontal();
                    GUILayout.FlexibleSpace();
                    if (GUILayout.Button("SET MY TITLE", PlayFabEditorHelper.uiStyle.GetStyle("textButton")))
                    {
                        PlayFabEditorMenu.OnSettingsClicked();
                    }
                    GUILayout.FlexibleSpace();
                    GUILayout.EndHorizontal();
                    GUILayout.EndVertical();
                }

                GUILayout.BeginHorizontal(PlayFabEditorHelper.uiStyle.GetStyle("gpStyleGray1"));

                GUILayout.FlexibleSpace();

                if (GUILayout.Button("VIEW RELEASE NOTES", PlayFabEditorHelper.uiStyle.GetStyle("textButton"), GUILayout.MinHeight(32), GUILayout.MinWidth(200)))
                {
                    Application.OpenURL("https://api.playfab.com/releaseNotes/");
                }

                GUILayout.FlexibleSpace();
                GUILayout.EndHorizontal();
            }
            else
            {
                //NO SDK Is Installed..

                GUILayout.BeginVertical(PlayFabEditorHelper.uiStyle.GetStyle("gpStyleGray1"));

                GUIStyle labelStyle = new GUIStyle(PlayFabEditorHelper.uiStyle.GetStyle("titleLabel"));

                GUILayout.Label("No SDK is installed.", labelStyle, GUILayout.MinWidth(EditorGUIUtility.currentViewWidth));
                GUILayout.Space(20);

                GUILayout.BeginHorizontal(PlayFabEditorHelper.uiStyle.GetStyle("gpStyleGray1"));
                var buttonWidth = 150;

                GUILayout.FlexibleSpace();
                if (GUILayout.Button("Install PlayFab SDK", PlayFabEditorHelper.uiStyle.GetStyle("Button"), GUILayout.MaxWidth(buttonWidth), GUILayout.MinHeight(32)))
                {
                    ImportLatestSDK();
                }
                GUILayout.FlexibleSpace();
                GUILayout.EndHorizontal();

                GUILayout.EndVertical();
            }
        }
        /// <summary>
        /// Handles state updates within the editor extension.
        /// </summary>
        /// <param name="state">the state that triggered this event.</param>
        /// <param name="status">a generic message about the status.</param>
        /// <param name="json">a generic container for additional JSON encoded info.</param>
        public void StateUpdateHandler(EdExStates state, string status, string json)
        {
            switch (state)
            {
            case EdExStates.OnMenuItemClicked:
                //Debug.Log(string.Format("MenuItem: {0} Clicked", status));
                PlayFabEditorDataService.editorSettings.currentSubMenu = 0;
                PlayFabEditorDataService.SaveEditorSettings();
                break;

            case EdExStates.OnSubmenuItemClicked:
                int parsed;
                if (Int32.TryParse(json, out parsed))
                {
                    PlayFabEditorDataService.editorSettings.currentSubMenu = parsed;
                    PlayFabEditorDataService.SaveEditorSettings();
                }
                break;


            case EdExStates.OnHttpReq:
                object temp;
                if (!string.IsNullOrEmpty(json) && Json.PlayFabSimpleJson.TryDeserializeObject(json, out temp))     // Json.JsonWrapper.DeserializeObject(json);)
                {
                    Json.JsonObject deserialized = temp as Json.JsonObject;
                    object          useSpinner   = false;
                    object          blockUi      = false;

                    if (deserialized.TryGetValue("useSpinner", out useSpinner) && bool.Parse(useSpinner.ToString()))
                    {
                        ProgressBar.UpdateState(ProgressBar.ProgressBarStates.spin);
                    }

                    if (deserialized.TryGetValue("blockUi", out blockUi) && bool.Parse(blockUi.ToString()))
                    {
                        AddBlockingRequest(status);
                    }
                }
                break;

            case EdExStates.OnHttpRes:
                ProgressBar.UpdateState(ProgressBar.ProgressBarStates.off);
                ProgressBar.UpdateState(ProgressBar.ProgressBarStates.success);
                ClearBlockingRequest(status);


                break;

            case EdExStates.OnError:

                // deserialize and add json details
                // clear blocking requests
                ProgressBar.UpdateState(ProgressBar.ProgressBarStates.error);
                ClearBlockingRequest();
                Debug.LogError(string.Format("PlayFab EditorExtensions: Caught an error:{0}", status));
                break;

            case EdExStates.OnWarning:
                ProgressBar.UpdateState(ProgressBar.ProgressBarStates.warning);
                ClearBlockingRequest();
                Debug.LogWarning(string.Format("PlayFab EditorExtensions: {0}", status));
                break;

            case EdExStates.OnSuccess:
                ClearBlockingRequest();
                ProgressBar.UpdateState(ProgressBar.ProgressBarStates.success);
                break;
            }
        }