public static void Apply(AddComponentMenuConfig config) { if (addComponentMenuConfigApplied) { #if DEV_MODE Debug.LogWarning("AddComponentMenuItems - Ignoring Apply(AddComponentMenuConfig) because addComponentMenuConfigApplied was already true"); #endif return; } addComponentMenuConfigApplied = true; var groups = config.groups; int count = groups.Length; for (int n = 0; n < count; n++) { var group = groups[n]; GetOrCreateGroup(group.label, group.customIcon); } var items = config.items; count = items.Length; for (int n = 0; n < count; n++) { var item = items[n]; var type = item.Type; if (type == null || !type.IsComponent()) { #if DEV_MODE && DEBUG_INVALID_DATA Debug.LogWarning("Skipping item with invalid type for Add Component menu: \"" + item.label + "\" with type " + StringUtils.ToString(type)); #endif continue; } try { Add(item.Type, item.label); } catch (NullReferenceException) { #if DEV_MODE Debug.LogError("Preferences.AddComponentMenuConfig NullReferenceException: item #" + n + " seems to contain invalid data."); #else continue; #endif } } }
public static void Apply(AddComponentMenuConfig config) { if (addComponentMenuConfigApplied) { #if DEV_MODE Debug.LogWarning("AddComponentMenuItems - Ignoring Apply(AddComponentMenuConfig) because addComponentMenuConfigApplied was already true"); #endif return; } addComponentMenuConfigApplied = true; var iconFromType = UnityEditor.AssetPreview.GetMiniTypeThumbnail(typeof(AudioSource)); GetOrCreateGroup("Audio", TextureUtility.Resize(iconFromType, 15, 15)); iconFromType = UnityEditor.AssetPreview.GetMiniTypeThumbnail(typeof(ParticleSystem)); GetOrCreateGroup("Effects", TextureUtility.Resize(iconFromType, 15, 15)); iconFromType = UnityEditor.AssetPreview.GetMiniTypeThumbnail(typeof(ParticleSystem)); GetOrCreateGroup("Effects", TextureUtility.Resize(iconFromType, 15, 15)); iconFromType = UnityEditor.AssetPreview.GetMiniTypeThumbnail(typeof(Canvas)); GetOrCreateGroup("Layout", TextureUtility.Resize(iconFromType, 15, 15)); iconFromType = UnityEditor.AssetPreview.GetMiniTypeThumbnail(typeof(MeshRenderer)); GetOrCreateGroup("Mesh", TextureUtility.Resize(iconFromType, 15, 15)); iconFromType = UnityEditor.AssetPreview.GetMiniTypeThumbnail(typeof(PolygonCollider2D)); GetOrCreateGroup("Physics 2D", TextureUtility.Resize(iconFromType, 15, 15)); iconFromType = UnityEditor.AssetPreview.GetMiniTypeThumbnail(typeof(BoxCollider)); GetOrCreateGroup("Physics", TextureUtility.Resize(iconFromType, 15, 15)); iconFromType = UnityEditor.AssetPreview.GetMiniTypeThumbnail(typeof(Camera)); GetOrCreateGroup("Rendering", TextureUtility.Resize(iconFromType, 15, 15)); iconFromType = UnityEditor.AssetPreview.GetMiniTypeThumbnail(typeof(UnityEngine.Tilemaps.Tilemap)); GetOrCreateGroup("Tilemap", TextureUtility.Resize(iconFromType, 15, 15)); var items = config.items; int count = items.Length; for (int n = 0; n < count; n++) { var item = items[n]; var type = item.Type; if (type == null || !type.IsComponent()) { #if DEV_MODE && DEBUG_INVALID_DATA Debug.LogWarning("Skipping item with invalid type for Add Component menu: \"" + item.label + "\" with type " + StringUtils.ToString(type)); #endif continue; } try { Add(item.Type, item.label); } catch (NullReferenceException) { #if DEV_MODE Debug.LogError("Preferences.AddComponentMenuConfig NullReferenceException: item #" + n + " seems to contain invalid data."); #else continue; #endif } } }