//获取下拉列表显示内容, public string[] GetLabels() { //if(inited == false && stringLabelAttribute != null && stringLabelAttribute.type != null) { Type type = stringLabelAttribute.type; strs = Enum.GetNames(type); labels = new string[strs.Length]; strValue = stringLabelAttribute.strValue; FieldInfo[] fieldInfoes = type.GetFields(); int j = 0; for (int i = 0; i < fieldInfoes.Length; i++) { FieldInfo fieldInfo = fieldInfoes[i]; object[] arr = fieldInfo.GetCustomAttributes(typeof(EnumLabelAttribute), true); if (arr.Length > 0) { EnumLabelAttribute aa = (EnumLabelAttribute)arr[0]; string label = aa.label; labels[j++] = label; //Debug.Log("propers[" + i + "] " + fieldInfoes[i].ToString() + " " + label); } } inited = true; } return(labels); }
public static EnumDescription Create(EnumLabelAttribute attr, String name) { var enumLabel = new EnumDescription(); enumLabel.Key = attr.Key; enumLabel.Name = name; var labelProperty = attr.ResourceType.GetTypeInfo().GetDeclaredProperty(attr.LabelResource); enumLabel.Label = labelProperty.GetValue(labelProperty.DeclaringType, null) as String; if (!String.IsNullOrEmpty(attr.HelpResource)) { var helpProperty = attr.ResourceType.GetTypeInfo().GetDeclaredProperty(attr.HelpResource); enumLabel.Help = helpProperty.GetValue(helpProperty.DeclaringType, null) as String; } return(enumLabel); }
public override void OnGUI(Rect position, SerializedProperty property, GUIContent label) { EnumLabelAttribute attr = attribute as EnumLabelAttribute; Match match = new Regex(@"Element (?<index>\d+)").Match(label.text); if (!match.Success) { EditorGUI.PropertyField(position, property, label); return; } int index = int.Parse(match.Groups["index"].Value); if (index < attr.EnumNames.Length) { EditorGUI.PropertyField(position, property, new GUIContent(attr.EnumNames[index]), true); } else { EditorGUI.PropertyField(position, property, label, true); } }