Ejemplo n.º 1
0
        void TrackCollision(CollisionData data)
        {
            Log.Message("Отслеживание коллизии.");
            var checker = new OrbDoubleCollisionChecker(data);

            if (waitForLateUpdateRoutine != null)
            {
                return;
            }

            waitForLateUpdateRoutine           = new CommonCoroutine(this, WaitForLateUpdate);
            waitForLateUpdateRoutine.OnFinish += () =>
            {
                if (checker.DoubleCollision)
                {
                    DoubleCollision(checker.Collision_1, checker.Collision_2);
                }
                else
                {
                    SingleCollision(checker.Collision_1);
                }

                waitForLateUpdateRoutine = null;
                OrbDoubleCollisionChecker.ClearCollisionData();
            };

            Log.Message("Запуск корутины ожидания.");
            waitForLateUpdateRoutine.Start();
        }
Ejemplo n.º 2
0
        public void Flash(bool match)
        {
            Log.Message("Запуск анимации мигания объекта: " + name);

            if (flashingDoubleShotRoutine != null)
            {
                Log.Message("Произведена попытка запуска двойной анимации мигания. Прошлая еще не завершила свое действие.");
                return;
            }

            Color          flashColor     = match ? matchedColor : mismatchedColor;
            SpriteRenderer spriteRenderer = GetComponent <SpriteRenderer>();

            flashingDoubleShotRoutine           = new CommonCoroutine(this, () => FlashDoubleShot(spriteRenderer, flashColor));
            flashingDoubleShotRoutine.OnFinish += () => flashingDoubleShotRoutine = null;
            flashingDoubleShotRoutine.Start();
        }
Ejemplo n.º 3
0
        IEnumerator Rotate(Transform formTransform, float angleY, float angleZ, float rotationSpeed)
        {
            Log.Message("Начало вращения.");

            var targetRotation = formTransform.rotation * Quaternion.Euler(0.0f, angleY, angleZ);

            for (float T = 0.00f;
                 Quaternion.Angle(formTransform.rotation, targetRotation) > 0.1f;
                 T += rotationSpeed * Time.deltaTime)
            {
                formTransform.rotation = Quaternion.Lerp(formTransform.rotation, targetRotation, T);
                yield return(new WaitForEndOfFrame());
            }

            formTransform.rotation = targetRotation;

            rotationRoutine = null;
            Log.Message("Конец вращения.");
        }
Ejemplo n.º 4
0
        IEnumerator FlashDoubleShot(SpriteRenderer spriteRenderer, Color targetColor)
        {
            Log.Message("Начало двойной анимации мигания.");

            var startColor = spriteRenderer.color;

            flashingOneShotRoutine = new CommonCoroutine(this, () => FlashOneShot(spriteRenderer, targetColor));
            flashingOneShotRoutine.Start();

            yield return(new WaitWhile(() => flashingOneShotRoutine.IsRunning));

            flashingOneShotRoutine = new CommonCoroutine(this, () => FlashOneShot(spriteRenderer, startColor));
            flashingOneShotRoutine.Start();

            yield return(new WaitWhile(() => flashingOneShotRoutine.IsRunning));

            flashingOneShotRoutine = null;
            Log.Message("Конец двойной анимации мигания.");
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Вращение объекта. Положительный угол оси Z соответствует вращению по часовой стрелке.
        /// </summary>
        public void RotateByAngle(
            Transform formTransform,
            float angleY        = 0,
            float angleZ        = 0,
            float rotationSpeed = 1,
            Action OnFinish     = null)
        {
            if (rotationRoutine != null)
            {
                Log.Message("Корутина вращения уже запущена.");
                return;
            }

            Log.Message($"Вращение формы на углы: Y = {angleY}, Z = {angleZ}");

            //-angleZ, чтобы вращался по часовой. Привычно для понимания
            rotationRoutine           = new CommonCoroutine(this, () => Rotate(formTransform, angleY, -angleZ, rotationSpeed));
            rotationRoutine.OnFinish += OnFinish;
            rotationRoutine.OnFinish += () => rotationRoutine = null;
            rotationRoutine.Start();
        }