示例#1
0
    private void RandomFillSuccessImage(WordsImageButton button)
    {
        char character = characters[selectedCharacterIndex];

        List <WordsCharacterImageButtons> imagesWithoutSelected = characterImageButtons.ToList();

        imagesWithoutSelected.RemoveAt(selectedCharacterIndex);

        WordsCharacterImageButtons successButton = null;
        int  randomIndex = 0;
        bool haveChar    = true;

        do
        {
            int successImageIndex = Random.Range(0, imagesWithoutSelected.Count);
            randomIndex   = Random.Range(0, imagesWithoutSelected[successImageIndex].normalButtons.Length);
            successButton = imagesWithoutSelected[successImageIndex];
            string filename = successButton.normalButtons[randomIndex].name;
            haveChar = filename.IndexOf(character) >= 0;
        } while (haveChar);

        button.SetStates(successButton.normalButtons[randomIndex],
                         successButton.successButtons[randomIndex],
                         successButton.wrongButtons[randomIndex]);
    }
示例#2
0
    private void AddWordsCharacterImageButtons()
    {
        WordsCharacterImageButtons wcb = characterImageButtons[selectedCharacterIndex];
        int randomPos = Random.Range(0, 4);

        List <int> buttons = new List <int>();

        for (int i = 0; i < characterImageButtons[selectedCharacterIndex].normalButtons.Length; i++)
        {
            buttons.Add(i);
        }

        for (int i = 0; i < 4; i++)
        {
            GameObject go = new GameObject();
            go.AddComponent <SpriteRenderer>();
            WordsImageButton cb = go.AddComponent <WordsImageButton>();
            cb.onClick           += WordsCharacterImageButtonOnClick;
            go.transform.position = treeButtonsPosition[i].position;
            if (i != randomPos)
            {
                int index           = Random.Range(0, buttons.Count);
                int wrongImageIndex = buttons[index];
                buttons.RemoveAt(index);

                cb.SetStates(wcb.normalButtons[wrongImageIndex],
                             wcb.successButtons[wrongImageIndex],
                             wcb.wrongButtons[wrongImageIndex]);
                cb.isSuccess = false;
            }
            else
            {
                RandomFillSuccessImage(cb);
                cb.isSuccess = true;
            }
            go.AddComponent <BoxCollider2D>();
            activeButtons.Add(cb);
        }
    }