public bool CreateRadioGroupView(Type type, BaseCommandModel model) { bool flag = false; object[] radioGroupAttrs = type.GetCustomAttributes(typeof(RadioGroupAttribute), false); if (radioGroupAttrs.Length > 0) { RadioGroupAttribute radioGroup = radioGroupAttrs[0] as RadioGroupAttribute; Type typeEnum = radioGroup.Type; string[] options = Enum.GetNames(typeEnum); int enumValue = -1; PropertyInfo[] infos = type.GetProperties(); foreach (PropertyInfo pd in infos) { if (pd.PropertyType.IsEnum && pd.PropertyType == typeEnum) { object value = pd.GetValue(model, null); int index = Array.IndexOf(options, value.ToString()); index = EditorGUILayout.Popup(index, options); string enumName = options[index]; value = Enum.Parse(typeEnum, enumName); pd.SetValue(model, value, null); enumValue = (int)value; flag = true; break; } } foreach (PropertyInfo pd in infos) { object[] itemAttrs = pd.GetCustomAttributes(typeof(RadioGroupAttribute), false); if (itemAttrs.Length > 0) { RadioGroupAttribute radioGroupItem = itemAttrs[0] as RadioGroupAttribute; if (radioGroupItem.EnumValue == enumValue) { object value = pd.GetValue(model, null); string fieldDisName; object[] atts = pd.GetCustomAttributes(typeof(DisplayNameAttribute), false); fieldDisName = atts.Length > 0 ? ((DisplayNameAttribute)atts[0]).DisplayName : pd.Name; value = EditorGUIUitls.GUIProperty(fieldDisName, pd, value); pd.SetValue(model, value, null); } } } } return(flag); }
public void CreateCommonView(Type type, BaseCommandModel model) { PropertyInfo[] infos = type.GetProperties(); foreach (PropertyInfo pd in infos) { GUILayout.BeginHorizontal(); object value = pd.GetValue(model, null); string fieldDisName; object[] atts = pd.GetCustomAttributes(typeof(DisplayNameAttribute), false); fieldDisName = atts.Length > 0 ? ((DisplayNameAttribute)atts[0]).DisplayName : pd.Name; value = EditorGUIUitls.GUIProperty(fieldDisName, pd, value); pd.SetValue(model, value, null); GUILayout.EndHorizontal(); } }