Exemple #1
0
        public static AssetTarget CreateFromGUID(string guid)
        {
            AssetTarget newAssetTarget = new AssetTarget();

            newAssetTarget.GUID      = guid;
            newAssetTarget.FilePath  = AssetDatabase.GUIDToAssetPath(guid);
            newAssetTarget.Extension = Path.GetExtension(newAssetTarget.FilePath);
            newAssetTarget.Filename  = Path.GetFileName(newAssetTarget.FilePath);

            return(newAssetTarget);
        }
Exemple #2
0
        //public string Style = "Width = 100%; Height = 100%;


        /// <summary>
        /// Checks to see if the module should draw on the passed target.
        /// </summary>
        /// <returns><c>true</c>, if target was evaluated sucessfully, <c>false</c> otherwise.</returns>
        /// <param name="filename">The filename of the target.</param>
        /// <param name="extension">The extension of the target.</param>
        public override bool EvaluateTarget(AssetTarget assetTarget)
        {
            if (!Active)
            {
                return(false);
            }

            if (!IsValid())
            {
                return(false);
            }

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

            return(false);
        }
 public abstract bool EvaluateTarget(AssetTarget assetTarget);
Exemple #4
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;
                    }
                }
            }
        }