/// <summary> /// Shows the add menu for the specified type /// </summary> public static void AddObjectType(Type type, bool friendlyNamespacePrefix, Array existingTypes, GenericMenu.MenuFunction2 addCallback) { if (!s_ObjectTypes.TryGetValue(type, out var typeList)) { // Search through all of the assemblies to find any types that derive from specified type. typeList = new List <Type>(); var assemblies = AppDomain.CurrentDomain.GetAssemblies(); for (int i = 0; i < assemblies.Length; ++i) { var assemblyTypes = assemblies[i].GetTypes(); for (int j = 0; j < assemblyTypes.Length; ++j) { // Must derive from specified type. if (!type.IsAssignableFrom(assemblyTypes[j])) { continue; } // Ignore abstract classes. if (assemblyTypes[j].IsAbstract) { continue; } // Ability types should not show ItemAbilities. if (type == typeof(Ability) && typeof(ItemAbility).IsAssignableFrom(assemblyTypes[j])) { continue; } typeList.Add(assemblyTypes[j]); } } s_ObjectTypes.Add(type, typeList); } var addMenu = new GenericMenu(); for (int i = 0; i < typeList.Count; ++i) { // Do not show already added types. var addType = true; if (!CanAddMultipleTypes(typeList[i]) && existingTypes != null) { for (int j = 0; j < existingTypes.Length; ++j) { if (existingTypes.GetValue(j).GetType() == typeList[i]) { addType = false; break; } } } if (!addType) { continue; } addMenu.AddItem(new GUIContent(InspectorUtility.DisplayTypeName(typeList[i], friendlyNamespacePrefix)), false, addCallback, typeList[i]); } addMenu.ShowAsContext(); }
/// <summary> /// Draws all of the elements. /// </summary> public static void OnListDraw(Array objects, Rect rect, int index, bool friendlyNamespacePrefix) { var obj = objects.GetValue(index); EditorGUI.LabelField(rect, InspectorUtility.DisplayTypeName(obj.GetType(), friendlyNamespacePrefix)); }