Exemplo n.º 1
0
    /// <summary>
    /// Load our categories.
    /// </summary>
    private void LoadCategories()
    {
        // Clear root
        foreach (Transform child in elementRoot.transform)
        {
            Destroy(child.gameObject);
        }

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

        options = new Dictionary <string, Dictionary <string, BaseSettingsElement[]> >();

        Dictionary <string, Dictionary <string, SettingsOption[]> > categories = PrototypeManager.SettingsCategories.Values.ToArray().SelectMany(x => x.categories).ToDictionary(kvp => kvp.Key, kvp => kvp.Value);

        foreach (string currentName in categories.Keys)
        {
            ColorButton button = Instantiate(categoryPrefab).GetComponent <ColorButton>();
            button.transform.SetParent(categoryRoot.transform);
            button.name = currentName;
            button.SetText(LocalizationTable.GetLocalization(currentName));
            options.Add(currentName, new Dictionary <string, BaseSettingsElement[]>());

            // This is quite optimised (despite being a forloop on a dictionary), and is only done during start
            foreach (KeyValuePair <string, SettingsOption[]> keyValuePair in categories[currentName])
            {
                options[currentName].Add(keyValuePair.Key, new BaseSettingsElement[keyValuePair.Value.Length]);

                for (int i = 0; i < keyValuePair.Value.Length; i++)
                {
                    if (FunctionsManager.SettingsMenu.HasFunction("Get" + keyValuePair.Value[i].className))
                    {
                        BaseSettingsElement element = FunctionsManager.SettingsMenu.Call("Get" + keyValuePair.Value[i].className).ToObject <BaseSettingsElement>();
                        element.option        = keyValuePair.Value[i];
                        element.parameterData = keyValuePair.Value[i].options;
                        element.InitializeLUA();
                        options[currentName][keyValuePair.Key][i] = element;
                    }
                    else if (keyValuePair.Value[i].name != null)
                    {
                        Debug.LogWarning("Get" + keyValuePair.Value[i].className + "() Doesn't exist");
                    }
                }
            }
        }
    }
Exemplo n.º 2
0
    /// <summary>
    /// Load our categories.
    /// </summary>
    private void LoadCategories()
    {
        // Clear root
        foreach (Transform child in elementRoot.transform)
        {
            Destroy(child.gameObject);
        }

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

        options = new Dictionary <string, Dictionary <string, BaseSettingsElement[]> >();

        List <SettingsCategory> categories = PrototypeManager.SettingsCategories.Values;

        for (int i = 0; i < categories.Count; i++)
        {
            ColorButton button = Instantiate(categoryPrefab).GetComponent <ColorButton>();
            button.transform.SetParent(categoryRoot.transform);
            button.name = categories[i].Type;
            button.SetText(LocalizationTable.GetLocalization(categories[i].Type));
            options.Add(categories[i].Type, new Dictionary <string, BaseSettingsElement[]>());

            foreach (KeyValuePair <string, List <SettingsOption> > keyValuePair in categories[i].headings)
            {
                options[categories[i].Type].Add(keyValuePair.Key, new BaseSettingsElement[keyValuePair.Value.Count]);

                for (int j = 0; j < keyValuePair.Value.Count; j++)
                {
                    if (FunctionsManager.SettingsMenu.HasFunction("Get" + keyValuePair.Value[j].classData.ClassName))
                    {
                        BaseSettingsElement element = FunctionsManager.SettingsMenu.Call("Get" + keyValuePair.Value[j].classData.ClassName).ToObject <BaseSettingsElement>();
                        element.option        = keyValuePair.Value[j];
                        element.parameterData = keyValuePair.Value[j].classData.ParameterData;
                        element.InitializeLUA();
                        options[categories[i].Type][keyValuePair.Key][j] = element;
                    }
                    else if (keyValuePair.Value[j].name != null)
                    {
                        UnityDebugger.Debugger.LogError("Get" + keyValuePair.Value[j].classData.ClassName + "() Doesn't exist");
                    }
                }
            }
        }
    }