x


Find position of SelectionGrid element clicked

How do you find the screenspace position of a SelectionGrid element that is clicked?

more ▼

asked Jan 12 '11 at 06:45 AM

ina gravatar image

ina
3.4k 500 554 615

I would like to know the answer to this question too :/ any hits yet?

Jun 20 '11 at 02:53 PM HHameline
(comments are locked)
10|3000 characters needed characters left

2 answers: sort voted first

It's pretty simple. You just feed the int you get back from the function into the string array you give to the function, like this:

var selGridInt : int = 0;
var selStrings : String[] = ["Grid 1", "Grid 2", "Grid 3", "Grid 4"];

    function OnGUI()
    {
       selGridInt = GUI.SelectionGrid (Rect (25, 25, 100, 100), selGridInt, selStrings, 2);
       Debug.Log(selStrings[selGridInt]);
    }
more ▼

answered Jun 20 '11 at 04:01 PM

ckfinite gravatar image

ckfinite
1.3k 5 9 24

Sorry What I meant and what I think ina meant was the actual rect position that the selected button in the grid is at. Not the position of the grid itself or the index of of the selected option. Sorry for any confusion.

Jun 20 '11 at 04:05 PM HHameline

Well, you could divide the number of elements by the width of buttons to get the number of rows, then partition the original rect into that many rows. Then, if the partitioned rects are in the same order as the original setup, you can just feed the index into that. I will give sample code in a bit.

Jun 20 '11 at 04:08 PM ckfinite

Ok, that's what I have happening now, I'm just going to be making a lot of the grids over the next few days and I was wondering if there was a nice built in way to do it that I hadn't found. I'll just keep my script nice and dynamic :P thanks for the help

Jun 20 '11 at 04:12 PM HHameline
(comments are locked)
10|3000 characters needed characters left

If you have a list of eg. buttons inside your grid, I would take the selection-value from the Grid and multiply it with the pixelheight of the button-style. This might be 25 pixels or something.

Would that work or are your content of different heights?

more ▼

answered Aug 02 '11 at 10:17 PM

BerggreenDK gravatar image

BerggreenDK
2.4k 54 62 75

(comments are locked)
10|3000 characters needed characters left
Your answer
toggle preview:

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Topics:

x3811
x501
x144
x38
x16

asked: Jan 12 '11 at 06:45 AM

Seen: 1566 times

Last Updated: Aug 02 '11 at 10:17 PM