public static void Init(string appId = "REFLECT_VIEWER")
        {
            if (s_Initialized)
            {
                return;
            }

            s_Initialized = true;

            var environmentInfo = LocaleUtils.GetEnvironmentInfo();

            Provider = environmentInfo.provider;

            var    projectDataSuffix = string.Empty;
            string projectServerAddress;

            if (PlayerPrefs.HasKey(LocaleUtils.SettingsKeys.CloudEnvironment) && environmentInfo.cloudEnvironment == CloudEnvironment.Other)
            {
                projectServerAddress = environmentInfo.customUrl;
                projectDataSuffix    = $"-{projectServerAddress.MD5Hash()}";
            }
            else
            {
                projectServerAddress = ProjectServerClient.ProjectServerAddress(environmentInfo.provider, environmentInfo.cloudEnvironment);

                if (environmentInfo.cloudEnvironment != CloudEnvironment.Production)
                {
                    projectDataSuffix = $"-{environmentInfo.provider}-{environmentInfo.cloudEnvironment}";
                }
                // else: No suffix for prod since real users already have data stored in their ProjectData folder
            }

            ProjectDataPath = Path.Combine(Application.persistentDataPath, $"ProjectData{projectDataSuffix}");
            Directory.CreateDirectory(ProjectDataPath);

            Client = new ProjectServerClient(projectServerAddress, appId, ProjectDataPath);
        }
        void OnSessionStateDataChanged(UISessionStateData data)
        {
            if (m_LoginState != data.sessionState.loggedState)
            {
                switch (data.sessionState.loggedState)
                {
                case LoginState.LoggedIn:
                    m_NoProjectPanel.SetActive(false);
                    m_FetchingProjectsPanel.SetActive(true);
                    break;

                case LoginState.LoggedOut:
                    ClearProjectListItem();
                    m_NoProjectPanel.SetActive(false);
                    m_FetchingProjectsPanel.SetActive(false);
                    break;

                case LoginState.LoggingIn:
                case LoginState.LoggingOut:
                    // todo put spinner
                    break;
                }

                m_LoginState = data.sessionState.loggedState;
            }

            if (m_LoginState == LoginState.LoggedIn)
            {
                // Display Cloud environment debug info when it's not "Production"
                var environmentInfo = LocaleUtils.GetEnvironmentInfo();
                if (environmentInfo.cloudEnvironment != CloudEnvironment.Production)
                {
                    m_CloudSettingDebugInfo.gameObject.SetActive(true);

                    if (environmentInfo.cloudEnvironment == CloudEnvironment.Other)
                    {
                        if (PlayerPrefs.HasKey(LocaleUtils.SettingsKeys.CloudEnvironment))
                        {
                            m_CloudSettingDebugInfo.text = $"Environment: {environmentInfo.customUrl}";
                        }
                        else
                        {
                            m_CloudSettingDebugInfo.text =
                                $"Environment: {ProjectServerClient.ProjectServerAddress(environmentInfo.provider)}";
                        }
                    }
                    else
                    {
                        m_CloudSettingDebugInfo.text = $"Environment: {environmentInfo.cloudEnvironment}";
                    }
                }
                else
                {
                    m_CloudSettingDebugInfo.gameObject.SetActive(false);
                }

                UpdateProjectItems(data.sessionState.rooms);

                if (m_Rooms != data.sessionState.rooms || !EnumerableExtension.SafeSequenceEquals(m_Rooms, data.sessionState.rooms))
                {
                    m_Rooms = data.sessionState.rooms;
                }
                else if (HasNoProjectsAvailable())
                {
                    m_NoProjectPanel.SetActive(true);
                    m_FetchingProjectsPanel.SetActive(false);
                }
            }
        }
        void UpdateSettings()
        {
            var environmentInfo = LocaleUtils.GetEnvironmentInfo();

            RegionOption regionOption = RegionOption.None;

            switch (environmentInfo.provider)
            {
            case RegionUtils.Provider.GCP:
                regionOption = RegionOption.Default;
                break;

            case RegionUtils.Provider.Tencent:
                regionOption = RegionOption.China;
                break;
            }

            OptionItemButton selectedButton = null;

            foreach (var button in m_RegionButtons)
            {
                button.SelectButton(button.regionOption == regionOption);
                if (button.regionOption == regionOption)
                {
                    selectedButton = button;
                }
            }

            if (selectedButton != null)
            {
                m_RegionText.text = $"Region: {selectedButton.label.text}";
            }

            CloudOption cloudOption = CloudOption.Default;

            if (PlayerPrefs.HasKey(LocaleUtils.SettingsKeys.CloudEnvironment))
            {
                switch (environmentInfo.cloudEnvironment)
                {
                case CloudEnvironment.Other:
                    cloudOption = CloudOption.Other;
                    break;

                case CloudEnvironment.Local:
                    cloudOption = CloudOption.Local;
                    break;

                case CloudEnvironment.Test:
                    cloudOption = CloudOption.Test;
                    break;

                case CloudEnvironment.Staging:
                    cloudOption = CloudOption.Staging;
                    break;

                case CloudEnvironment.Production:
                    cloudOption = CloudOption.Production;
                    break;
                }
            }

            m_CloudOtherSelected = cloudOption == CloudOption.Other;
            EnableCustomInput(m_CloudOtherSelected);
            m_CloudURLInput.text = environmentInfo.customUrl;

            foreach (var button in m_CloudButtons)
            {
                button.SelectButton(button.cloudOption == cloudOption);
            }

            if (environmentInfo.cloudEnvironment != CloudEnvironment.Production)
            {
                m_CloudSettingDebugInfo.gameObject.SetActive(true);

                if (environmentInfo.cloudEnvironment == CloudEnvironment.Other)
                {
                    if (PlayerPrefs.HasKey(LocaleUtils.SettingsKeys.CloudEnvironment))
                    {
                        m_CloudSettingDebugInfo.text = $"Environment: {environmentInfo.customUrl}";
                    }
                    else
                    {
                        m_CloudSettingDebugInfo.text =
                            $"Environment: {ProjectServerClient.ProjectServerAddress(environmentInfo.provider, Protocol.Http)}";
                    }
                }
                else
                {
                    m_CloudSettingDebugInfo.text = $"Environment: {environmentInfo.cloudEnvironment}";
                }
            }
            else
            {
                m_CloudSettingDebugInfo.gameObject.SetActive(false);
            }
        }
Example #4
0
        void OnLoggedStateDataChanged(LoginState newData)
        {
            if (m_LoginState != newData)
            {
                switch (newData)
                {
                case LoginState.ProcessingToken:
                    ClearProjectListItem();
                    m_NoProjectPanel.SetActive(false);
                    m_FetchingProjectsPanel.SetActive(false);
                    break;

                case LoginState.LoggingIn:
                    m_NoProjectPanel.SetActive(false);
                    m_FetchingProjectsPanel.SetActive(false);
                    break;

                case LoginState.LoggedIn:
                    m_NoProjectPanel.SetActive(false);
                    m_FetchingProjectsPanel.SetActive(true);
                    break;

                case LoginState.LoggedOut:
                    ClearProjectListItem();
                    m_NoProjectPanel.SetActive(false);
                    m_FetchingProjectsPanel.SetActive(false);
                    break;

                case LoginState.LoggingOut:
                    // todo put spinner
                    break;
                }

                m_LoginState = newData;
            }

            if (m_LoginState == LoginState.LoggedIn)
            {
                // Display Cloud environment debug info when it's not "Production"
                var environmentInfo = LocaleUtils.GetEnvironmentInfo();
                if (environmentInfo.cloudEnvironment != CloudEnvironment.Production)
                {
                    m_CloudSettingDebugInfo.gameObject.SetActive(true);

                    if (environmentInfo.cloudEnvironment == CloudEnvironment.Other)
                    {
                        if (PlayerPrefs.HasKey(LocaleUtils.SettingsKeys.CloudEnvironment))
                        {
                            m_CloudSettingDebugInfo.text = $"Environment: {environmentInfo.customUrl}";
                        }
                        else
                        {
                            m_CloudSettingDebugInfo.text =
                                $"Environment: {ProjectServerClient.ProjectServerAddress(environmentInfo.provider, Protocol.Http)}";
                        }
                    }
                    else
                    {
                        m_CloudSettingDebugInfo.text = $"Environment: {environmentInfo.cloudEnvironment}";
                    }
                }
                else
                {
                    m_CloudSettingDebugInfo.gameObject.SetActive(false);
                }
            }
        }