/// <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); } } }
public override void OnGUI(Rect position, SerializedProperty property, GUIContent label) { EditorGUI.BeginProperty(position, label, property); if (untintedStyle == null) { untintedStyle = new CompiledStyleDefinition(new StyleDefinition() { MaxSize = 64 }); tintedStyle = new CompiledStyleDefinition(new StyleDefinition() { MaxSize = 64 }); } var sliderRect = new Rect(position.x, position.y + 12, position.width, EditorGUIUtility.singleLineHeight); var previewArea = new Rect(position.x, sliderRect.yMax + 12, position.width, position.yMax - 24 - sliderRect.yMax); var untintedRect = new Rect(previewArea.x, previewArea.y, (previewArea.width * 0.5f) - 3.0f, previewArea.height); var tintedRect = new Rect(untintedRect.xMax + 6.0f, previewArea.y, untintedRect.width, previewArea.height); var tintStrengthProperty = property.FindPropertyRelative("tintStrength"); tintStrengthProperty.floatValue = EditorGUI.Slider(sliderRect, label, tintStrengthProperty.floatValue, 0.0f, 1.0f); if (Event.current.type == EventType.Repaint) { var tint = new ColorTint(tintStrengthProperty.floatValue * 1.0f); tintedStyle.Tint = tint.Apply(Color.white); AssetIconDrawer.DrawSprite(untintedRect, AssetIconResources.CurrentTheme.SampleImage, untintedStyle, false); AssetIconDrawer.DrawSprite(tintedRect, AssetIconResources.CurrentTheme.SampleImage, tintedStyle, false); } EditorGUI.EndProperty(); }
/// <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); } }