Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System.Collections;
- using System.Collections.Generic;
- using System.Threading.Tasks;
- using Unity.Services.RemoteConfig;
- using Unity.Services.Authentication;
- using Unity.Services.Core;
- using UnityEngine;
- using UnityEngine.SceneManagement;
- public class remoteconfig : MonoBehaviour
- {
- public static remoteconfig Instance { get; private set; }
- public struct userAttributes { }
- public struct appAttributes { }
- public bool isMaintenance = false;
- public int test = 1;
- async Task InitializeRemoteConfigAsync()
- {
- await UnityServices.InitializeAsync();
- if (!AuthenticationService.Instance.IsSignedIn)
- {
- await AuthenticationService.Instance.SignInAnonymouslyAsync();
- }
- }
- void Awake()
- {
- if (Instance == null)
- {
- Instance = this;
- }
- else
- {
- Destroy(gameObject);
- }
- }
- async void Start()
- {
- if (Utilities.CheckForInternetConnection())
- {
- await InitializeRemoteConfigAsync();
- }
- RemoteConfigService.Instance.FetchConfigs<userAttributes, appAttributes>(new userAttributes(), new appAttributes() { });
- RemoteConfigService.Instance.SetEnvironmentID("");
- RemoteConfigService.Instance.FetchCompleted += setMaintenance;
- }
- void setMaintenance(ConfigResponse configResponse)
- {
- switch (configResponse.requestOrigin)
- {
- case ConfigOrigin.Default:
- //Debug.Log("No settings loaded this session; using default values.");
- break;
- case ConfigOrigin.Cached:
- //Debug.Log("No settings loaded this session; using cached values from a previous session.");
- break;
- case ConfigOrigin.Remote:
- //Debug.Log("New settings loaded this session; update values accordingly.");
- isMaintenance = RemoteConfigService.Instance.appConfig.GetBool("maintenance");
- test = RemoteConfigService.Instance.appConfig.GetInt("test");
- //Debug.Log(test);
- Scene currentScene = SceneManager.GetActiveScene();
- string sceneName = currentScene.name;
- //Debug.Log(sceneName);
- if (isMaintenance == true && sceneName != "Maintenance")
- {
- SceneManager.LoadScene("Maintenance");
- }
- else if (isMaintenance == false && sceneName == "Maintenance")
- {
- SceneManager.LoadScene("Menu");
- }
- break;
- }
- }
- private void Update()
- {
- RemoteConfigService.Instance.FetchConfigs<userAttributes, appAttributes>(new userAttributes(), new appAttributes() { });
- RemoteConfigService.Instance.SetEnvironmentID("");
- RemoteConfigService.Instance.FetchCompleted += setMaintenance;
- }
- /*private void OnDestroy()
- {
- RemoteConfigService.Instance.FetchCompleted -= setMaintenance;
- }*/
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement