Skip to content

Instantly share code, notes, and snippets.

@kyubuns
Created December 11, 2020 03:16
Show Gist options
  • Save kyubuns/2dbe0024d762cee51c69e2a899ed1790 to your computer and use it in GitHub Desktop.
Save kyubuns/2dbe0024d762cee51c69e2a899ed1790 to your computer and use it in GitHub Desktop.
using System;
using System.Collections.Generic;
using System.Linq;
using AnimeTask;
using UniRx.Triggers;
using UniRx;
using UnityEngine;
using UnityEngine.UI;
using Anime = AnimeRx.Anime;
using Motion = AnimeRx.Motion;
namespace Sandbox
{
public class SandboxAnimation : MonoBehaviour
{
[SerializeField] List<Image> cards = new List<Image>();
[SerializeField] List<Text> debugText = new List<Text>();
private readonly ReactiveProperty<Image> _selectingCard = new ReactiveProperty<Image>(null);
private const float SelectingY = 50.0f;
public void Start()
{
foreach (var (card, text) in cards.Zip(debugText, Tuple.Create))
{
var cardRectTransform = card.GetComponent<RectTransform>();
card.OnPointerClickAsObservable().Subscribe(x => _selectingCard.Value = card).AddTo(card);
var gauge = new ReactiveProperty<float>(0f);
_selectingCard
.Select(x =>
{
var isSelecting = x == card;
var target = isSelecting ? 1.0f : 0.0f;
var speed = isSelecting ? 1.0f : 2.0f; // 戻る時は2倍速
card.color = isSelecting ? Color.yellow : Color.white;
return Anime.Play(gauge.Value, target, Motion.Uniform(speed));
})
.Switch()
.Subscribe(x => gauge.Value = x);
gauge
.Subscribe(x =>
{
text.text = $"{x:0.0}";
})
.AddTo(card);
gauge
.Subscribe(x =>
{
var p = cardRectTransform.localPosition;
p.y = OutCirc.Calc(x) * SelectingY;
cardRectTransform.localPosition = p;
})
.AddTo(card);
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment