private void ProcessDropDown(FieldInfo field, string fieldName, object templateObject, RectTransform parent, bool addToForm) { DropDownAttribute dropDrownAttr = Utils.ExtractAttributeFromFieldInfo <DropDownAttribute>(field); if (dropDrownAttr != null) { object item = field?.GetValue(templateObject); string fieldValue = item?.ToString(); CreateUIDropDown(field.FieldType, fieldValue, fieldName, templateObject, parent, addToForm); } }
private static UIDropDown AddDropdown <T>(this UIHelperBase group, string text, string propertyName, DropDownAttribute attr, Func <string, string> translator = null) { var property = typeof(T).GetProperty(propertyName); var defaultCode = (int)property.GetValue(OptionsWrapper <T> .Options, null); int defaultSelection; var items = attr.GetItems(translator); try { defaultSelection = items.First(kvp => kvp.Value == defaultCode).Value; } catch { defaultSelection = 0; property.SetValue(OptionsWrapper <T> .Options, items.First().Value, null); } return((UIDropDown)group.AddDropdown(text, items.Select(kvp => kvp.Key).ToArray(), defaultSelection, sel => { var code = items[sel].Value; property.SetValue(OptionsWrapper <T> .Options, code, null); OptionsWrapper <T> .SaveOptions(); attr.Action <int>().Invoke(code); })); }
private static void SetViewdataWithValue(DropDownAttribute attr, string name, IDictionary <string, object> viewData, object value) { var viewDataKey = "DDKey_" + name; viewData[viewDataKey] = viewData[viewDataKey] ?? attr.GetMethodResult(value); }
private static void SetViewdataWithValue(DropDownAttribute attr, string name, IDictionary<string, object> viewData, object value) { var viewDataKey = "DDKey_" + name; viewData[viewDataKey] = viewData[viewDataKey] ?? attr.GetMethodResult(value); }