private GamemodeBase GetGamemodeFromSettings() { foreach (var page in Pages) { foreach (var element in page.GetComponentsInChildren <UiElement>()) { if (element == null) { continue; } object value = null; if (element is UiCheckbox) { value = ((UiCheckbox)element).Value; } else if (element is UiInput) { value = ((UiInput)element).InputField.text; } else if (element is UiDropdown) { value = ((UiDropdown)element).Dropdown.value; } if (value == null) { continue; } var propertyInfo = Gamemode.GetType().GetProperty(element.gameObject.name); if (propertyInfo == null) { Debug.LogWarning($"Property could not be found: {element.gameObject.name}"); continue; } if (propertyInfo.PropertyType.IsEnum) { propertyInfo.SetValue(Gamemode, value); } else { propertyInfo.SetValue(Gamemode, Convert.ChangeType(value, propertyInfo.PropertyType), null); } } //foreach (Transform child in page.transform) //{ // var element = child.gameObject.GetComponent<UiElement>(); // if (element == null) continue; // object value = null; // if (element is UiCheckbox) // { // value = ((UiCheckbox)element).Value; // } // else if (element is UiInput) // { // value = ((UiInput)element).Value; // } else if (element is UiDropdown) // { // value = ((UiDropdown) element).Dropdown.value; // } // if (value == null) continue; // var propertyInfo = Gamemode.GetType().GetProperty(element.gameObject.name); // if (propertyInfo == null) // { // Debug.LogWarning($"Property could not be found: {element.gameObject.name}"); // continue; // } // propertyInfo.SetValue(Gamemode, Convert.ChangeType(value, propertyInfo.PropertyType), null); //} } return(Gamemode); }