Skip to content

Instantly share code, notes, and snippets.

@kyubuns
Created February 6, 2018 00:11
Show Gist options
  • Save kyubuns/8f3964cf197666b5cf126b02f85f25f5 to your computer and use it in GitHub Desktop.
Save kyubuns/8f3964cf197666b5cf126b02f85f25f5 to your computer and use it in GitHub Desktop.
よくあるHPゲージが後追いでゆっくり減るやつにEasingをつける
private IEnumerator Sample12()
{
var hp = new ReactiveProperty<int>(100);
var gauge = new ReactiveProperty<float>(100.0f);
// HPゲージは、実際の値に1.5秒かけて追いつく
hp
.Select(x => Anime.Play(gauge.Value, x, Easing.EaseOutSine(TimeSpan.FromSeconds(1.5))))
.Switch()
.Subscribe(x => gauge.Value = x);
gauge.Subscribe(x =>
{
// HPゲージの長さにする
Debug.LogFormat("hp: {0}", x);
});
yield return new WaitForSeconds(1.0f);
Debug.Log("ダメージを受けてHPが30に!");
hp.Value = 30;
yield return new WaitForSeconds(1.0f);
Debug.Log("回復してHPが80に!");
hp.Value = 80;
}
/*
hp: 100
ダメージを受けてHPが30に!
hp: 97.73669
hp: 73.9443
hp: 71.5481
hp: 69.92892
hp: 67.57964
hp: 65.49018
hp: 63.21416
hp: 61.25372
hp: 59.33255
hp: 57.20453
hp: 55.35437
hp: 53.56058
hp: 51.85281
hp: 49.98868
hp: 48.38297
hp: 46.81829
hp: 44.95667
hp: 43.70924
hp: 42.35075
hp: 40.90713
hp: 39.6825
hp: 38.50326
回復してHPが80に!
hp: 40.20254
hp: 41.4445
hp: 43.05221
hp: 44.36655
hp: 45.77445
hp: 47.30541
hp: 48.78835
hp: 49.97299
hp: 51.4628
hp: 52.7821
hp: 54.09845
hp: 55.3648
hp: 56.78092
hp: 58.34243
hp: 59.39455
hp: 60.57467
hp: 61.74545
hp: 62.86186
hp: 64.13189
hp: 65.37547
hp: 67.03042
hp: 67.88847
hp: 68.9938
hp: 69.91893
hp: 70.79873
hp: 71.7552
hp: 72.68343
hp: 73.34964
hp: 74.16785
hp: 74.87849
hp: 75.50638
hp: 76.19359
hp: 76.89402
hp: 77.26965
hp: 77.80202
hp: 78.23071
hp: 78.60365
hp: 78.97717
hp: 79.26752
hp: 79.56013
hp: 79.78877
hp: 79.90522
hp: 79.97715
hp: 80
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment