public override void OnGUI(Rect position, SerializedProperty property, GUIContent label) { ListToPopupAttribute atb = attribute as ListToPopupAttribute; List <Type> stringList = null; if (atb.classType.GetField(atb.listName, BindingFlags.Static | BindingFlags.NonPublic) != null) { stringList = atb.classType.GetField(atb.listName, BindingFlags.Static | BindingFlags.NonPublic) .GetValue(atb.classType) as List <Type>; } if (stringList != null && stringList.Count != 0) { int selectedIndex = Mathf.Max(0, stringList.FindIndex(t => t.Name == property.stringValue)); selectedIndex = EditorGUI.Popup(position, property.name, selectedIndex , stringList.Select(t => t.Name).ToArray()); property.stringValue = stringList[selectedIndex].Name; (property.serializedObject.targetObject as EntityDescriptorHolder).type = Activator.CreateInstance(stringList[selectedIndex]) as IEntityDescriptor; } else { EditorGUI.TextArea(position, "Error - no valid entity descriptors found"); } }
public override void OnGUI(Rect position, SerializedProperty property, GUIContent label) { ListToPopupAttribute atb = attribute as ListToPopupAttribute; List <string> stringList = null; if (atb.myType.GetField(atb.propertyName) != null) { stringList = atb.myType.GetField(atb.propertyName).GetValue(atb.myType) as List <string>; } if (stringList != null && stringList.Count != 0) { int selectedIndex = Mathf.Max(stringList.IndexOf(property.stringValue), 0); selectedIndex = EditorGUI.Popup(position, property.name, selectedIndex, stringList.ToArray()); property.stringValue = stringList[selectedIndex]; } else { EditorGUI.PropertyField(position, property, label); } }