1
\$\begingroup\$

this is how a sprite shows in the inspector. It's white pixelart with transparent background. Is there a way to change the background checkered pattern color in the inspector so I can actually see the sprite?

Note: I don't want to change any color in the game, just the background in the inspector, in the editor, so there's some contrast and I can actually see the sprite pattern.

enter image description here

\$\endgroup\$
  • \$\begingroup\$ I don't know if that's a feature. If you own pro though you can use the black theme which has a darker checkered pattern for the sprite inspector background. \$\endgroup\$ – n_plum Feb 15 '17 at 21:47
  • \$\begingroup\$ @n_palum Yeah since I can't find anything similar, I guess it might not even be a feature. \$\endgroup\$ – Petruza Feb 17 '17 at 15:44
  • \$\begingroup\$ As far as I could tell, pro version would be your only option but it doesn't sound like you need the pro version \$\endgroup\$ – n_plum Feb 17 '17 at 15:45
2
\$\begingroup\$

Use a custom editor with sprite preview

(EDIT: now supports multi-sprite images)

  1. Create an empty script (or use one you already got), let's call that TestScript.
  2. Place this script on an empty game object.
  3. Add a Sprite Renderer component to that object.
  4. Add another script, let's name it SpritePreview. It should inherit from Editor. You can place the code for that class in the same file as the TestScript.

SpritePreview

[CustomEditor(typeof(TestScript))]
public class SpritePreview : Editor {
    public override void OnInspectorGUI() {
    var sr = ((TestScript)target).GetComponent<SpriteRenderer>();

    // it's not enough to check for the renderer as it might be empty
    if (sr && sr.sprite) {

        // we need the rect in pixels to reserve space in the layout system
        // we also use it for calculating the rect in percentage
        var rect = sr.sprite.rect;

        // reserve a rect in the layout of the editor, we will draw the sprite there
        var destRect = GUILayoutUtility.GetRect(rect.width, rect.height);

        // the texture, this object contains all of the sprites in case of a multiple sprites image
        var texture = sr.sprite.texture;

        // calculate the rect of the selected sprite as a percentage of the sprite sheet
        // this is how TexCoords work
        var rectAsPercentage = new Rect(rect.x / texture.width, rect.y / texture.height,
                               rect.width / texture.width, rect.height / texture.height);

        // draw the selected sprite
        GUI.DrawTextureWithTexCoords(destRect, texture, rectAsPercentage);
    }
    }
}
  1. Now select a sprite in the sprite renderer.
  2. You will see the preview in the editor, with grey background, like this: Result

EDIT: i've updated the script to also work with multiple sprite resources:

enter image description here

\$\endgroup\$
  • \$\begingroup\$ Thanks, looks like a great solution and a good introduction on extending the editor! Will try this. \$\endgroup\$ – Petruza Feb 20 '17 at 14:49
  • \$\begingroup\$ Please mark answer as accepted if this works for you :-) \$\endgroup\$ – lilotop Feb 20 '17 at 14:52
  • \$\begingroup\$ Count on it, as soon as I make myself some time to work with unity. Despite what I'd like, PHP is still paying my bills instead of Unity. \$\endgroup\$ – Petruza Feb 21 '17 at 13:58
  • \$\begingroup\$ I tried it, it does work but it displays the complete spritesheet, I already have that on the project view. I'd need to see the individual sprites in order to be able to select them. See the attached screenshot in my question. \$\endgroup\$ – Petruza Mar 1 '17 at 0:53
  • \$\begingroup\$ Try with the new code ;-) \$\endgroup\$ – lilotop Mar 1 '17 at 18:40
0
\$\begingroup\$

You can change texture type to advanced and uncheck Alpha Is Transparency checkbox. It still behaves as Sprite in the game as far as I tried, though be careful about other values and read about them before changing. Sprite still has transparency in the scene and the game views.

Alpha is not transparency

\$\endgroup\$
  • \$\begingroup\$ I don't have Advanced as an option for texture type, but I de have "Alpha is transparency", I unchecked it, it doesn't work. \$\endgroup\$ – Petruza Mar 1 '17 at 22:55
  • \$\begingroup\$ What do you mean, you must have it. It's in Unity, check out documentation. Just pick the texture or sprite in project folder and it's on the top, Texture Type - Advanced is last in the list. \$\endgroup\$ – Candid Moon _Max_ Mar 1 '17 at 23:40

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.