Example #1
0
        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;
        }
Example #2
0
        private SlotHandler[] SetSlots()
        {
            SlotHandler[] slotHandlers = new SlotHandler[SlotQuan];

            SpriteRenderer sr = SlotsHolder.GetComponent <SpriteRenderer>();

            Vector3[] points = SizeAndPositionFinder.GetSpriteBorderPoints(sr);

            SizeAndPositionFinder.CalculateSpriteSizes(points, out float width, out float height, out Vector3 start);
            Vector2 oneSlotSize = new Vector2(width / SlotQuan, height);

            GameObject slot = GameObject.Instantiate(SlotPrefab, SlotsHolder);

            slot.name = "Slot " + 1;
            slot.transform.position = start + new Vector3(oneSlotSize.x / 2, 0, 0);

            slotHandlers[0] = slot.GetComponent <SlotHandler>();
            slotHandlers[0].SetPictures(Pictures, oneSlotSize);

            for (int i = 1; i < SlotQuan; i++)
            {
                GameObject slotCopy = GameObject.Instantiate(slot, SlotsHolder);
                slotCopy.name = "Slot " + (i + 1);

                float xOffset = (i + 1) * oneSlotSize.x - (oneSlotSize.x / 2);
                slotCopy.transform.position = start + new Vector3(xOffset, 0, 0);

                slotHandlers[i] = slotCopy.GetComponent <SlotHandler>();
            }

            return(slotHandlers);
        }