Author Topic: UIGrid, how to get the index from a child  (Read 3965 times)

FOX_ITA

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 5
    • View Profile
UIGrid, how to get the index from a child
« on: January 27, 2014, 03:27:09 PM »
Hello there,

i'm pretty new to NGUI and i'm using it a lot.
But i can't figure out hot to determinate the index of a child clicked on the UIGrid.

I got a UIScrollView with attached an UIGrid with as a children different UIButtons.

How can i get the index or position of pressed button in the grid?

for example if i click on the first one i can see that is pressed the item 0 into the UIGrid.

Many thanks,

cheers!

Nicki

  • Global Moderator
  • Hero Member
  • *****
  • Thank You
  • -Given: 33
  • -Receive: 141
  • Posts: 1,768
    • View Profile
Re: UIGrid, how to get the index from a child
« Reply #1 on: January 27, 2014, 04:35:31 PM »
  1. //assuming this is on the child
  2. UIGrid gridReference;
  3.  
  4. void OnClick()
  5. {
  6. int xPos = transform.localPosition.x;
  7. int index = (int) xPos / gridReference.cellWidth; //or cellheight
  8. }

FOX_ITA

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 5
    • View Profile
Re: UIGrid, how to get the index from a child
« Reply #2 on: January 28, 2014, 07:50:51 AM »
Thanks a lot,

i'm gonna test it right now!