예제 #1
0
        /// <summary>
        /// <para>Renders the graphic for this drawer.</para>
        /// </summary>
        /// <param name="rect">The are in which to draw the icon.</param>
        /// <param name="target">The object to draw graphics for.</param>
        /// <param name="selected">Whether the selected graphic should appear selected.</param>
        public void Draw(Rect rect, object target, bool selected)
        {
            UpdateCachedProvidedGraphicsForTarget(target);

            for (int i = 0; i < providedGraphics.Length; i++)
            {
                var    graphicProvider = Graphics[i];
                object providedGraphic = providedGraphics[i];

                if (providedGraphic != null && !providedGraphic.Equals(null))
                {
                    var drawRect = AssetIconTools.AreaToIconRect(rect, graphicProvider.Style.MaxSize);
                    AssetIconDrawer.DrawObject(drawRect, providedGraphic, graphicProvider.Style, selected);
                }
            }
        }
예제 #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);
            }
        }