Esempio n. 1
0
        /// <summary>
        /// Listens for the creation of assets and adds them to the ExtensionDrawers
        /// </summary>
        /// <param name="path">The path of the created asset.</param>
        static void OnWillCreateAsset(string path)
        {
            string pathExtension = Path.GetExtension(path);

            if (pathExtension != ".asset")
            {
                return;
            }

            AssetIconModule loadedIcon = AssetDatabase.LoadAssetAtPath <AssetIconModule> (path);

            if (loadedIcon != null)
            {
                if (!ExtensionDrawers.Contains(loadedIcon))
                {
                    ExtensionDrawers.Add(loadedIcon);
                }
            }
        }
Esempio n. 2
0
        /// <summary>
        /// Listens for the saving of assets and adds them to the ExtensionDrawers, primarily used to add Duplicated modules
        /// to the manifest.
        /// </summary>
        /// <param name="paths">The path of the saved assets.</param>
        static string[] OnWillSaveAssets(string[] paths)
        {
            foreach (string path in paths)
            {
                string pathExtension = Path.GetExtension(path);

                if (pathExtension != ".asset")
                {
                    return(paths);
                }

                AssetIconModule loadedIcon = AssetDatabase.LoadAssetAtPath <AssetIconModule> (path);

                if (loadedIcon != null)
                {
                    if (!ExtensionDrawers.Contains(loadedIcon))
                    {
                        ExtensionDrawers.Add(loadedIcon);
                    }
                }
            }

            return(paths);
        }
Esempio n. 3
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;
                    }
                }
            }
        }