Пример #1
0
    public void UpdatePrizesQuantityMenu()
    {
        GameObject newPrize;
        int        childIndex     = 0;
        int        filesInfoIndex = 0;
        float      imageSize      = imagePattern.GetComponent <Renderer>().bounds.extents.x * 290;

        if (slotMachineController.prizes.Length > 4)
        {
            RectTransform scrollViewRect = quantityScrollView.GetComponent <RectTransform>();
            scrollViewRect.sizeDelta = new Vector2(imageSize * slotMachineController.prizes.Length, Screen.height);
        }

        slotMachineController.prizeInputTextFieldDictionary = new Dictionary <GameObject, GameObject>();

        foreach (GameObject prize in slotMachineController.prizes)
        {
            SpriteRenderer prizeSpriteRenderer = prize.GetComponent <SpriteRenderer>();
            Texture2D      newTexture          = prizeSpriteRenderer.sprite.texture;
            Customization.LoadTexture2D(slotMachineController.customFolderDataPath + prize.name + ".png", newTexture);

            filesInfoIndex++;

            Rect       textRect = new Rect(0, 0, 350, 450);
            GameObject inputField;

            newPrize = Instantiate(prizeSpritePrefab) as GameObject;
            newPrize.transform.SetParent(quantityScrollView.transform, true);

            childIndex = quantityScrollView.transform.childCount;

            newPrize.name = "Prize Quantity " + childIndex.ToString();

            if (quantityScrollView.transform.childCount > 1)
            {
                Transform lastChild = quantityScrollView.transform.GetChild(childIndex - 2);
                newPrize.transform.SetParent(quantityScrollView.transform, true);
                newPrize.transform.position = new Vector3(lastChild.position.x + 360, lastChild.position.y, lastChild.position.z);
            }
            else
            {
                Camera  camera        = Camera.main;
                Vector3 screen        = new Vector3(0, Screen.height / 2, 10);
                Vector3 newCoordinate = camera.ScreenToWorldPoint(screen);
                newPrize.transform.position = new Vector3(newCoordinate.x + 160, Screen.height / 2, newCoordinate.z);
            }

            inputField      = Instantiate(prizeInputPrefab) as GameObject;
            inputField.name = "Input Field " + childIndex.ToString();
            inputField.transform.SetParent(newPrize.transform);
            inputField.GetComponent <InputSelector>().prizeIndex = childIndex - 1;

            slotMachineController.prizeInputTextFieldDictionary.Add(slotMachineController.prizes[childIndex - 1], inputField);

            RectTransform inputRectTransform = inputField.GetComponent <RectTransform>();
            inputRectTransform.localPosition = new Vector3(0, -240, 0);

            newPrize.GetComponent <Image>().sprite = Sprite.Create(newTexture, textRect, new Vector2(0.5f, 0.5f));
        }
    }
    private void GetSlotMachineSprite()
    {
        string         spritePath     = string.Format("{0}/background.png", customFolderDataPath);
        SpriteRenderer spriteRenderer = slotMachineSpriteGameObject.GetComponent <SpriteRenderer>();
        Texture2D      image          = null;

        if (File.Exists(spritePath))
        {
            image = new Texture2D(1920, 1080, TextureFormat.ARGB32, true);
            StartCoroutine(Customization.LoadTexture2D(spritePath, image));
            Rect imageRect = new Rect(0, 0, 1920, 1080);
            spriteRenderer.sprite = Sprite.Create(image, imageRect, new Vector2(0.5f, 0.5f));
        }

        //print(Screen.width + " x " + Screen.height);
    }
    private void UpdateGraphics()
    {
        folderFileCount = GetFolderFileCount(customFolderDataPath);

        bool destroyRemainingPrizes = folderFileCount < prizes.Length;

        prizesDictionary = new Dictionary <GameObject, int>();

        if (destroyRemainingPrizes)
        {
            foreach (GameObject row in rows)
            {
                for (int i = folderFileCount; i < prizes.Length; i++)
                {
                    Destroy(row.transform.GetChild(i).gameObject);
                }
            }
        }

        prizes = new GameObject[folderFileCount];

        GetSlotMachineSprite();

        for (int i = 0; i <= folderFileCount - 1; i++)
        {
            string prizePath = string.Empty;

            prizePath = string.Format("{0}/premio {1}.png", customFolderDataPath, i + 1);

            foreach (GameObject row in rows)
            {
                SpriteRenderer newSpriteRenderer = null;
                Texture2D      image             = null;

                try
                {
                    GameObject child = row.transform.GetChild(i).gameObject;
                    newSpriteRenderer = child.GetComponent <SpriteRenderer>();
                    image             = newSpriteRenderer.sprite.texture;
                    prizes[i]         = child;
                }
                catch
                {
                    RowData    rowScript = row.GetComponent <RowData>();
                    GameObject newPrize  = Instantiate(prizePrefab) as GameObject;
                    Vector3    topmost   = rowScript.GetTopMostElement().transform.position;
                    newSpriteRenderer = newPrize.GetComponent <SpriteRenderer>();

                    newPrize.transform.SetParent(row.transform, true);
                    newPrize.GetComponent <Collider>().isTrigger = true;

                    image = newSpriteRenderer.sprite.texture;

                    newPrize.transform.position = new Vector3(topmost.x, topmost.y + heightDifference, topmost.z);

                    rowScript.prizesList.AddFirst(newPrize);

                    prizes[i] = newPrize;
                }

                prizes[i].name = string.Format("prize {0}", i + 1);

                image = new Texture2D(350, 450, TextureFormat.ARGB32, true);
                StartCoroutine(Customization.LoadTexture2D(prizePath, image));
                Rect imageRect = new Rect(0, 0, image.width, image.height);
                newSpriteRenderer.sprite = Sprite.Create(image, imageRect, new Vector2(0.5f, 0.5f));
            }

            prizesDictionary.Add(prizes[i], 0);
        }
    }