private void CreatePref(ModPrefs.PrefDesc pref, ref float totalHeight)
        {
            GameObject textName = new GameObject("PrefName (" + pref.DisplayText + ")", typeof(RectTransform), typeof(Text));

            textName.transform.SetParent(scrollContent, false);
            textName.GetComponent <RectTransform>().sizeDelta        = new Vector2(675f, 70f);
            textName.GetComponent <RectTransform>().anchorMin        = new Vector2(0.5f, 1.0f);
            textName.GetComponent <RectTransform>().anchorMax        = new Vector2(0.5f, 1.0f);
            textName.GetComponent <RectTransform>().pivot            = new Vector2(1f, 1.0f);
            textName.GetComponent <RectTransform>().anchoredPosition = new Vector2(-75, -totalHeight);

            textName.GetComponent <Text>().font            = QuickMenuUtils.GetQuickMenuInstance().transform.Find("ShortcutMenu/BuildNumText").GetComponent <Text>().font;
            textName.GetComponent <Text>().fontSize        = 50;
            textName.GetComponent <Text>().alignment       = TextAnchor.MiddleRight;
            textName.GetComponent <Text>().alignByGeometry = true;
            textName.GetComponent <Text>().text            = pref.DisplayText;

            if (pref.Type == ModPrefs.PrefType.BOOL)
            {
                UIToggleSwitch toggle = UnityUiUtils.CreateUIToggleSwitch(scrollContent.GetComponent <RectTransform>());
                toggle.GetComponent <RectTransform>().anchorMin        = new Vector2(0.5f, 1.0f);
                toggle.GetComponent <RectTransform>().anchorMax        = new Vector2(0.5f, 1.0f);
                toggle.GetComponent <RectTransform>().pivot            = new Vector2(0.0f, 1.0f);
                toggle.GetComponent <RectTransform>().anchoredPosition = new Vector2(75f, -totalHeight);
                toggle.GetComponent <Toggle>().isOn = pref.Value == "1";
                toggle.OnChange = (isOn) => pref.ValueEdited = isOn ? "1" : "0";
            }
            else
            {
                GameObject textValue = new GameObject("PrefValue (" + pref.DisplayText + ")", typeof(RectTransform), typeof(Text));
                textValue.transform.SetParent(scrollContent, false);
                textValue.GetComponent <RectTransform>().sizeDelta        = new Vector2(675f, 70f);
                textValue.GetComponent <RectTransform>().anchorMin        = new Vector2(0.5f, 1.0f);
                textValue.GetComponent <RectTransform>().anchorMax        = new Vector2(0.5f, 1.0f);
                textValue.GetComponent <RectTransform>().pivot            = new Vector2(0f, 1.0f);
                textValue.GetComponent <RectTransform>().anchoredPosition = new Vector2(75f, -totalHeight);

                textValue.GetComponent <Text>().font            = QuickMenuUtils.GetQuickMenuInstance().transform.Find("ShortcutMenu/BuildNumText").GetComponent <Text>().font;
                textValue.GetComponent <Text>().fontSize        = 50;
                textValue.GetComponent <Text>().alignment       = TextAnchor.MiddleLeft;
                textValue.GetComponent <Text>().alignByGeometry = true;
                textValue.GetComponent <Text>().text            = pref.Value;
            }

            totalHeight += 70;
        }
Beispiel #2
0
 public void SetConfigPref(ModPrefs.PrefDesc pref)
 {
     this.pref = pref;
 }