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

9-Slice equivalent in Unity

Discussion in 'Immediate Mode GUI (IMGUI)' started by auzette, May 13, 2009.

  1. auzette

    auzette

    Joined:
    Mar 23, 2009
    Posts:
    74
    Hey there. In past Flash projects, we made use of 9-slicing, a technique used on elements such as buttons to make the button stretch in a specified middle portion of a button while *not* stretching defined edges of a button (so it doesn't *look* stretched around the edges).

    Looking at the skin and style settings, I've tested some of the values (offsets, particularly) to achieve the same effect, but haven't had success.

    Is there a way to achieve 9-slice like behavior with styles? I'd love to be able to use a single button image across the project to handle various sizes of buttons.

    Thanks.
     
  2. HiggyB

    HiggyB

    Unity Product Evangelist

    Joined:
    Dec 8, 2006
    Posts:
    6,183
    Yes, that's exactly how our GUI works. You provide an image, then you specify in your Skin or Style the amount of padding to use for the edges/corners so as not to stretch. Download the built-in GUI skin and have a closer look and you'll see what I'm talking about (I believe it's the border property in particular).
     
  3. auzette

    auzette

    Joined:
    Mar 23, 2009
    Posts:
    74
    Ah!!!! The padding. Duh. Thanks!
     
  4. richierich1204

    richierich1204

    Joined:
    May 20, 2010
    Posts:
    45
    Using this method I am able to get the corners to display correctly, but the interior stretches the texture. Is there a way to scale the texture on the interior as well?
     
  5. Nition

    Nition

    Joined:
    Jul 4, 2012
    Posts:
    780
    Border does the interior slicing.
     
  6. pengo

    pengo

    Joined:
    Jun 3, 2013
    Posts:
    5