示例#1
0
    // Use this for initialization
    void Start()
    {
        // Load toggle state based on xml file
        GlobalConfigSettings settings = GameObject.FindObjectOfType <GlobalConfigSettings>();

        lightToggle.isOn = settings.themeContainer.Themes[0].Selected;
        darkToggle.isOn  = settings.themeContainer.Themes[1].Selected;
    }
示例#2
0
    public void ChangeOnToggle()
    {
        // Check which toggle is checked
        GlobalConfigSettings settings = GameObject.FindObjectOfType <GlobalConfigSettings>();

        settings.themeContainer.Themes[0].Selected = lightToggle.isOn;
        settings.themeContainer.Themes[1].Selected = darkToggle.isOn;

        // Write/save to XML file
        settings.themeContainer.Save(Application.dataPath + "/StreamingAssets/ThemeOptions.xml");
    }
示例#3
0
    public void UpdateTheme()
    {
        // Read if light or dark theme and change colours accordingly
        GlobalConfigSettings settings = GameObject.FindObjectOfType <GlobalConfigSettings>();
        Image  img          = this.TopPanel.GetComponent <Image>();
        string bgColorHex   = null;
        string fontColorHex = null;

        // Get the active hex value
        foreach (Theme theme in settings.themeContainer.Themes)
        {
            if (theme.Selected)
            {
                bgColorHex   = theme.BGColour;
                fontColorHex = theme.FontColour;
                break;
            }
        }

        // Set the background colour
        Color bgColor = new Color();

        ColorUtility.TryParseHtmlString(bgColorHex, out bgColor);
        img.color = bgColor;

        // Set the font color
        Color fontColor = new Color();

        ColorUtility.TryParseHtmlString(fontColorHex, out fontColor);

        Debug.Log(TopPanel.transform.childCount);

        for (int i = 0; i < TopPanel.transform.childCount; i++)
        {
            GameObject child = TopPanel.transform.GetChild(i).gameObject;
            if (child.transform.childCount == 1 || child.transform.childCount == 2)
            {
                child.transform.GetChild(0).gameObject.GetComponent <Text>().color = fontColor;
            }
            else if (child.transform.childCount == 0)
            {
                Text targetText = child.GetComponent <Text>();
                targetText.color = fontColor;
            }
        }
    }