-
-
Notifications
You must be signed in to change notification settings - Fork 36
Gallery
kyubuns edited this page Apr 1, 2021
·
34 revisions
AnimeTaskの使用例を紹介します。
動きだけでなく、ソースコードの美しさも併せてご覧ください。
#AnimeTaskGallery
「AnimeTaskでこういうアニメーションはどう書くの?」
「こういうのは出来るの?」
というお題、挑戦状、受付中です。
twitterへのリプライか、メッセージフォームからどうぞ。
MIT LICENSE will be applied to this code as well as the AnimeTask itself.
await UniTask.WhenAll(
Easing.Create<InQuart>(start: 0f, end: 1f, duration: 0.2f).ToLocalScaleY(square),
Easing.Create<InQuart>(start: 0f, end: 1f, duration: 0.2f).ToColorA(square)
);
await Easing.Create<InQuart>(to: 30f, duration: 0.5f).ToAnchoredPositionX(text);
await Easing.Create<Linear>(to: -30f, duration: 1f).ToAnchoredPositionX(text);
await Easing.Create<OutQuart>(to: -2000f, duration: 0.5f).ToAnchoredPositionX(text);
await UniTask.WhenAll(
Easing.Create<OutQuart>(start: 1f, end: 0f, duration: 0.2f).ToLocalScaleY(square),
Easing.Create<OutQuart>(start: 1f, end: 0f, duration: 0.2f).ToColorA(square)
);
foreach (var text in texts)
{
var cancellationToken = text.GetAnimationCanceller().Token;
UniTask.Create(async () =>
{
while (true)
{
cancellationToken.ThrowIfCancellationRequested();
text.text = Random.Range(0, 10).ToString();
await UniTask.Yield(cancellationToken: cancellationToken);
}
}).Forget();
}
await Anime.Delay(1f);
foreach (var text in texts)
{
text.GetAnimationCanceller().Cancel();
text.color = prefabs.White;
text.text = Random.Range(0, 10).ToString();
await Easing.Create<InQuart>(to: 1.5f, duration: 0.1f)
.Concat(Easing.Create<OutQuart>(to: 1f, duration: 0.1f))
.ToLocalScale(text);
await Anime.Delay(1f);
}
await Easing.Create<OutQuart>(to: 1f, duration: 0.3f).ToLocalScaleY(one);
await Anime.Delay(0.2f);
await Easing.Create<InOutQuart>(to: 0.3f, duration: 0.3f).ToLocalScale(one);
await Anime.Delay(0.2f);
await UniTask.WhenAll(
Easing.Create<OutQuart>(to: -200f, duration: 0.3f).ToLocalPositionX(one),
UniTask.Create(async () =>
{
await Anime.Delay(0.1f);
f.color = r.color = Color.white;
await UniTask.WhenAll(
Easing.Create<OutQuart>(start: -250f, end: -400f, duration: 0.1f).ToLocalPositionX(f),
Easing.Create<OutQuart>(start: -150f, end: 0f, duration: 0.1f).ToLocalPositionX(r)
);
await Anime.Delay(0.05f);
s.color = Color.white;
await Easing.Create<OutQuart>(start: 150f, end: 200f, duration: 0.05f).ToLocalPositionX(s);
t.color = Color.white;
await Easing.Create<OutQuart>(start: 350f, end: 400f, duration: 0.05f).ToLocalPositionX(t);
})
);
async UniTask Animation(Disc disc, int i, float start, float end)
{
await Easing.Create<InOutQuart>(start, end, duration: 1f)
.Convert(x =>
{
var r = x * Mathf.PI + (Mathf.PI * 2.0f / 8f) * i;
return new Vector3(Mathf.Sin(r), Mathf.Cos(r), 0.0f) * x * 3f;
})
.ToLocalPosition(disc);
}
var discs = Enumerable.Range(0, 8).Select(x => prefabs.CreateDisc()).ToArray();
await UniTask.WhenAll(discs.Select((disc, i) => Animation(disc, i, start: 0f, end: 1f)));
await UniTask.Delay(TimeSpan.FromSeconds(0.25));
await UniTask.WhenAll(discs.Select((disc, i) => Animation(disc, i, start: 1f, end: 0f)));
await UniTask.Delay(TimeSpan.FromSeconds(0.25));
await Enumerable.Range(0, 32).Select((x, i) => UniTask.Create(async () =>
{
await Anime.Delay(i * 0.1f);
var disc = prefabs.CreateDisc(Vector3.zero);
await Moving.Gravity(
velocity: new Vector3(Random.Range(-xRange, xRange), Random.Range(yRangeMin, yRangeMax)),
acceleration: Vector3.down * 9.8f,
duration: 3f
).ToLocalPosition(disc);
}));
public class RandomMoveAnimator : IAnimator<Vector3>
{
public (Vector3, float) Update(float time)
{
const float duration = 2f;
var value = Random.insideUnitCircle;
return (value, Mathf.Min(time, duration));
}
}
var disc = prefabs.CreateDisc(Vector3.zero);
await new RandomMoveAnimator().ToLocalPosition(disc);
var blocks = Enumerable.Range(-5, 10).SelectMany(x =>
{
return Enumerable.Range(-4, 8).Select(y =>
{
return prefabs.CreateSquare(new Vector3(x, y, 0f));
});
}).ToArray();
var closeAnimation = Easing.Create<OutElastic>(start: 0f, end: 1f, duration: 1f);
await blocks.Shuffle().Select((x, i) => Animator.Delay<float>(i * 0.03f).Concat(closeAnimation).ToLocalScale(x));
var openAnimation = Easing.Create<OutQuart>(start: 1f, end: 0f, duration: 1f);
await blocks.Shuffle().Select((x, i) => Animator.Delay<float>(i * 0.03f).Concat(openAnimation).ToLocalScale(x));
await Enumerable.Range(0, 8).Select(x =>
UniTask.Create(async () =>
{
await Anime.Delay(Random.Range(0, 1f));
var position = Random.insideUnitCircle * 300f;
var text = prefabs.CreateText(Random.Range(1, 100).ToString(), position);
text.fontSize = 40;
await Easing.Create<InQuart>(start: 1.5f, end: 1.0f, duration: 0.2f).ToLocalScale(text);
await Anime.Delay(0.8f);
await UniTask.WhenAll(
Easing.Create<Linear>(to: position.y + 60f, duration: 0.2f).ToLocalPositionY(text),
Easing.Create<Linear>(to: 0f, duration: 0.2f).ToColorA(text)
);
})
);
await texts.Select((text, i) => UniTask.Create(async () =>
{
await Anime.Delay(i * 0.1f);
await Easing.Create<OutQuart>(to: 125f, duration: 0.1f).ToLocalPositionY(text);
await Easing.Create<OutBounce>(to: 0f, duration: 0.3f).ToLocalPositionY(text);
}));
await rectangles.Select(
rectangle => Easing.Create<OutQuart>(Vector3.zero, duration: l => l / 10f).ToLocalPosition(rectangle)
);
await UniTask.Delay(TimeSpan.FromSeconds(0.2));
await rectangles.Zip(randomPositions, ValueTuple.Create).Select(
x => Easing.Create<OutQuart>(x.Item2, duration: l => l / 10f).ToLocalPosition(x.Item1)
);
await UniTask.Delay(TimeSpan.FromSeconds(0.2));
var hp = new FloatReactiveProperty(maxHp);
var displayHp = new FloatReactiveProperty(hp.Value);
hp.Zip(hp.Skip(1), ValueTuple.Create).SubscribeTask(async (x, cancellationToken) =>
{
displayHp.Value = x.Item1;
await UniTask.Delay(TimeSpan.FromSeconds(0.2f), cancellationToken: cancellationToken);
await Easing.Create<Linear>(to: x.Item2, duration: 0.4f).ToReactiveProperty(displayHp, cancellationToken);
});
hp.Subscribe(x => image.fillAmount = x / maxHp).AddTo(image);
displayHp.Subscribe(x => red.fillAmount = x / maxHp).AddTo(red);
await Anime.Delay(0.3f);
hp.Value = 80;
await Anime.Delay(0.9f);
hp.Value = 50;
await Anime.Delay(0.9f);
hp.Value = 0;
await Anime.Delay(0.9f);
hp.Value = 100;
await Anime.Delay(0.9f);
await texts.Select((text, i) => UniTask.Create(async () =>
{
var y = startY - i * spacing;
await UniTask.Delay(TimeSpan.FromSeconds(i * 0.2f));
await UniTask.WhenAll(
Easing.Create<OutQuart>(start: y - 200f, end: y, duration: 1f).ToAnchoredPositionY(text),
Easing.Create<OutQuart>(start: 0f, end: 1f, duration: 1f).ToColorA(text)
);
}));
await UniTask.Delay(TimeSpan.FromSeconds(1));
await Easing.Create<InQuart>(start: 0f, end: 1f, duration: 0.5f).ToColorA(square);
foreach (var text in texts) GameObject.Destroy(text);
await UniTask.Delay(TimeSpan.FromSeconds(0.5));
await Easing.Create<OutQuart>(start: 1f, end: 0f, duration: 0.5f).ToColorA(square);
await Enumerable.Range(0, 256).Select(async i =>
{
var disc = prefabs.CreateDisc();
var r = Random.Range(0f, Mathf.PI * 2f);
var x = Random.Range(-6f, 6f);
var startY = Random.Range(-12f, -7f);
var endY = Random.Range(2f, 8f);
var duration = Random.Range(2f, 4f);
await UniTask.WhenAll(
Easing.Create<InQuart>(start: r, end: r + Mathf.PI * 2f, duration).Convert(p => Mathf.Sin(p) + x).ToLocalPositionX(disc),
Easing.Create<InQuart>(start: startY, end: endY, duration).ToLocalPositionY(disc),
Easing.Create<InQuart>(start: 1f, end: 0f, duration).ToColorA(disc)
);
});
var animations = new List<UniTask>();
for (var x = 0; x < 8; ++x)
{
for (var y = 0; y < 6; ++y)
{
var rectangle = prefabs.CreateRectangle(
position: new Vector3(x * (width + margin), -y * (height + margin), 0f),
size: new Vector2(baseSize, baseSize)
);
var delay = TimeSpan.FromSeconds((x + y) * 0.1f);
animations.Add(UniTask.Create(async () =>
{
await UniTask.Delay(delay);
await UniTask.WhenAll(
Easing.Create<OutBounce>(width, 0.5f).ToLocalScaleX(rectangle),
Easing.Create<OutBounce>(height, 0.5f).ToLocalScaleY(rectangle)
);
await UniTask.Delay(TimeSpan.FromSeconds(1));
await UniTask.WhenAll(
Easing.Create<InQuart>(baseSize, 0.5f).ToLocalScaleX(rectangle),
Easing.Create<InQuart>(baseSize, 0.5f).ToLocalScaleY(rectangle)
);
}));
}
}
await animations;
IEnumerable<UniTask> MenuCategoryAnimation(Vector1EasingAnimator baseAnimation)
{
return categories.Select((x, i) =>
{
var distance = (i + 1) * 1.5f;
return baseAnimation
.Convert(d => startX + Mathf.Min(d, distance))
.ToLocalPositionX(x);
});
}
var maxDistance = (categoryNum + 1) * 1.5f;
var openAnimation = Easing.Create<InOutQuart>(start: 0f, end: maxDistance, duration: 0.6f);
await MenuCategoryAnimation(openAnimation);
await UniTask.Delay(TimeSpan.FromSeconds(0.4));
var closeAnimation = Easing.Create<InOutQuart>(start: maxDistance, end: 0f, duration: 0.6f);
await MenuCategoryAnimation(closeAnimation);
await UniTask.Delay(TimeSpan.FromSeconds(0.4));
await Easing.Create<InQuart>(to: 0.8f, duration: 0.1f).ToLocalScale(button);
await UniTask.Delay(TimeSpan.FromSeconds(0.5));
await Easing.Create<OutElastic>(to: 1f, duration: 0.4f).ToLocalScale(button);
await Easing.Create<OutQuad>(start: -9f, end: -4f, duration: 0.5f).ToLocalPositionX(rectangle);
await UniTask.WhenAll(
Easing.Create<InQuad>(start: -4f, end: 4f, duration: 0.5f).ToLocalPositionX(rectangle),
Easing.Create<InQuad>(start: 1f, end: 0.5f, duration: 0.5f).ToLocalScaleX(rectangle),
Easing.Create<InQuad>(start: 1f, end: 4f, duration: 0.5f).ToLocalScaleY(rectangle)
);
await Easing.Create<InQuad>(start: 4f, end: 9f, duration: 0.5f).ToLocalPositionX(rectangle);
var score = new IntReactiveProperty(0);
score.SubscribeToText(targetText, x => $"Target: {x:0000}");
var displayScore = new FloatReactiveProperty(0f);
displayScore.SubscribeToText(scoreText, x => $"Score: {x:0000}");
score.SubscribeTask(async (x, cancellationToken) =>
{
await Easing.Create<Linear>(to: x, duration: 0.5f).ToReactiveProperty(displayScore, cancellationToken);
});
await Anime.Delay(0.5f);
score.Value = 100;
await Anime.Delay(0.75f);
score.Value = 1000;
await Anime.Delay(0.75f);
score.Value = 5000;
await Anime.Delay(0.3f);
score.Value = 0;
await Anime.Delay(0.5f);
while (true)
{
await Easing.Create<InCubic>(to: 0f, duration: 0.3f).ToColorA(rectangle);
await Easing.Create<OutCubic>(to: 1f, duration: 0.3f).ToColorA(rectangle);
}
await UniTask.WhenAll(
Enumerable.Range(1, 8)
.Select(async i =>
{
var disc = prefabs.CreateDisc(new Vector3(0f, 3f));
await Anime.Delay(i * 0.1f);
await Easing.Create<InOutCubic>(0.0f, Mathf.PI * 2.0f, 2f)
.Convert(x => new Vector3(Mathf.Sin(x), Mathf.Cos(x), 0.0f) * 3.0f)
.ToLocalPosition(disc);
})
);
await Easing.Create<OutBounce>(start: -4f, end: 4f, duration: 1f).ToLocalPositionX(rectangle);
await Easing.Create<OutBounce>(to: -4f, duration: 1f).ToLocalPositionX(rectangle);