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();
            }
        }
Пример #2
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);
            }
        }
        void OnGUI()
        {
            try
            {
                GUI.skin = PlayFabEditorHelper.uiStyle;

                GUILayout.BeginVertical();

                //Run all updaters prior to drawing;
                PlayFabEditorSettings.Update();
                PlayFabEditorPackageManager.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;

                            case PlayFabEditorMenu.MenuStates.Tools:
                                PlayFabEditorToolsMenu.DrawToolsPanel();
                                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);
                        if (ShowEdExUpgrade())
                        {
                            GUILayout.BeginHorizontal();
                            GUILayout.FlexibleSpace();
                            if (GUILayout.Button("UPGRADE EDEX", PlayFabEditorHelper.uiStyle.GetStyle("textButtonOr")))
                            {
                                UpgradeEdEx();
                            }
                            GUILayout.FlexibleSpace();
                            GUILayout.EndHorizontal();
                        }


                        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.EDEX_ROOT))
                        {
                            GUILayout.BeginHorizontal();
                            GUILayout.FlexibleSpace();
                            if (GUILayout.Button("UNINSTALL ", PlayFabEditorHelper.uiStyle.GetStyle("textButton")))
                            {
                                RemoveEdEx();
                            }
                            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);
            }
        }