Working on a hobby-project, I am studying and reconstructing the various systems in MonterHunter.
For easier management of items, I’ve been trying to make CustomPreviews of my ScriptableObjects. This includes a preview of its in-game sprite with a UnityEngine.Color as tint applied to it, the sprite is used as black and white-template.
Now, since I did not have my Sprites packed, this worked fine for my custom preview:
public class ItemIconPreview : ObjectPreview
{
public override bool HasPreviewGUI() => true;
public override void OnPreviewGUI(Rect r, GUIStyle background)
{
if (target is Item_Object t)
{
GUI.DrawTexture(r, t.Sprite.texture, ScaleMode.ScaleToFit, true, 0, t.SpriteTint, 0, 0);
}
}
}
However, when my sprites are packed in an atlas, Sprite.texture is not pointing to the singular sprite anymore, but the entire atlas.
This renders the above snippet unusable, as the entire atlas is drawn in the preview, not my assigned sprite only:
Additionaly, GUI.DrawTexture() is the only method I found where I can apply a color; similar methods like GUI.DrawTextureRect() or EditorGUI.Draw... do not have a color parameter.
EditorGUI.DrawPreviewTexture() does a material parameter (not color, but close enough), but the texture problem is still there.
Is there a way to only draw the assigned sprite texture, not the entire atlas?
Or is there a better alternative, like instantiating an empty gameobject and attaching a SpriteRenderer component and then somehow displaying that?
Thanks for any idea or suggestions

