예제 #1
0
    public static void DisplayCategory(string category)
    {
        if (instance == null)
        {
            return;
        }

        // Optimisation for saving
        if (instance.currentCategory != string.Empty && instance.currentCategory != category && instance.options.ContainsKey(instance.currentCategory))
        {
            foreach (string headingName in instance.options[instance.currentCategory].Keys)
            {
                for (int i = 0; i < instance.options[instance.currentCategory][headingName].Length; i++)
                {
                    BaseSettingsElement elementCopy = instance.options[instance.currentCategory][headingName][i];

                    if (elementCopy != null && elementCopy.valueChanged)
                    {
                        instance.changesTracker.Add(elementCopy);
                    }
                }
            }
        }

        instance.categoryHeading.text = category;
        instance.currentCategory      = category;

        // Clear root
        foreach (Transform child in instance.elementRoot.transform)
        {
            Destroy(child.gameObject);
        }

        foreach (ColorButton button in instance.categoryRoot.GetComponentsInChildren <ColorButton>())
        {
            if (button.gameObject.name != category)
            {
                button.RevertColor();
            }
            else
            {
                button.SelectColor();
            }
        }

        if (instance.options.ContainsKey(category) == false)
        {
            return;
        }

        if (instance.currentCategory != string.Empty && instance.options.ContainsKey(instance.currentCategory))
        {
            foreach (string headingName in instance.options[instance.currentCategory].Keys)
            {
                // Create heading prefab
                SettingsHeading heading = Instantiate(instance.headingPrefab).GetComponent <SettingsHeading>();
                heading.SetText(headingName);
                heading.transform.SetParent(instance.elementRoot.transform);

                for (int i = 0; i < instance.options[instance.currentCategory][headingName].Length; i++)
                {
                    if (instance.options[instance.currentCategory][headingName][i] != null)
                    {
                        heading.AddObjectToRoot(instance.options[instance.currentCategory][headingName][i].InitializeElement());
                    }
                }
            }
        }
    }
예제 #2
0
    public static void DisplayCategory(string category)
    {
        if (instance == null)
        {
            return;
        }

        // Optimisation for saving
        if (instance.currentCategory != string.Empty && instance.currentCategory != category && instance.options.ContainsKey(instance.currentCategory))
        {
            foreach (string headingName in instance.options[instance.currentCategory].Keys)
            {
                for (int i = 0; i < instance.options[instance.currentCategory][headingName].Length; i++)
                {
                    BaseSettingsElement elementCopy = instance.options[instance.currentCategory][headingName][i];

                    if (elementCopy != null && elementCopy.valueChanged)
                    {
                        instance.changesTracker.Add(elementCopy);
                    }
                }
            }

            if (instance.changesTracker.Count > 0)
            {
                instance.Apply();
            }
        }

        instance.categoryHeading.text = LocalizationTable.GetLocalization(category);
        instance.currentCategory      = category;

        // Clear root
        foreach (Transform child in instance.elementRoot.transform)
        {
            child.BroadcastMessage("Despawn", SendMessageOptions.DontRequireReceiver);
            Destroy(child.gameObject);
        }

        foreach (ColorButton button in instance.categoryRoot.GetComponentsInChildren <ColorButton>())
        {
            if (button.gameObject.name != category)
            {
                button.RevertColor();
            }
            else
            {
                button.SelectColor();
            }
        }

        if (instance.options.ContainsKey(category) == false)
        {
            return;
        }

        if (instance.currentCategory != string.Empty && instance.options.ContainsKey(instance.currentCategory))
        {
            foreach (string headingName in instance.options[instance.currentCategory].Keys)
            {
                // Create heading prefab
                SettingsHeading heading = Instantiate(instance.headingPrefab).GetComponent <SettingsHeading>();
                heading.SetText(headingName);
                heading.transform.SetParent(instance.elementRoot.transform);

                for (int i = 0; i < instance.options[instance.currentCategory][headingName].Length; i++)
                {
                    if (instance.options[instance.currentCategory][headingName][i] != null)
                    {
                        BaseSettingsElement element = instance.options[instance.currentCategory][headingName][i];
                        heading.AddObjectToRoot(element.InitializeElement());
                        element.valueChanged = false;
                    }
                }
            }
        }

        // Update canvases, to allow the normalized position to properly exist.
        Canvas.ForceUpdateCanvases();
        instance.settingsScrollRect.normalizedPosition = new Vector2(0, 1);
    }
예제 #3
0
    public static void DisplayCategory(string category, bool initial = false)
    {
        if (instance == null)
        {
            return;
        }

        RectTransform rectTransform = instance.mainRoot.GetComponent <RectTransform>();

        if (rectTransform.sizeDelta.x > Screen.width * 0.8f)
        {
            rectTransform.sizeDelta = new Vector2(Screen.width * 0.8f, rectTransform.sizeDelta.y);
        }

        if (rectTransform.sizeDelta.y > Screen.height * 0.8f)
        {
            rectTransform.sizeDelta = new Vector2(rectTransform.sizeDelta.x, Screen.height * 0.8f);
        }

        // Optimisation for saving
        if (instance.currentCategory != string.Empty && instance.currentCategory != category && instance.options.ContainsKey(instance.currentCategory) && initial == false)
        {
            foreach (string headingName in instance.options[instance.currentCategory].Keys)
            {
                for (int i = 0; i < instance.options[instance.currentCategory][headingName].Length; i++)
                {
                    BaseSettingsElement elementCopy = instance.options[instance.currentCategory][headingName][i];

                    if (elementCopy != null && elementCopy.valueChanged)
                    {
                        instance.changesTracker.Add(elementCopy);
                    }
                }
            }

            if (instance.changesTracker.Count > 0)
            {
                instance.Apply();
            }
        }

        instance.categoryHeading.text = LocalizationTable.GetLocalization(category);
        instance.currentCategory      = category;

        // Clear root
        foreach (Transform child in instance.elementRoot.transform)
        {
            Destroy(child.gameObject);
        }

        foreach (ColorButton button in instance.categoryRoot.GetComponentsInChildren <ColorButton>())
        {
            if (button.gameObject.name != category)
            {
                button.RevertColor();
            }
            else
            {
                button.SelectColor();
            }
        }

        if (instance.options.ContainsKey(category) == false)
        {
            return;
        }

        if (instance.currentCategory != string.Empty && instance.options.ContainsKey(instance.currentCategory))
        {
            foreach (string headingName in instance.options[instance.currentCategory].Keys)
            {
                // Create heading prefab
                SettingsHeading heading = Instantiate(instance.headingPrefab).GetComponent <SettingsHeading>();
                heading.SetText(headingName);
                heading.transform.SetParent(instance.elementRoot.transform);

                for (int i = 0; i < instance.options[instance.currentCategory][headingName].Length; i++)
                {
                    if (instance.options[instance.currentCategory][headingName][i] != null)
                    {
                        BaseSettingsElement element = instance.options[instance.currentCategory][headingName][i];
                        heading.AddObjectToRoot(element.InitializeElement());
                        element.valueChanged = false;
                    }
                }
            }
        }

        instance.settingsScrollRect.verticalNormalizedPosition   = 1;
        instance.settingsScrollRect.horizontalNormalizedPosition = 0;
    }