API/Autodoc/Files/RuStoreRemoteConfigClient.cs.en.md
Namespaces
Classes
Source code
using UnityEngine;
using System;
using RuStore.RemoteConfig.Internal;
namespace RuStore.RemoteConfig {
public class RuStoreRemoteConfigClient {
public static string PluginVersion = "10.3.1";
private static RuStoreRemoteConfigClient _instance;
private static bool _isInstanceInitialized;
private bool _isInitialized;
public bool IsInitialized => _isInitialized;
private AndroidJavaObject _clientWrapper;
public static RuStoreRemoteConfigClient Instance {
get {
if (!_isInstanceInitialized) {
_isInstanceInitialized = true;
_instance = new RuStoreRemoteConfigClient();
}
return _instance;
}
}
private RuStoreRemoteConfigClient() {
}
public bool Init(RuStoreRemoteConfigClientSettings settings, IRemoteConfigClientEventListener eventListener = null) {
if (_isInitialized) {
Debug.LogError("Error: RuStore Remote Config is already initialized");
return false;
}
if (Application.platform != RuntimePlatform.Android) {
return false;
}
CallbackHandler.InitInstance();
ActivityInstaller.Instance.Install();
using (var clientJavaClass = new AndroidJavaClass("ru.rustore.unitysdk.remoteconfigclient.RuStoreUnityRemoteConfigClient")) {
_clientWrapper = clientJavaClass.GetStatic<AndroidJavaObject>("INSTANCE");
}
if (!string.IsNullOrEmpty(settings.account)) {
SetAccount(settings.account);
}
if (!string.IsNullOrEmpty(settings.language)) {
SetLanguage(settings.language);
}
var parameters = new RemoteConfigClientParameters(settings);
var listener = new RemoteConfigClientEventListener(eventListener);
AndroidJavaClass updateBehaviour = new AndroidJavaClass("ru.rustore.unitysdk.remoteconfigclient.model.UnityUpdateBehaviour");
AndroidJavaObject updateBehaviourActual = updateBehaviour.GetStatic<AndroidJavaObject>("Actual");
_clientWrapper.Call("init", settings.appId, 15, updateBehaviourActual, parameters, listener, null);
_isInitialized = true;
return true;
}
public bool Init(IRemoteConfigClientEventListener eventListener = null) {
if (Application.platform != RuntimePlatform.Android) {
return false;
}
CallbackHandler.InitInstance();
using (var clientJavaClass = new AndroidJavaClass("ru.rustore.unitysdk.remoteconfigclient.RuStoreUnityRemoteConfigClient")) {
_clientWrapper = clientJavaClass.GetStatic<AndroidJavaObject>("INSTANCE");
}
if (eventListener != null) {
using (var listenerJavaClass = new AndroidJavaClass("ru.rustore.unitysdk.remoteconfigclient.RemoteConfigClientEventListenerDefault")) {
var instance = listenerJavaClass.GetStatic<AndroidJavaObject>("INSTANCE");
var listener = new RemoteConfigClientEventListener(eventListener);
instance.Call("setListener", listener);
}
}
_isInitialized = true;
return true;
}
public void GetRemoteConfig(Action<RuStoreError> onFailure, Action<RemoteConfig> onSuccess) {
if (!IsPlatformSupported(onFailure)) {
return;
}
var listener = new GetRemoteConfigListener(onFailure, onSuccess);
_clientWrapper.Call("getRemoteConfig", listener);
}
public void SetAccount(string account) {
if (!IsPlatformSupported((error) => { })) {
return;
}
_clientWrapper.Call("setAccount", account);
}
public void SetLanguage(string language) {
if (!IsPlatformSupported((error) => { })) {
return;
}
_clientWrapper.Call("setLanguage", language);
}
private bool IsPlatformSupported(Action<RuStoreError> onFailure) {
if (Application.platform != RuntimePlatform.Android) {
onFailure?.Invoke(new RuStoreError() {
name = "RuStoreRemoteConfigClientError",
description = "Unsupported platform"
});
return false;
}
return true;
}
}
}