Advertisement
Guest User

Untitled

a guest
Oct 7th, 2022
97
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 3.13 KB | None | 0 0
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using System.Threading.Tasks;
  4. using Unity.Services.RemoteConfig;
  5. using Unity.Services.Authentication;
  6. using Unity.Services.Core;
  7. using UnityEngine;
  8. using UnityEngine.SceneManagement;
  9.  
  10. public class remoteconfig : MonoBehaviour
  11. {
  12.     public static remoteconfig Instance { get; private set; }
  13.     public struct userAttributes { }
  14.     public struct appAttributes { }
  15.     public bool isMaintenance = false;
  16.     public int test = 1;
  17.  
  18.     async Task InitializeRemoteConfigAsync()
  19.     {
  20.         await UnityServices.InitializeAsync();
  21.  
  22.         if (!AuthenticationService.Instance.IsSignedIn)
  23.         {
  24.             await AuthenticationService.Instance.SignInAnonymouslyAsync();
  25.         }
  26.     }
  27.  
  28.     void Awake()
  29.     {
  30.         if (Instance == null)
  31.         {
  32.             Instance = this;
  33.         }
  34.         else
  35.         {
  36.             Destroy(gameObject);
  37.         }
  38.     }
  39.     async void Start()
  40.     {
  41.  
  42.         if (Utilities.CheckForInternetConnection())
  43.         {
  44.             await InitializeRemoteConfigAsync();
  45.         }
  46.         RemoteConfigService.Instance.FetchConfigs(new userAttributes(), new appAttributes() { });
  47.         RemoteConfigService.Instance.SetEnvironmentID("03e37ee7-10ee-4b63-8f67-bba906fe5bd2");
  48.         RemoteConfigService.Instance.FetchCompleted += setMaintenance;
  49.     }
  50.  
  51.     void setMaintenance(ConfigResponse configResponse)
  52.     {
  53.         switch (configResponse.requestOrigin)
  54.         {
  55.             case ConfigOrigin.Default:
  56.                 //Debug.Log("No settings loaded this session; using default values.");
  57.                 break;
  58.             case ConfigOrigin.Cached:
  59.                 //Debug.Log("No settings loaded this session; using cached values from a previous session.");
  60.                 break;
  61.             case ConfigOrigin.Remote:
  62.                 //Debug.Log("New settings loaded this session; update values accordingly.");
  63.                 isMaintenance = RemoteConfigService.Instance.appConfig.GetBool("maintenance");
  64.                 test = RemoteConfigService.Instance.appConfig.GetInt("test");
  65.                 //Debug.Log(test);
  66.                 Scene currentScene = SceneManager.GetActiveScene();
  67.                 string sceneName = currentScene.name;
  68.                 Debug.Log(sceneName);
  69.                 Debug.Log(isMaintenance);
  70.  
  71.                 if (isMaintenance == true && sceneName != "Maintenance")
  72.                 {
  73.                     SceneManager.LoadScene("Maintenance");
  74.                 }
  75.                 else if (isMaintenance == false && sceneName == "Maintenance")
  76.                 {
  77.                     SceneManager.LoadScene("Menu");
  78.                 }
  79.                 break;
  80.         }
  81.     }
  82.     private void Update()
  83.     {
  84.         RemoteConfigService.Instance.FetchConfigs(new userAttributes(), new appAttributes() { });
  85.         RemoteConfigService.Instance.SetEnvironmentID("03e37ee7-10ee-4b63-8f67-bba906fe5bd2");
  86.         RemoteConfigService.Instance.FetchCompleted += setMaintenance;
  87.     }
  88.     /*private void OnDestroy()
  89.     {
  90.         RemoteConfigService.Instance.FetchCompleted -= setMaintenance;
  91.     }*/
  92. }
  93.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement