Author Topic: Changing size of all buttons  (Read 4468 times)

jimbo999

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 5
    • View Profile
Changing size of all buttons
« on: November 07, 2014, 10:07:44 AM »
I have button which i have copied many times, which are now close to each other like a button bar.
I want be able to change the size of one button in the scene and all other buttons should get resized too.
When the width changes, they will overlap so i need to calculate the new positions based on my resizing.
All ideas to solve this i have in mind are very stupid and complicated i guess, any easy solution ?

Thx in advance

technoir

  • Newbie
  • *
  • Thank You
  • -Given: 3
  • -Receive: 1
  • Posts: 27
    • View Profile
Re: Changing size of all buttons
« Reply #1 on: November 07, 2014, 10:25:37 AM »
You'll want to look into Prefabs in order to have any changes to a 'master' object also change its copies: http://docs.unity3d.com/Manual/Prefabs.html

Off the top of my head, if you set the pivot of the UISprite widget of the line prefab to the side you want them to meet at (left, or right, etc., rather than the centre), then when resized they should extend from the pivot. Then you'll need to store all lines in a list and work out where to place them  (now from their new pivot position, not centre) based on the width/height of their previous one.

Not tested this, so let me now how it goes :)
« Last Edit: November 07, 2014, 11:18:54 AM by technoir »

jimbo999

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 5
    • View Profile
Re: Changing size of all buttons
« Reply #2 on: November 07, 2014, 03:54:13 PM »
Many thx,

the prefab were the right solution, now everything works out. In order to change the button size i can change the prefab by changing the values of the width/heigth. Is is possible to do the same by just resizing on of the buttons made of this prefab ?
When i do this now, just this buttons changes in size, the prefab and so the others buttons stay the same. This way would
be more "visual".
EDIT:
This was really easy to solve, just click the apply button on the prefab line in the prefab item inspector window.

Another thing:
The buttons now get placed correct in the grid by changing the grid cell width dynamic to the button width. This works well,
but after i stop playing the scene the buttons get placed back to the original wrong position. How to save this positions ? I guess that was what you were trying to tell me with the lists ?
« Last Edit: November 07, 2014, 04:06:19 PM by jimbo999 »

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Changing size of all buttons
« Reply #3 on: November 07, 2014, 04:08:36 PM »
Right click the grid, Execute.