Exemplo n.º 1
0
    public void UpdateUI()
    {
        if (!useUI)
        {
            return;
        }

        content.ClearChildren(true);

        for (int i = 0; i < highscores.Length; i++)
        {
            Highscore score = highscores[i];

            Transform item = Instantiate(template, content.transform);
            item.gameObject.SetActive(true);
            item.gameObject.name = score.username;

            Image image = item.GetComponent <Image>();
            if (i == 0)
            {
                image.color = first;
            }
            else if (i == 1)
            {
                image.color = second;
            }
            else if (i == 2)
            {
                image.color = third;
            }
            else if (score.username == Options.username)
            {
                image.color = mine;
            }

            foreach (Text t in item.GetComponentsInChildren <Text>())
            {
                if (t.gameObject.name == "Rank")
                {
                    t.text = (i + 1).ToString("D3");
                }
                else if (t.gameObject.name == "Username")
                {
                    t.text = score.username;
                }
                else if (t.gameObject.name == "Version")
                {
                    t.text  = score.version.ToString();
                    t.color = (score.version == Highscore.Version.Full) ? Color.blue : Color.red;
                }
                else if (t.gameObject.name == "Score")
                {
                    t.text = score.score.ToString("D3");
                }
            }
        }

        content.ReCalculate();
        ScrollToMe();
    }
    void UpdateOption(Option option)
    {
        AutoLayoutGroup selector = null;

        Sprite[] list = null;
        Dictionary <string, Button> buttons = new Dictionary <string, Button>();
        string def = "";

        switch (option)
        {
        case (Option.Skin):
            selector = skinSelector;
            def      = defaultSkin;
            break;

        case (Option.Background):
            selector = backgroundSelector;
            def      = defaultBackground;
            break;
        }

        list = Resources.LoadAll <Sprite>(option.ToString() + "s");
        selector.ClearChildren();

        foreach (Sprite sprite in list)
        {
            Image image = new GameObject(sprite.name).AddComponent <Image>();
            image.sprite = sprite;

            image.color          = Color.white;
            image.material       = null;
            image.raycastTarget  = true;
            image.type           = Image.Type.Simple;
            image.preserveAspect = true;

            Animator animator = image.gameObject.AddComponent <Animator>();
            animator.runtimeAnimatorController = optionButtonAnimatorController;
            animator.updateMode = AnimatorUpdateMode.UnscaledTime;

            Button button = image.gameObject.AddComponent <Button>();
            button.onClick.AddListener(delegate() { ChooseSprite(option, sprite); });
            button.transition = Selectable.Transition.Animation;
            button.image      = image;

            UIAudio audio = image.gameObject.AddComponent <UIAudio>();
            audio.element = UIAudio.Element.Button;

            buttons.Add(sprite.name, button);

            if (sprite.name == PlayerPrefs.GetString(option.ToString(), def))
            {
                image.color = selectedColour;

                switch (option)
                {
                case (Option.Skin):
                    skin = sprite;
                    foreach (Image i in skinnedImages)
                    {
                        i.sprite = sprite;
                    }
                    break;

                case (Option.Background):
                    background = sprite;
                    Background.UpdateBackgrounds();
                    break;
                }
            }

            image.transform.SetParent(selector.transform);
        }

        switch (option)
        {
        case (Option.Skin):
            skins       = list;
            skinButtons = buttons;
            break;

        case (Option.Background):
            backgrounds       = list;
            backgroundButtons = buttons;
            break;
        }

        selector.ReCalculate();
    }