- Home /
Resize a button while it's active
I want to resize a button while it's being pressed. At the moment I have a style with no image as background (_style.normal.background = null) and Buttons are being drawn using some images and that style. I would like to define a size of the buttons being displayed for the same layer but in the active state instead of normal and I have no idea how to do it.
code:
public class Buildings : MainSubPanel {
private Rect[] _boxes;
private GUIStyle _style;
private Texture2D[] _icons;
public Buildings(Swapper swapper, Texture2D[] icons) : base(swapper){
int i = 0;
int n = 0;
int shift = 10;
_icons = icons;
_boxes = new Rect[12];
_style = new GUIStyle();
_style.normal.background = null;
while(i < 3){
while(n < 4){
_boxes[i*4+n] = new Rect(15+shift+shift*n+50*n, 15+shift+shift*i+i*50, 50, 50);
++n;
}
n = 0;
++i;
}
}
public override void draw(){
int i = 0;
while(i<_icons.Length){
if(GUI.Button(_boxes[i], _icons[i], _style)){
_swapper.swap(i);
}
i++;
}
}
}
Answer by Berenger · Feb 06, 2012 at 12:43 AM
You could use a different rect for the active button. It's going to look weird though, as the active state in a button, when it's not a selection grid (and even the the state is OnNormal) is very fast, just the time of a clic.
Could you explain how does SelectionGrid works? It just creates a grid of images?
A grid of buttons actually. The difference being that, when you clic one, it stays activated and deactive the previous one. For example, if you have a selection grid with those elements : "Banana", "Apple", "Strawberry", you can choose which one you're going to eat (only one $$anonymous$$d you !). For the script part, check out the manual.
Ok, I see. But I'm not sure if that's what I want. Here is a sample of my idea, so I hope anyone knows how to realize it without creating X images for active backgrounds or X additional styles (new style for every button).
Sample: on the right part of image 2nd button is being pressed but not released yet -> http://img215.imageshack.us/img215/9855/29395185.jpg
P.S.: all the images will be different as it's obvious