private void DrawFolderIcon(string path, Rect selectionRect, PvRuleItem rule, bool selected) { string name = Path.GetFileName(path); IconSizeType sizeType = PvCustomizerUtility.GetSizeType(selectionRect); Rect iconRect = PvCustomizerUtility.ItemRectToIconRect(selectionRect, sizeType == IconSizeType.TreeView); Color tint = selected ? (Color)PvCustomizerGUI.ICON_SELECTED_TINT : Color.white; #region Icon Drawing if (sizeType == IconSizeType.Small || sizeType == IconSizeType.TreeView && rule.smallIcon.sprite != null) { TryDrawIconBackground(); iconRect = PvCustomizerUtility.ItemRectToIconRect(selectionRect, true); PvCustomizerGUI.DrawSprite(iconRect, rule.smallIcon.sprite, tint: tint, scaleMode: PvScaleMode.ScaleToFit); } else if (sizeType == IconSizeType.Large && rule.largeIcon.sprite != null) { TryDrawIconBackground(); PvCustomizerGUI.DrawSprite(iconRect, rule.largeIcon.sprite, tint: tint, scaleMode: PvScaleMode.ScaleToFit); } #endregion #region Text Drawing Rect textRect = PvCustomizerUtility.ItemRectToTextRect(selectionRect); textRect.height++; PvCustomizerGUI.DrawBackground(textRect); if (rule.textBackground.sprite != null) { PvCustomizerGUI.DrawSprite(textRect, rule.textBackground.sprite, tint: tint, scaleMode: PvScaleMode.StretchToFill); } using (new TempFontSize(10)) { PvCustomizerGUI.DrawTextDirect(textRect, name, textAnchor: sizeType == IconSizeType.Small || sizeType == IconSizeType.TreeView ? PvAnchor.MiddleLeft : PvAnchor.MiddleCenter, color: rule.textColor); } #endregion void TryDrawIconBackground() { if (rule.eraseDefaultFolder) { PvCustomizerGUI.DrawBackground(iconRect); } } }
private IconStyle CompileStyle(object asset, PvIconAttribute attr, Rect fullRect) { IconSizeType sizeType = PvCustomizerUtility.GetSizeType(fullRect); Rect iconRect = PvCustomizerUtility.ItemRectToIconRect(fullRect, sizeType == IconSizeType.TreeView); IconStyle style = new IconStyle { IsSet = true, Tint = attr.Tint, CustomValues = attr.CustomData, FontStyle = attr.FontStyle, SizeType = PvCustomizerUtility.GetSizeType(iconRect), MaxSize = attr.MaxSize, ScaleMode = attr.ScaleMode }; //----------complex assignments #region Material if (string.IsNullOrEmpty(attr.Material)) { style.Material = null; } else { ValueableMemberCache.Pair matMember = ValueableMemberCache.GetValueables(asset.GetType()). Find(v => v.Member.Name == attr.Material && v.ValueType == typeof(Material)); style.Material = matMember.Member?.GetMemberValue(asset) as Material; } #endregion if (PvCustomizerUtility.TryParseGridRect(attr.Grid, out int rows, out int cols, out int pos)) { float width = iconRect.width / cols; float height = iconRect.height / rows; float x = width * (pos % cols); float y = height * (pos / rows); style.DrawRect = new Rect(iconRect.x + x, iconRect.y + y, width, height); }
private bool TryDrawFromValue(object asset, object value, Rect fullRect, PvIconAttribute attr, bool selected) { if (!CanDisplay(attr.Display, PvCustomizerUtility.GetSizeType(fullRect))) { return(false); } if (value == null) { return(false); } if (!TryGetDrawer(value.GetType(), out var drawer)) { return(false); } //compile the style from attribute into something we can pass along to drawer IconStyle style = CompileStyle(asset, attr, fullRect); try { if (selected) { style.Tint *= PvCustomizerGUI.ICON_SELECTED_TINT; } drawer.Draw(value, fullRect, selected, style); } catch { //ignore } return(true); bool TryGetDrawer(Type valueType, out IDrawer d) { //get proper drawer for this member's value type d = Registry.GetIconDrawer(valueType); return(d != null); } }
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); }