Exemplo n.º 1
0
        public AssetTarget GetOrCreateFromGuid(string guid)
        {
            AssetTarget assetDrawer;

            if (!cacheCollection.TryGetValue(guid, out assetDrawer))
            {
                assetDrawer           = AssetTarget.CreateFromGUID(guid);
                cacheCollection[guid] = assetDrawer;
            }
            return(assetDrawer);
        }
Exemplo n.º 2
0
        /// <summary>
        /// <para>Paints the item in the project window.</para>
        /// </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 (!AssetIconsPreferences.Enabled.Value)
            {
                return;
            }

            var assetTarget = AssetTarget.CreateFromGUID(guid);

            if (string.IsNullOrEmpty(assetTarget.Extension))
            {
                return;
            }

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

                if (obj == null)
                {
                    return;
                }

                var type = obj.GetType();

                AssetDrawer assetDrawer;
                bool        result = AssetDrawerLibrary.AssetDrawers.TryGetValue(type, out assetDrawer);

                if (result)
                {
                    if (assetDrawer.CanDraw(obj))
                    {
                        bool selected = Selection.Contains(obj);

                        var backgroundRect = AssetIconTools.AreaToIconRect(rect, 64);
                        AssetIconDrawer.DrawBackground(backgroundRect);

                        assetDrawer.Draw(rect, obj, selected);
                    }
                    assetDrawer.ClearCache();
                }
            }
            else if (AssetIconsPreferences.DrawGUIStyles.Value && assetTarget.Extension == ".guiskin")
            {
                if (assetTarget.UnityObject is GUISkin)
                {
                    bool selected = Selection.Contains(assetTarget.UnityObject);
                    var  skin     = (GUISkin)assetTarget.UnityObject;

                    rect = AreaToIconRect(rect);

                    AssetIconDrawer.DrawBackground(rect);
                    skin.box.Draw(rect, new GUIContent("Style"), 0, selected);
                }
                return;
            }

            var icon = AssetIconsPreferences.TypeIcons[assetTarget.Extension];

            if (icon != null && icon.ObjectReference != null)
            {
                bool selected = Selection.Contains(assetTarget.UnityObject);
                rect = AreaToIconRect(rect);

                AssetIconDrawer.DrawBackground(rect);

                AssetIconDrawer.DrawObject(rect, icon, CompiledStyleDefinition.Default, selected);
            }
        }