Skip to content

Instantly share code, notes, and snippets.

@yuw-unknown
Last active July 7, 2019 01:32
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save yuw-unknown/e332c181200a7d2f1fd781e5d85b8d3c to your computer and use it in GitHub Desktop.
Save yuw-unknown/e332c181200a7d2f1fd781e5d85b8d3c to your computer and use it in GitHub Desktop.
Firebase RemoteConfig with Unity sample.
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using UnityEngine;
using Firebase;
using Firebase.RemoteConfig;
using System.Threading.Tasks;
public class FirebaseRemoteConfig {
// _________________________________________
#region シングルトン
private static FirebaseRemoteConfig _Instance = new FirebaseRemoteConfig();
public static FirebaseRemoteConfig Instance() {
return _Instance;
}
private FirebaseRemoteConfig() {
}
#endregion
// _________________________________________
// _________________________________________
#region 外部取得用Properties
/// <summary>
/// RemoteConfigのバージョン
/// </summary>
private string _ConfigVersion = "0.0.1";
public string ConfigVersion {
// set { _ConfigVersion = value; }
get { return _ConfigVersion; }
}
/// <summary>
/// ドアを開くスピード
/// </summary>
private float _DoorMoveSpeed = 0.2f;
public float DoorMoveSpeed {
// set { _DoorMoveSpeed = value; }
get { return _DoorMoveSpeed; }
}
/// <summary>
/// どれくらい戸棚が開いていれば開いているとみなすのか
/// </summary>
private float _DoorOpenDistance = 0.5f;
public float DoorOpenDistance {
// set { _DoorOpenDistance = value; }
get { return _DoorOpenDistance; }
}
/// <summary>
/// 暑さゲージの自然増の時間間隔
/// </summary>
private float _HeatMeterPlusInterval = 0.15f;
public float HeatMeterPlusInterval {
get { return _HeatMeterPlusInterval; }
}
/// <summary>
/// 団扇で扇がれた時に暑さゲージをどれだけ下げるか
/// </summary>
private int _HeatMeterMinusWithFan = 2;
public int HeatMeterMinusWithFan {
get { return _HeatMeterMinusWithFan; }
}
private float _CatOnStageTimeMin = 1.0f;
public float CatOnStageTimeMin {
get { return _CatOnStageTimeMin; }
}
private float _CatOnStageTimeMax = 1.0f;
public float CatOnStageTimeMax {
get { return _CatOnStageTimeMax; }
}
#endregion
// _________________________________________
/// <summary>
/// サーバとの同期を行います
/// </summary>
/// <param name="completionHandler">同期完了時のコールバック</param>
public void fetch (Action<bool> completionHandler) {
// TODO: RELEASE時にここを外す
var settings = Firebase.RemoteConfig.FirebaseRemoteConfig.Settings;
settings.IsDeveloperMode = true;
Firebase.RemoteConfig.FirebaseRemoteConfig.Settings = settings;
System.Threading.Tasks.Task fetchTask = Firebase.RemoteConfig.FirebaseRemoteConfig.FetchAsync (new System.TimeSpan (0));
fetchTask.ContinueWith(task => {
if (task.IsCanceled || task.IsFaulted) {
completionHandler(false);
Utilitys.LogCurrentMethod("Faild.");
} else {
Utilitys.LogCurrentMethod("Completed.");
}
Firebase.RemoteConfig.FirebaseRemoteConfig.ActivateFetched ();
RefrectProperties();
completionHandler(true);
});
}
/// <summary>
/// RemoteConfigからFetchした情報をフィールド反映します
/// </summary>
private void RefrectProperties() {
_ConfigVersion = Firebase.RemoteConfig.FirebaseRemoteConfig.GetValue("version").StringValue;
Utilitys.LogCurrentMethod("config version = " + _ConfigVersion);
_DoorMoveSpeed = (float)Firebase.RemoteConfig.FirebaseRemoteConfig.GetValue("door_move_speed").DoubleValue;
Utilitys.LogCurrentMethod("door move speed = " + _DoorMoveSpeed);
_DoorOpenDistance = (float)Firebase.RemoteConfig.FirebaseRemoteConfig.GetValue("door_open_distance").DoubleValue;
Utilitys.LogCurrentMethod("door_open_distance = " + _DoorOpenDistance);
_HeatMeterPlusInterval = (float)Firebase.RemoteConfig.FirebaseRemoteConfig.GetValue("heatmeter_plus_interval").DoubleValue;
Utilitys.LogCurrentMethod("heatmeter_plus_interval = " + _HeatMeterPlusInterval);
_HeatMeterMinusWithFan = (int)Firebase.RemoteConfig.FirebaseRemoteConfig.GetValue("heatmeter_minus_fan").DoubleValue;
Utilitys.LogCurrentMethod("heatmeter_minus_fan = " + _HeatMeterMinusWithFan);
_CatOnStageTimeMin = (float)Firebase.RemoteConfig.FirebaseRemoteConfig.GetValue("cat_onstage_time_min").DoubleValue;
Utilitys.LogCurrentMethod("cat_onstage_time_min = " + _CatOnStageTimeMin);
_CatOnStageTimeMax = (float)Firebase.RemoteConfig.FirebaseRemoteConfig.GetValue("cat_onstage_time_max").DoubleValue;
Utilitys.LogCurrentMethod("cat_onstage_time_max = " + _CatOnStageTimeMax);
}
private void ConfigFetchComplete(Task fetchTask) {
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment