Example #1
0
        public async UniTask Sample09()
        {
            using (var cubes = new SampleCubes(new Vector3(-5f, 0f, 0f)))
            {
                await UniTask.Delay(TimeSpan.FromSeconds(1));

                var a = Animator.Concat(
                    Easing.Create <OutCubic>(-5f, 0f, 2f),
                    Animator.Delay <float>(1f),
                    Easing.Create <OutCubic>(0f, 5f, 2f)
                    );

                await UniTask.WhenAll(
                    a.Convert(x => new Vector3(x, 0f, 0f)).ToLocalPosition(cubes[0]),
                    a.Convert(x => Vector3.one *Mathf.Abs(x)).ToLocalScale(cubes[0])
                    );

                await Easing.Create <OutCubic>(5f, 0f, 2f)
                .Delay(1f)
                .Concat(Easing.Create <OutCubic>(0f, -5f, 2f))
                .Convert(x => new Vector3(x, 0f, 0f))
                .ToLocalPosition(cubes[0]);

                await UniTask.Delay(TimeSpan.FromSeconds(1));
            }
        }
Example #2
0
        private static async UniTask Sample4()
        {
            using (var shapeObject = new DisposableGameObject(new Vector3(-3f, 0f, 0f)))
            {
                var shape = shapeObject.AddComponent <Rectangle>();
                shape.Type      = Rectangle.RectangleType.RoundedHollow;
                shape.Color     = new Color32(255, 242, 173, 255);
                shape.Thickness = 0.1f;

                var cube = shape;

                await Anime.Delay(0.3f);

                await UniTask.WhenAll(
                    Anime.PlayTo(
                        Moving.Linear(3f, 2f),
                        TranslateTo.LocalPositionX(cube)
                        ),
                    Anime.PlayTo(
                        Animator.Delay(1.8f, Easing.Create <Linear>(Vector3.zero, 0.2f)),
                        TranslateTo.LocalScale(cube)
                        )
                    );

                await Anime.Delay(0.3f);
            }
        }
Example #3
0
        private async UniTask CircleAnimation(GameObject go, float delay)
        {
            await UniTask.Delay(TimeSpan.FromSeconds(delay));

            await Easing.Create <OutCubic>(0.0f, Mathf.PI * 2.0f, 2f)
            .Convert(x => new Vector3(Mathf.Sin(x), Mathf.Cos(x), 0.0f) * 3.0f)
            .ToLocalPosition(go);
        }
Example #4
0
        public async UniTask Sample13()
        {
            using (var cubes = new SampleCubes(new Vector3(-5f, 0f, 0f)))
            {
                await UniTask.Delay(TimeSpan.FromSeconds(1));

                var skipTokenSource = new SkipTokenSource();
                Easing.Create <OutCubic>(new Vector3(5f, 0f, 0f), 5f).ToLocalPosition(cubes[0], default, skipTokenSource.Token).Forget();
Example #5
0
        public async UniTask FlashAsync(CancellationToken ct)
        {
            var material      = photoCameraView.CameraMonitor.material;
            var originalColor = material.GetColor(EmissionColor);
            await Easing.Create <InSine>(originalColor, Color.black, photoCameraView.FlashDuration)
            .ToAction(color => material.SetColor(EmissionColor, color), ct);

            material.SetColor(EmissionColor, originalColor);
        }
Example #6
0
        private async UniTask CircleTestElement(Component go, float delay)
        {
            await Anime.Delay(delay);

            await Anime.Play(
                Animator.Convert(Easing.Create <OutCubic>(0.0f, Mathf.PI * 2.0f, 2f),
                                 x => new Vector3(Mathf.Sin(x), Mathf.Cos(x), 0.0f) * 3.0f),
                TranslateTo.LocalPosition(go)
                );
        }
Example #7
0
    private async UniTask MainGameFlow()
    {
        var titleUi  = new TitleUiElements(titleUiCache);
        var quizUi   = new QuizUiElements(quizUiCache);
        var resultUi = new ResultUiElements(resultUiCache);

        while (true)
        {
            titleUi.Root.SetActive(true);
            quizUi.Root.SetActive(false);
            resultUi.Root.SetActive(false);

            // Title

            var origin = titleUi.TitleText.rectTransform.anchoredPosition;
            await Easing.Create <OutBounce>(origin + new Vector2(0f, 600f), origin, 0.5f).ToAnchoredPosition(titleUi.TitleText);

            await titleUi.StartButton.OnClickAsync();

            titleUi.Root.SetActive(false);
            quizUi.Root.SetActive(true);

            // Quiz

            quizUi.QuizText.text = "6 * 4 = ";
            var buttonClick = new UniTaskCompletionSource <int>();
            using (var editor = quizUi.SelectList.Edit())
            {
                for (var i = 0; i < 100; i++)
                {
                    var i1 = i;
                    editor.Contents.Add(new UIFactory <SelectButtonUiElements>(x =>
                    {
                        x.Text.text = $"{i1}";
                        x.Button.onClick.AddListener(() => buttonClick.TrySetResult(i1));
                    }));
                }
            }

            var index = await buttonClick.Task;

            quizUi.Root.SetActive(false);
            resultUi.Root.SetActive(true);

            // Result

            resultUi.Circle.SetActive(index == 24);
            resultUi.Cross.SetActive(index != 24);

            var animator = Easing.Create <OutBounce>(Vector3.one * 5f, Vector3.one, 0.5f);
            await UniTask.WhenAll(animator.ToLocalScale(resultUi.Circle), animator.ToLocalScale(resultUi.Cross));

            await resultUi.ReturnButton.OnClickAsync();
        }
    }
Example #8
0
        private async UniTask LineTestElement()
        {
            const byte colorA = 64;

            /*
             * var colors = new[]
             * {
             *  // 114
             *  new Color32(78, 191, 214, colorA),
             *  new Color32(0, 85, 149, colorA),
             *  new Color32(25, 36, 74, colorA),
             *  new Color32(87, 189, 168, colorA),
             *  new Color32(246, 249, 228, colorA),
             *  new Color32(0, 0, 0, colorA),
             *  new Color32(162, 67, 137, colorA),
             *  new Color32(229, 230, 71, colorA),
             * };
             */
            var colors = new[]
            {
                new Color32(255, 0, 0, colorA),
                new Color32(0, 255, 0, colorA),
                new Color32(0, 0, 255, colorA),
                new Color32(255, 255, 0, colorA),
                new Color32(255, 0, 255, colorA),
                new Color32(0, 255, 255, colorA),
            };

            var unitCircle = Random.insideUnitCircle.normalized * Random.Range(2f, 8f);

            using (var shapeObject = new DisposableGameObject(
                       new Vector3(unitCircle.x, unitCircle.y, 50f)
                       ))
            {
                var shape = shapeObject.AddComponent <Line>();
                shape.Geometry  = LineGeometry.Volumetric3D;
                shape.BlendMode = ShapesBlendMode.Additive;
                shape.Color     = colors[Random.Range(0, colors.Length)];
                shape.Start     = new Vector3(0f, 0f, 0f);
                shape.End       = new Vector3(0f, 0f, Random.Range(4f, 10f));
                shape.Thickness = Random.Range(0.1f, 1.0f);

                await UniTask.WhenAll(
                    Anime.PlayTo(
                        Easing.Create <OutCubic>(-20f, Random.Range(1f, 3f)),
                        TranslateTo.LocalPositionZ(shape)
                        ),
                    Anime.Play(
                        Easing.Create <InCubic>(Vector3.zero, Vector3.one, 0.15f),
                        TranslateTo.LocalScale(shape)
                        )
                    );
            }
        }
Example #9
0
        public async UniTask Sample01()
        {
            using (var cubes = new SampleCubes(new Vector3(-5f, 0f, 0f)))
            {
                await UniTask.Delay(TimeSpan.FromSeconds(1));

                await Easing.Create <OutCubic>(new Vector3(5f, 0f, 0f), 2f).ToLocalPosition(cubes[0]);

                await UniTask.Delay(TimeSpan.FromSeconds(1));
            }
        }
Example #10
0
        private async Task CircleAnimation(GameObject go, float delay)
        {
            await Anime.Delay(delay);

            await Anime.Play(
                Easing.Create <OutCubic>(0.0f, Mathf.PI * 2.0f, 2f),
                TranslateTo.Action <float>(x =>
            {
                var p = new Vector3(Mathf.Sin(x), Mathf.Cos(x), 0.0f) * 3.0f;
                go.transform.localPosition = p;
            }));
        }
Example #11
0
        public async UniTask Sample05()
        {
            using (var cubes = new SampleCubes(new Vector3(-5f, 0f, 0f)))
            {
                await UniTask.Delay(TimeSpan.FromSeconds(1));

                await UniTask.WhenAll(
                    Easing.Create <OutCubic>(Quaternion.identity, Quaternion.Euler(30f, 0f, 0f), 0.5f).ToGlobalRotation(cubes[0])
                    );

                await UniTask.Delay(TimeSpan.FromSeconds(1));
            }
        }
Example #12
0
        public async Task Sample01()
        {
            using (var cubes = new SampleCubes(new Vector3(-5f, 0f, 0f)))
            {
                await Anime.Delay(1f);

                await Anime.PlayTo(
                    Easing.Create <OutCubic>(new Vector3(5f, 0f, 0f), 2f),
                    TranslateTo.LocalPosition(cubes[0])
                    );

                await Anime.Delay(1f);
            }
        }
Example #13
0
        public async UniTask Sample04()
        {
            using (var cubes = new SampleCubes(new Vector3(-5f, 0f, 0f)))
            {
                await UniTask.Delay(TimeSpan.FromSeconds(1));

                await UniTask.WhenAll(
                    Moving.Linear(2f, 2f).ToLocalPositionX(cubes[0]),
                    Animator.Delay <Vector3>(1.8f).Concat(Easing.Create <Linear>(Vector3.zero, 0.2f)).DebugLog().ToLocalScale(cubes[0])
                    );

                await UniTask.Delay(TimeSpan.FromSeconds(1));
            }
        }
Example #14
0
        public async UniTask Sample10()
        {
            using (var cubes = new SampleCubes(new Vector3(0f, 0f, 0f), new Vector3(0f, 1f, 0f)))
            {
                await UniTask.Delay(TimeSpan.FromSeconds(1));

                var moveAnimation = Easing.Create <Linear>(0f, 5f, 2f);
                await UniTask.WhenAll(
                    moveAnimation.ToLocalPositionX(cubes[0]),
                    moveAnimation.RelativeDelay(-0.5f).Concat(moveAnimation).ToLocalPositionX(cubes[1])
                    );

                await UniTask.Delay(TimeSpan.FromSeconds(1));
            }
        }
Example #15
0
        public async UniTask Sample08()
        {
            using (var cubes = new SampleCubes(new Vector3(-5f, -1f, 0f), new Vector3(0f, 1f, 0f)))
            {
                await UniTask.Delay(TimeSpan.FromSeconds(1));

                var a = Easing.Create <OutCubic>(new Vector3(5f, 0f, 0f), 2f);
                await UniTask.WhenAll(
                    a.ToLocalPosition(cubes[0]),
                    a.ToLocalPosition(cubes[1])
                    );

                await UniTask.Delay(TimeSpan.FromSeconds(1));
            }
        }
Example #16
0
        public async UniTask Sample03()
        {
            using (var cubes = new SampleCubes(new Vector3(-5f, 0f, 0f)))
            {
                await UniTask.Delay(TimeSpan.FromSeconds(1));

                CancellationTokenSource cancellationTokenSource = new CancellationTokenSource();
                cancellationTokenSource.Token.Register(() => Debug.Log("Cancel"));
                cancellationTokenSource.CancelAfter(500);

                await Easing.Create <OutCubic>(new Vector3(5f, 0f, 0f), 2f).ToLocalPosition(cubes[0], cancellationTokenSource.Token);

                await UniTask.Delay(TimeSpan.FromSeconds(1), cancellationToken : cancellationTokenSource.Token);
            }
        }
Example #17
0
        public async UniTask Sample07()
        {
            using (var cubes = new SampleCubes(new Vector3(-5f, 0f, 0f)))
            {
                await UniTask.Delay(TimeSpan.FromSeconds(1));

                var a = Easing.Create <OutCubic>(new Vector3(-5f, 0f, 0f), new Vector3(5f, 0f, 0f), 2f);
                await UniTask.WhenAll(
                    a.ToLocalPosition(cubes[0]),
                    a.Convert(x => Vector3.one *Mathf.Abs(x.x)).ToLocalScale(cubes[0])
                    );

                await UniTask.Delay(TimeSpan.FromSeconds(1));
            }
        }
Example #18
0
        public async Task Sample03()
        {
            using (var cubes = new SampleCubes(new Vector3(-5f, 0f, 0f)))
            {
                await Anime.Delay(1f);

                CancellationTokenSource cancellationTokenSource = new CancellationTokenSource();
                cancellationTokenSource.Token.Register(() => Debug.Log("Cancel"));
                cancellationTokenSource.CancelAfter(500);

                await Anime.PlayTo(
                    Easing.Create <OutCubic>(new Vector3(5f, 0f, 0f), 2f),
                    TranslateTo.LocalPosition(cubes[0]),
                    cancellationTokenSource.Token
                    );

                await Anime.Delay(1f);
            }
        }
Example #19
0
        public async Task Sample04()
        {
            using (var cubes = new SampleCubes(new Vector3(-5f, 0f, 0f)))
            {
                await Anime.Delay(1f);

                await UniTask.WhenAll(
                    Anime.PlayTo(
                        Moving.Linear(2f, 2f),
                        TranslateTo.LocalPositionX(cubes[0])
                        ),
                    Anime.PlayTo(
                        Animator.Delay(1.8f, Easing.Create <Linear>(Vector2.zero, 0.2f)),
                        TranslateTo.LocalScale(cubes[0])
                        )
                    );

                await Anime.Delay(1f);
            }
        }
Example #20
0
        private static async UniTask Sample3()
        {
            using (var shapeObject = new DisposableGameObject(new Vector3(1f, -2f, 0f)))
            {
                var shape = shapeObject.AddComponent <Rectangle>();
                shape.Type      = Rectangle.RectangleType.RoundedHollow;
                shape.Color     = new Color32(255, 242, 173, 255);
                shape.Thickness = 0.1f;

                var cube = shape;

                await Anime.Delay(0.3f);

                await Anime.PlayTo(
                    Easing.Create <InCubic>(new Vector3(-5f, 3f, 0f), 2f),
                    TranslateTo.LocalPosition(cube)
                    );

                await Anime.Delay(0.3f);
            }
        }
Example #21
0
        private static async UniTask ExplosionTestElement()
        {
            using (var shapeObjects = new DisposableGameObject(Vector3.zero))
            {
                var shape = shapeObjects.AddComponent <Disc>();
                shape.Type      = Disc.DiscType.Ring;
                shape.Color     = new Color32(255, 242, 173, 255);
                shape.Radius    = 0.3f;
                shape.Thickness = 0.1f;

                const float rangeMin = 1f;
                const float rangeMax = 3f;
                var         v        = Random.insideUnitCircle.normalized * Random.Range(rangeMin, rangeMax);

                const float duration      = 1f;
                const float eraseDuration = 0.5f;
                await Anime.Delay(0.5f);

                await UniTask.WhenAll(
                    Anime.PlayTo(
                        Easing.Create <OutExpo>(
                            new Vector3(v.x, v.y, 0f),
                            duration
                            ),
                        TranslateTo.LocalPosition(shape)
                        ),
                    Anime.Play(
                        Animator.Delay(duration - eraseDuration - 0.3f, Easing.Create <Linear>(1f, 0f, eraseDuration)),
                        TranslateTo.Action <float>(x =>
                {
                    var tmp     = shape.Color;
                    tmp.a       = x;
                    shape.Color = tmp;
                })
                        )
                    );
            }
        }
Example #22
0
        public async UniTask Sample06()
        {
            var p = Enumerable.Range(0, 11)
                    .Select(x => Enumerable.Range(0, 11).Select(y => new Vector3(x - 5f, y - 5f, 0)))
                    .SelectMany(x => x)
                    .ToArray();

            using (var cubes = new SampleCubes(p))
            {
                for (var i = 0; i < 5; ++i)
                {
                    await UniTask.WhenAll(
                        cubes.All.Select(x =>
                    {
                        var r  = x.GetComponent <MeshRenderer>();
                        var pb = new MaterialPropertyBlock();
                        r.GetPropertyBlock(pb);
                        return(Easing.Create <InOutCubic>(pb.GetColor(ShaderColor), UnityEngine.Random.ColorHSV(), 0.5f).ToMaterialPropertyColor(r, "_Color"));
                    })
                        );
                }
            }
        }
Example #23
0
        private static async UniTask Tweet1()
        {
            using (var shapeObjects = new DisposableGameObjectList(new[]
            {
                new Vector3(-5f, 0f),
                new Vector3(-2.5f, 0f),
                new Vector3(0.0f, 0f),
                new Vector3(2.5f, 0f),
                new Vector3(5f, 0f),
            }))

            {
                var shapes = shapeObjects.GameObjects.Select(x =>
                {
                    var shape              = x.AddComponent <Rectangle>();
                    shape.Type             = Rectangle.RectangleType.RoundedHollow;
                    shape.Width            = 1f;
                    shape.Height           = 1f;
                    shape.Color            = new Color32(255, 242, 173, 0);
                    shape.Thickness        = 0f;
                    shape.CornerRadiusMode = Rectangle.RectangleCornerRadiusMode.PerCorner;
                    shape.CornerRadiii     = Vector4.zero;
                    return(shape);
                }).ToArray();

                async UniTask Anime1(Rectangle shape, int index)
                {
                    await Anime.Delay(index * 0.2f);

                    await UniTask.WhenAll(
                        Anime.Play(
                            Easing.Create <OutSine>(0f, 0.15f, 0.5f),
                            TranslateTo.Action <float>(x => shape.Thickness = x)
                            ),
                        Anime.Play(
                            Easing.Create <OutSine>(0f, 1f, 0.1f),
                            TranslateTo.Action <float>(x =>
                    {
                        var tmp     = shape.Color;
                        tmp.a       = x;
                        shape.Color = tmp;
                    })
                            )
                        );

                    await Anime.Delay(0.5f);

                    for (var i = 0; i < 4; ++i)
                    {
                        const float duration = 0.3f;
                        await Anime.Play(
                            Easing.Create <InOutCubic>(0f, 0.5f, duration),
                            TranslateTo.Action <float>(x =>
                        {
                            var tmp = shape.CornerRadiii;
                            tmp[(i + index) % 4] = x;
                            shape.CornerRadiii   = tmp;
                        })
                            );

                        var tmp2 = shape.CornerRadiii;
                        tmp2[(i + index) % 4] = 100;
                        shape.CornerRadiii    = tmp2;
                    }
                }

                async UniTask Anime2(Rectangle shape, int index)
                {
                    const float duration = 1f;
                    await UniTask.WhenAll(
                        Anime.PlayTo(
                            Easing.Create <InOutExpo>(0f, duration),
                            TranslateTo.LocalPositionX(shape.gameObject)
                            )
                        );

                    if (index != 0)
                    {
                        await UniTask.WhenAll(
                            Anime.Play(
                                Easing.Create <OutSine>(1f, 0f, 0.1f),
                                TranslateTo.Action <float>(x =>
                        {
                            var tmp     = shape.Color;
                            tmp.a       = x;
                            shape.Color = tmp;
                        })
                                )
                            );
                    }
                }

                async UniTask Anime3(Rectangle shape)
                {
                    await Anime.Play(
                        Easing.Create <InOutExpo>(0.5f, 0f, 0.5f),
                        TranslateTo.Action <float>(x => shape.CornerRadiii = Vector4.one *x)
                        );

                    await Anime.Play(
                        Easing.Create <InOutExpo>(0f, -20f, 0.5f),
                        TranslateTo.Action <float>(x => shape.transform.localRotation = Quaternion.Euler(0f, 0f, x))
                        );

                    await Anime.Play(
                        Easing.Create <InCubic>(0f, -7f, 0.5f),
                        TranslateTo.LocalPositionY(shape.gameObject)
                        );
                }

                await UniTask.WhenAll(shapes.Select((x, i) => Anime1(x, i)));

                await Anime.Delay(0.25f);

                await UniTask.WhenAll(shapes.Select((x, i) => Anime2(x, i)));
                await Anime3(shapes[0]);

                await Anime.Delay(0.5f);
            }
        }