Hi.
I am seeing remote config returns ConfigOrigin.Remote when device is offline. Is this normal?
Below is my code and what i am trying to do:
-
When the device is online, Remote Config would work perfectly and everything is fine.
-
When the device is online, I delete Remote Config cache with my own code after Remote Config finishes its magic. The reason i do this is to make player harder to cheat.
-
When the device is offline, Remote Config will not able to read any cache since I always delete that.
-
When the device is offline, GetData(ConfigResponse configResponse) return ConfigOrigin.Remote, which I would expect it returns .Default since there is no cache and Offline.
If I keep the cache there things would work. But I really want to keep that cache out of the device. Is there a way to tell RemoteConfig to return ConfigOrigin.Default when the device is offline in my case? Or is there a better way to do to what i want to achieve?
Thank you!
using System.Collections;
using UnityEngine;
using Unity.RemoteConfig;
using System.IO;
public class RemoteConfigController : MonoBehaviour
{
[Tooltip("this delay is mainly for incase there is a loading and saving operations in other scripts so it wait a little bit before reading server")]
private float startDelay = 0.2f;
[HideInInspector] public struct UserAttribute { }
[HideInInspector] public struct AppAttributes { }
#region Singleton
public static RemoteConfigController instance;
private void Awake()
{
if (instance != null)
{
Destroy(instance.gameObject);
}
instance = this;
DontDestroyOnLoad(this);
}
#endregion
private void Start()
{
ConfigManager.FetchCompleted += GetData;
StartCoroutine(FetchDataCoroutine());
}
IEnumerator FetchDataCoroutine()
{
yield return new WaitForSeconds(startDelay);
ConfigManager.SetEnvironmentID("xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx");
ConfigManager.FetchConfigs<UserAttribute, AppAttributes>(new UserAttribute(), new AppAttributes());
}
private void GetData(ConfigResponse configResponse)
{
switch (configResponse.requestOrigin)
{
case ConfigOrigin.Default:
Debug.Log("ConfigOrigin = Default.");
break;
case ConfigOrigin.Cached:
Debug.Log("ConfigOrigin = Cached.");
break;
case ConfigOrigin.Remote:
Debug.Log("ConfigOrigin = Remote.");
break;
}
StartCoroutine(DeleteRemoteConfigCache());
}
IEnumerator DeleteRemoteConfigCache()
{
//using delay because the file cannot be deleted at the exact moment after it was created/modified
yield return new WaitForSeconds(0.1f);
//check if cache file exist, if so delete the cache file
string path = Application.persistentDataPath + "/RemoteConfigCache.json";
if (File.Exists(path)) //check if file exists
{
File.Delete(path);
Debug.Log("Deleted " + path);
}
}
}