Esempio n. 1
0
    private void DrawSetupPhoton()
    {
        DrawInputWithLabel("Photon Cloud Setup", () =>
        {
            GUILayout.BeginVertical();
            GUILayout.Space(5);
            GUILayout.Label(BoltWizardText.PHOTON, textLabel);
            GUILayout.EndVertical();

            GUILayout.BeginHorizontal();
            GUILayout.Label(BoltWizardText.PHOTON_DASH, textLabel);
            if (GUILayout.Button("Visit Dashboard", minimalButton))
            {
                OpenURL("https://dashboard.photonengine.com/")();
            }
            GUILayout.EndHorizontal();
        }, false);
        GUILayout.Space(15);

        BoltRuntimeSettings settings = BoltRuntimeSettings.instance;

        DrawInputWithLabel("Photon Bolt App ID", () =>
        {
            GUILayout.BeginVertical();

            settings.photonAppId = EditorGUILayout.TextField(settings.photonAppId, centerInputText);

            GUILayout.EndVertical();
        }, false, true);

        DrawInputWithLabel("Connection Mode", () =>
        {
            settings.photonUseOnPremise = BoltEditorGUI.ToggleDropdown("Custom Hosted", "Photon Cloud", settings.photonUseOnPremise);
        }, true, true);

        if (settings.photonUseOnPremise)
        {
            DrawInputWithLabel("Master Server IP Address", () =>
            {
                GUILayout.BeginVertical();
                settings.photonOnPremiseIpAddress = EditorGUILayout.TextField(settings.photonOnPremiseIpAddress);
                GUILayout.EndVertical();
            }, true, true);
        }
        else
        {
            DrawInputWithLabel("Region", () =>
            {
                settings.photonCloudRegionIndex = EditorGUILayout.Popup(settings.photonCloudRegionIndex, BoltRuntimeSettings.photonCloudRegions);
            }, true, true);
        }

        DrawInputWithLabel("NAT Punchthrough Enabled", () =>
        {
            settings.photonUsePunch = BoltEditorGUI.Toggle(settings.photonUsePunch);
        }, true, true);

        // Action

        if (beforeNextCallback == null)
        {
            beforeNextCallback = () =>
            {
                if (!IsAppId(settings.photonAppId))
                {
                    ShowNotification(new GUIContent("Please specify a valid Bolt App ID."));
                    return(false);
                }

                return(true);
            };
        }
    }
    private void DrawSetupPhoton()
    {
        DrawInputWithLabel("Photon Cloud Setup", () =>
        {
            GUILayout.BeginVertical();
            GUILayout.Space(5);
            GUILayout.Label(BoltWizardText.PHOTON, textLabel);
            GUILayout.EndVertical();

            GUILayout.BeginHorizontal();
            GUILayout.Label(BoltWizardText.PHOTON_DASH, textLabel);
            if (GUILayout.Button("Visit Dashboard", minimalButton))
            {
                OpenURL("https://dashboard.photonengine.com/")();
            }

            GUILayout.EndHorizontal();
        }, false);
        GUILayout.Space(15);

        BoltRuntimeSettings settings = BoltRuntimeSettings.instance;

        DrawInputWithLabel("Photon Bolt App ID or Email", () =>
        {
            GUILayout.BeginVertical();

            AppIdOrEmail = EditorGUILayout.TextField(AppIdOrEmail, centerInputText);

            GUILayout.EndVertical();
        }, false, true, 300);

        DrawInputWithLabel("Region",
                           () =>
        {
            settings.photonCloudRegionIndex = EditorGUILayout.Popup(settings.photonCloudRegionIndex,
                                                                    BoltRuntimeSettings.photonCloudRegions);
        }, true, true);

        DrawInputWithLabel("NAT Punchthrough Enabled",
                           () => { settings.photonUsePunch = BoltEditorGUI.Toggle(settings.photonUsePunch); }, true, true);

        // Action

        if (beforeNextCallback == null)
        {
            beforeNextCallback = () =>
            {
                if (requestingAppId)
                {
                    BoltLog.Info("Please, wait until your request for a new AppID finishes.");
                    return(false);
                }

                if (AccountService.IsValidEmail(AppIdOrEmail))
                {
                    try
                    {
                        EditorUtility.DisplayProgressBar(BoltWizardText.CONNECTION_TITLE,
                                                         BoltWizardText.CONNECTION_INFO, 0.5f);
                        BoltLog.Info("Starting request");

                        requestingAppId = new AccountService().RegisterByEmail(
                            AppIdOrEmail,
                            new List <ServiceTypes>()
                        {
                            ServiceTypes.Bolt
                        },
                            (response) =>
                        {
                            if (response.ReturnCode == AccountServiceReturnCodes.Success)
                            {
                                var appKey = response.ApplicationIds[((int)ServiceTypes.Bolt).ToString()];

                                settings.photonAppId = appKey;
                                AppIdOrEmail         = appKey;

                                BoltLog.Info("You new App ID: {0}", AppIdOrEmail);
                            }
                            else
                            {
                                BoltLog.Warn(
                                    "It was not possible to process your request, please go to the Photon Cloud Dashboard.");
                                BoltLog.Warn("Return Code: {0}",
                                             AccountServiceReturnCodes.ReturnCodes[response.ReturnCode]);
                            }

                            requestingAppId = false;
                            EditorUtility.ClearProgressBar();
                        }, (err) =>
                        {
                            BoltLog.Error(err);

                            requestingAppId = false;
                            EditorUtility.ClearProgressBar();
                        });

                        if (requestingAppId)
                        {
                            BoltLog.Info("Requesting your new App ID");
                        }
                        else
                        {
                            BoltLog.Warn(
                                "It was not possible to process your request, please go to the Photon Cloud Dashboard.");
                            EditorUtility.ClearProgressBar();
                        }
                    }
                    catch (Exception ex)
                    {
                        EditorUtility.DisplayDialog("Error", ex.Message, "ok");
                    }
                }
                else if (IsAppId(AppIdOrEmail))
                {
                    settings.photonAppId = AppIdOrEmail;
                    return(true);
                }
                else
                {
                    ShowNotification(new GUIContent("Please specify a valid Photon Bolt App ID or Email."));
                }

                return(false);
            };
        }
    }
Esempio n. 3
0
    private void DrawSetupPhoton()
    {
        DrawInputWithLabel("Photon Cloud Setup", () =>
        {
            GUILayout.BeginVertical();
            GUILayout.Space(5);
            GUILayout.Label(BoltWizardText.PHOTON, textLabel);
            GUILayout.EndVertical();

            GUILayout.BeginHorizontal();
            GUILayout.Label(BoltWizardText.PHOTON_DASH, textLabel);
            if (GUILayout.Button("Visit Dashboard", minimalButton))
            {
                OpenURL("https://dashboard.photonengine.com/")();
            }
            GUILayout.EndHorizontal();
        }, false);
        GUILayout.Space(15);

        BoltRuntimeSettings settings = BoltRuntimeSettings.instance;

        DrawInputWithLabel("Photon Bolt App ID or Email", () =>
        {
            GUILayout.BeginVertical();

            AppIdOrEmail = EditorGUILayout.TextField(AppIdOrEmail, centerInputText);

            GUILayout.EndVertical();
        }, false, true, 300);

        DrawInputWithLabel("Connection Mode", () =>
        {
            settings.photonUseOnPremise = BoltEditorGUI.ToggleDropdown("Custom Hosted", "Photon Cloud", settings.photonUseOnPremise);
        }, true, true);

        if (settings.photonUseOnPremise)
        {
            DrawInputWithLabel("Master Server IP Address", () =>
            {
                GUILayout.BeginVertical();
                settings.photonOnPremiseIpAddress = EditorGUILayout.TextField(settings.photonOnPremiseIpAddress);
                GUILayout.EndVertical();
            }, true, true);
        }
        else
        {
            DrawInputWithLabel("Region", () =>
            {
                settings.photonCloudRegionIndex = EditorGUILayout.Popup(settings.photonCloudRegionIndex, BoltRuntimeSettings.photonCloudRegions);
            }, true, true);
        }

        DrawInputWithLabel("NAT Punchthrough Enabled", () =>
        {
            settings.photonUsePunch = BoltEditorGUI.Toggle(settings.photonUsePunch);
        }, true, true);

        // Action

        if (beforeNextCallback == null)
        {
            beforeNextCallback = () =>
            {
                if (IsEmail(AppIdOrEmail))
                {
                    try
                    {
                        EditorUtility.DisplayProgressBar(BoltWizardText.CONNECTION_TITLE, BoltWizardText.CONNECTION_INFO, 0.5f);
                        BoltLog.Info("Starting request");

                        string result = new AccountService().RegisterByEmail(AppIdOrEmail);

                        if (!string.IsNullOrEmpty(result) && IsAppId(result))
                        {
                            settings.photonAppId = result;
                            AppIdOrEmail         = result;

                            BoltLog.Info("You new App ID: {0}", settings.photonAppId);
                            return(true);
                        }
                    }
                    catch (Exception ex)
                    {
                        EditorUtility.DisplayDialog("Error", ex.Message, "ok");
                        //ShowNotification(new GUIContent(ex.Message));
                    }
                    finally
                    {
                        EditorUtility.ClearProgressBar();
                        BoltLog.Info("Finished request");
                    }
                }
                else if (IsAppId(AppIdOrEmail))
                {
                    settings.photonAppId = AppIdOrEmail;
                    return(true);
                }
                else
                {
                    ShowNotification(new GUIContent("Please specify a valid Bolt App ID or Email."));
                }

                return(false);
            };
        }
    }