private void UpdatePreview() { previewFetched = true; #if UNITY_EDITOR if (IsGroup) { var child = GetFirstNonGroupChild(); if (child != null) { var source = child.Preview as Texture2D; preview = TextureUtility.Resize(source, 15, 15); } return; } UnityEditor.EditorGUIUtility.SetIconSize(Vector2.zero); preview = UnityEditor.AssetPreview.GetMiniTypeThumbnail(type); if (preview == null && Types.MonoBehaviour.IsAssignableFrom(type)) { preview = InspectorUtility.Preferences.graphics.CSharpScriptIcon; } if (preview != null) { preview.filterMode = FilterMode.Point; } #endif }
private void UpdatePreview() { previewFetched = true; #if UNITY_EDITOR if (IsGroup) { var child = GetFirstNonGroupChild(); if (child != null) { var source = child.Preview as Texture2D; preview = TextureUtility.Resize(source, 15, 15); if (preview != null) { preview.filterMode = FilterMode.Trilinear; fetchedPreviewNotNull = true; #if DEV_MODE && PI_ASSERTATIONS Debug.Assert(preview.width == 15 && preview.height == 15); #endif } #if DEV_MODE else { Debug.LogWarning("AddComponentMenuItem.UpdatePreview TextureUtility.Resize returned null for group \"" + label + "\"."); } #endif } #if DEV_MODE else { Debug.LogWarning("AddComponentMenuItem.UpdatePreview called for group \"" + label + "\" but had no children."); } #endif return; } UnityEditor.EditorGUIUtility.SetIconSize(Vector2.zero); preview = UnityEditor.AssetPreview.GetMiniTypeThumbnail(type); if (preview == null && Types.MonoBehaviour.IsAssignableFrom(type)) { preview = InspectorUtility.Preferences.graphics.CSharpScriptIcon; } if (preview != null) { fetchedPreviewNotNull = true; preview.filterMode = FilterMode.Point; } #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 } } }