Beispiel #1
0
        /// <summary>
        /// Here's how the drawer checks what avenue to take:
        /// 1. If valid folder and folder has assigned icon, draw replacement icon and exit.
        /// 2. Else if asset successfully loads, try to draw it by passing any PvIconAttributes through registry.
        /// 3. Else check if asset path matches regex, and draw replacement if it does.
        /// 4. Else check if asset extension matches one of the registered extns, and draw replacement if it does
        /// 5. Failed to find a good substitute icon. Leave original icon intact.
        /// </summary>
        public void DrawProjectIcon(string guid, Rect selectionrect)
        {
            /*
             *          ValidateProjectBrowser();
             *          bool didClip = false;
             *          if (_getProjectBrowserRect != null)
             *          {
             *              Rect projectBrowserRect = _getProjectBrowserRect();
             *              Rect clippingRect = new Rect(Vector2.down * (18f), projectBrowserRect.size - new Vector2(0f, 36f));
             *              /EditorGUI.DrawRect(clippingRect, Color.green);
             *              GUI.BeginClip(clippingRect);
             *              selectionrect = new Rect(selectionrect.position - clippingRect.position, selectionrect.size);
             *              didClip       = true;
             *          }
             */

            //determine whether given asset is currently selected
            bool selected = Array.IndexOf(Selection.assetGUIDs, guid) > -1;

            string path  = AssetDatabase.GUIDToAssetPath(guid);
            Object asset = AssetDatabase.LoadAssetAtPath(path, typeof(Object));

            //PvCustomizerGUI.InvertedColors = selected;

            PvCustomizerSettings settings = PvCustomizerSettings.GetOrCreateSettings();

            if (AssetDatabase.IsValidFolder(path) && settings.DrawFolderIcons)
            {
                if (settings.TryMatchAgainstRules(path, out var pattern))
                {
                    DrawFolderIcon(path, selectionrect, pattern, selected);
                }
            }
            else if (asset != null && settings.DrawAssetIcons)
            {
                //if the class has an attribute defined, draw it
                if (PvIconAttributeCache.TryGetClassAttribute(asset.GetType(), out var attrs))
                {
                    foreach (PvIconAttribute attr in attrs)
                    {
                        TryDrawFromValue(asset, asset, selectionrect, attr, selected);
                    }
                }
                //else, descend into the members
                else
                {
                    bool didDraw = FindAndDrawAttributes(asset, selectionrect, selected);
                }
            }

            /*if (didClip)
             * {
             *  GUI.EndClip();
             * }*/
        }
Beispiel #2
0
        private bool FindAndDrawAttributes(Object asset, Rect fullRect, bool selected)
        {
            //get all relevant attributes and member info on which they're declared
            var          triplets = PvIconAttributeCache.GetAttributeTriplets(asset.GetType());
            IconSizeType sizeType = PvCustomizerUtility.GetSizeType(fullRect);

            if (triplets.Exists(t => CanDisplay(t.Attr.Display, sizeType) && !t.Attr.DontEraseDefault))
            {
                Rect iconRect = PvCustomizerUtility.ItemRectToIconRect(fullRect, sizeType == IconSizeType.TreeView);
                PvCustomizerGUI.DrawBackground(iconRect);
            }

            bool drewAtleastOnce = false;

            foreach (var(member, attr, valueType) in triplets)
            {
                object value = member.GetMemberValue(asset);
                drewAtleastOnce |= TryDrawFromValue(asset, value, fullRect, attr, selected);
            }

            return(drewAtleastOnce);
        }