예제 #1
0
 public virtual void Draw(string guid, Rect rect)
 {
     AssetIconDrawer.DrawCustomIcon(guid, rect, Icon);
 }
예제 #2
0
        /// <summary>
        /// Paints the item in the project window.
        /// </summary>
        /// <param name="guid">The GUID of the asset to check.</param>
        /// <param name="rect">The Rect in which the item is drawn.</param>
        private static void ItemOnGUI(string guid, Rect rect)
        {
            if (Event.current.type != EventType.Repaint || string.IsNullOrEmpty(guid))
            {
                return;
            }

            if (!isEnabled)
            {
                return;
            }

            AssetTarget assetTarget = AssetTarget.CreateFromGUID(guid);

            if (assetTarget.Extension == "")
            {
                return;
            }

            if (assetTarget.Extension == ".asset")
            {
                UnityEngine.Object obj = AssetDatabase.LoadAssetAtPath(assetTarget.FilePath, typeof(UnityEngine.Object)) as UnityEngine.Object;

                if (obj == null)
                {
                    return;
                }

                Type type = obj.GetType();

                IIconProvider iconProvider;
                IconProviders.TryGetValue(type, out iconProvider);

                if (iconProvider != null)
                {
                    object objectIcon = iconProvider.GetIcon(obj);

                    if (objectIcon == null)
                    {
                        return;
                    }

                    Type iconType = objectIcon.GetType();

                    if (typeof(Sprite).IsAssignableFrom(iconType))
                    {
                        Sprite spriteIcon = (Sprite)objectIcon;

                        if (spriteIcon != null)
                        {
                            AssetIconDrawer.DrawCustomIcon(guid, rect, spriteIcon);
                            return;
                        }
                    }
                    else if (typeof(Texture).IsAssignableFrom(iconType))
                    {
                        Texture textureIcon = (Texture)objectIcon;

                        if (textureIcon != null)
                        {
                            AssetIconDrawer.DrawCustomIcon(guid, rect, textureIcon);
                            return;
                        }
                    }
                }
            }

            if (ModuleManifest.ExtensionDrawers != null)
            {
                for (int i = 0; i < ModuleManifest.ExtensionDrawers.Count; i++)
                {
                    AssetIconModule module = ModuleManifest.ExtensionDrawers [i];

                    if (module == null)
                    {
                        ModuleManifest.ExtensionDrawers.Remove(null);
                        continue;
                    }

                    if (module.EvaluateTarget(assetTarget))
                    {
                        module.Draw(guid, rect);
                        return;
                    }
                }
            }
        }