public void SpinToElement(SlotElement se, int circlesAmmount)
        {
            SlotElement needElem = null;

            foreach (SlotElement elem in Elements)
            {
                if (elem.OriginCode == se.OriginCode)
                {
                    needElem = elem;
                    break;
                }
            }

            Vector3 pos = needElem.transform.position;

            pos = transform.InverseTransformPoint(pos);
            float needDistance = -pos.y;

            Vector3 needOffset = new Vector3(0, needDistance, 0);

            needOffset   = transform.TransformVector(needOffset);
            needDistance = needOffset.y;

            needDistance += circlesAmmount * Elements.Length * Size.y;
            StartCoroutine(SpinToElementCor(0.005f, 0.0005f, Size.y / 4, needDistance, needElem));
        }
        public void SetPictures(Sprite[] sprites, Vector2 size)
        {
            Size         = size;
            VerticalStep = new Vector3(0, size.y, 0);
            LocalVerStep = transform.InverseTransformVector(VerticalStep);

            int elemQuan = sprites.Length;

            Elements = new SlotElement[elemQuan];

            for (int i = 0; i < elemQuan; i++)
            {
                GameObject  slotElem = GameObject.Instantiate(ElementPrefab, transform);
                SlotElement se       = slotElem.GetComponent <SlotElement>();
                se.SR.sprite  = sprites[i];
                se.OriginCode = CodeGenerator.Generate(sprites[i]);

                Vector3[] spritePoints = SizeAndPositionFinder.GetSpriteBorderPoints(se.SR);
                SizeAndPositionFinder.CalculateSpriteSizes(spritePoints, out float xDist, out float yDist, out Vector3 s);

                Vector2 pictureSize = new Vector2(xDist, yDist);
                Vector3 needSize    = size / pictureSize;
                se.transform.localScale = needSize;

                se.transform.position += new Vector3(0, i * size.y, 0);

                Elements[i] = se;
            }

            LocalUpBorder   = Vector3.zero + LocalVerStep;
            LocalDownBorder = Vector3.zero - LocalVerStep;
        }
        private IEnumerator SpinToElementCor(float accel, float decel, float speedLimit, float distance, SlotElement se)
        {
            float speed = 0;
            int   sign  = distance > 0 ? 1 : -1;

            while (Mathf.Abs(distance) > 0.001f)
            {
                AcceleratedMoveTools.HandleSpeed(distance * sign, accel, decel, speedLimit, ref speed);
                Spin(speed * Time.deltaTime * 100);
                distance -= speed * Time.deltaTime * 100 * sign;

                yield return(null);
            }
            float y = se.transform.localPosition.y;

            Spin(-y, true);

            if (SlotStopped != null)
            {
                SlotStopped.Invoke();
            }
        }