Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Drawing Single Sprite from Multiple Sprite sheet onto Label

Discussion in 'Immediate Mode GUI (IMGUI)' started by The_BenEvans, Dec 29, 2014.

  1. The_BenEvans

    The_BenEvans

    Joined:
    Jul 31, 2012
    Posts:
    138
    Hey all,

    Just trying to find a way of using a single sprite from a sprite sheet with multiple sprites as the texture for a custom editor window label/button.

    So to make it a bit clearer:
    -Get a individual sprite from a multiple sprite sheet
    -Get it's texture
    -Assign it to EditorGUI Label/Button
    -???
    -Profit!

    Currently using the selected sprite's texture works, but displays the entire sheet instead of just the one sprite.

    Any ideas?
     
  2. TonyLi

    TonyLi

    Joined:
    Apr 10, 2012
    Posts:
    12,523
    You can't easily specify texture coordinates with EditorGUI.LabelField, GUI.Label, or GUI.Button. You could pass them a custom GUIStyle with clipping=true and imagePosition set to the correct sprite in the texture, but this seems kind of klunky. Can you use GUI.DrawTextureWithTexCoords instead?
     
  3. The_BenEvans

    The_BenEvans

    Joined:
    Jul 31, 2012
    Posts:
    138
    Ah, so am I right in thinking sprites are mainly just coordinates with a reference to their parent texture?

    I'll have a go with your idea later, thanks
     
  4. TonyLi

    TonyLi

    Joined:
    Apr 10, 2012
    Posts:
    12,523
    The Sprite class provides a little more than that, but that's the heart of it.