Esempio n. 1
0
        /// <summary> Returns the value of a setting. </summary>
        /// <param name="settingName">The name of the setting.</param>
        /// <returns></returns>
        public int GetIntSetting(string settingName)
        {
            int settingIndex = FindSettingIndex(settingName);

            if (settingIndex < 0)
            {
                return(0);
            }
            UISetting setting = uiSettings[settingIndex];

            if (setting.UIToggle)
            {
                return(PlayerPrefs.GetInt(settingName));
            }
            if (setting.UIDropdown)
            {
                return(PlayerPrefs.GetInt(settingName));
            }
            if (setting.UITMP_Dropdown)
            {
                return(PlayerPrefs.GetInt(settingName));
            }
            if (setting.UIOptionsList)
            {
                return(PlayerPrefs.GetInt(settingName));
            }
            return(0);
        }
Esempio n. 2
0
        /// <summary> Returns the value of a setting. </summary>
        /// <param name="settingName">The name of the setting.</param>
        /// <returns></returns>
        public float GetFloatSetting(string settingName)
        {
            int settingIndex = FindSettingIndex(settingName);

            if (settingIndex < 0)
            {
                return(0f);
            }
            UISetting setting = uiSettings[settingIndex];

            if (setting.UISlider)
            {
                return(PlayerPrefs.GetFloat(settingName));
            }
            return(0f);
        }
Esempio n. 3
0
        /// <summary> Returns the value of a setting. </summary>
        /// <param name="settingName">The name of the setting.</param>
        /// <returns></returns>
        public string GetStringSetting(string settingName)
        {
            int settingIndex = FindSettingIndex(settingName);

            if (settingIndex < 0)
            {
                return("");
            }
            UISetting setting = uiSettings[settingIndex];

            if (setting.UIText)
            {
                return(PlayerPrefs.GetString(settingName));
            }
            if (setting.UITextMeshProUGUI)
            {
                return(PlayerPrefs.GetString(settingName));
            }
            return("");
        }
Esempio n. 4
0
        /// <summary> Saves the given setting from certain UI elements. </summary>
        /// <param name="settingName">The name to save under.</param>
        public void SaveSetting(string settingName)
        {
            int settingIndex = FindSettingIndex(settingName);

            if (settingIndex < 0)
            {
                return;
            }
            UISetting setting = uiSettings[settingIndex];

            if (setting.UISlider)
            {
                PlayerPrefs.SetFloat(settingName, setting.UISlider.value);
            }
            if (setting.UIToggle)
            {
                PlayerPrefs.SetInt(settingName, setting.UIToggle.isOn ? 1 : 0);
            }
            if (setting.UIText)
            {
                PlayerPrefs.SetString(settingName, setting.UIText.text);
            }
            if (setting.UITextMeshProUGUI)
            {
                PlayerPrefs.SetString(settingName, setting.UITextMeshProUGUI.text);
            }
            if (setting.UIDropdown)
            {
                PlayerPrefs.SetInt(settingName, setting.UIDropdown.value);
            }
            if (setting.UITMP_Dropdown)
            {
                PlayerPrefs.SetInt(settingName, setting.UITMP_Dropdown.value);
            }
            if (setting.UIOptionsList)
            {
                PlayerPrefs.SetInt(settingName, setting.UIOptionsList.CurrentOption);
            }
            PlayerPrefs.Save();
        }
Esempio n. 5
0
        protected void LoadSetting(string settingName)
        {
            int settingIndex = FindSettingIndex(settingName);

            if (settingIndex < 0)
            {
                return;
            }
            UISetting setting = uiSettings[settingIndex];

            if (setting.UISlider)
            {
                setting.UISlider.value = PlayerPrefs.GetFloat(settingName);
            }
            if (setting.UIToggle)
            {
                setting.UIToggle.isOn = PlayerPrefs.GetInt(settingName) == 1 ? true : false;
            }
            if (setting.UIText)
            {
                setting.UIText.text = PlayerPrefs.GetString(settingName);
            }
            if (setting.UITextMeshProUGUI)
            {
                setting.UITextMeshProUGUI.text = PlayerPrefs.GetString(settingName);
            }
            if (setting.UIDropdown)
            {
                setting.UIDropdown.value = PlayerPrefs.GetInt(settingName);
            }
            if (setting.UITMP_Dropdown)
            {
                setting.UITMP_Dropdown.value = PlayerPrefs.GetInt(settingName);
            }
            if (setting.UIOptionsList)
            {
                setting.UIOptionsList.CurrentOption = PlayerPrefs.GetInt(settingName);
            }
        }
Esempio n. 6
0
        protected void Awake()
        {
            // Finds the window componenents in children and adds them to the list of windows.
            Window[] childWindows     = GetComponentsInChildren <Window>(true); // Patched in 1.0.1
            int      childWindowCount = childWindows.Length;

            for (int i = 0; i < childWindowCount; ++i)
            {
                windows.Add(childWindows[i]);
            }

            // Sets up all the windows and tabs based on their active state.
            int    windowCount = windows.Count;
            Window window      = null;

            for (int i = 0; i < windowCount; ++i)
            {
                window = windows[i];
                window.Setup();
                if (window.Active && type == MenuType.Solitary)
                {
                    activeWindows.Add(window);
                }
                else if (window.Active && type == MenuType.Tab && activeWindows.Count == 0)
                {
                    activeWindows.Add(window);
                }
                if (window.Active && !activeTab)
                {
                    activeTab = window.Tab;
                }
                if (window.Tab)
                {
                    tabs.Add(window.Tab); window.Tab.Setup(window.Active);
                }
            }

            // Load settings.
            int       settingsCount = uiSettings.Count;
            UISetting setting       = new UISetting();

            for (int i = 0; i < settingsCount; ++i)
            {
                setting = uiSettings[i];
                LoadSetting(setting.Name); uiSettings[i] = setting;
            }

            // Align the tabs.
            if (type != MenuType.Tab)
            {
                return;
            }
            float         tabsWidth    = 0;
            int           tabCount     = tabs.Count;
            RectTransform tabTransform = null;

            // Find the total width.
            for (int i = 0; i < tabCount; ++i)
            {
                tabTransform = tabs[i].GetComponent <RectTransform>(); if (!tabTransform)
                {
                    continue;
                }
                tabsWidth += tabTransform.rect.width;
            }
            // Align the tabs using the total width.
            float currentTabWidth = 0;

            for (int i = 0; i < tabCount; ++i)
            {
                tabTransform = tabs[i].GetComponent <RectTransform>();
                if (!tabTransform)
                {
                    continue;
                }
                float tabWidth  = tabTransform.rect.width;
                float tabHeight = tabTransform.rect.height;

                if (tabAlign == TabAlign.Center)
                {
                    tabTransform.anchorMin        = new Vector2(0.5f, 1);
                    tabTransform.anchorMax        = new Vector2(0.5f, 1);
                    tabTransform.pivot            = new Vector2(0.5f, 1);
                    tabTransform.anchoredPosition = new Vector2(-tabsWidth / 2 / tabs.Count + currentTabWidth, tabHeight + tabOffset);
                    currentTabWidth += tabWidth;
                }
                else if (tabAlign == TabAlign.Left)
                {
                    tabTransform.anchorMin        = new Vector2(0, 1);
                    tabTransform.anchorMax        = new Vector2(0, 1);
                    tabTransform.pivot            = new Vector2(0, 1);
                    tabTransform.anchoredPosition = new Vector2(currentTabWidth, tabHeight + tabOffset);
                    currentTabWidth += tabWidth;
                }
                else if (tabAlign == TabAlign.Right)
                {
                    currentTabWidth              += tabWidth;
                    tabTransform.anchorMin        = new Vector2(1, 1);
                    tabTransform.anchorMax        = new Vector2(1, 1);
                    tabTransform.pivot            = new Vector2(1, 1);
                    tabTransform.anchoredPosition = new Vector2(-tabsWidth + currentTabWidth, tabHeight + tabOffset);
                }
            }
        }