playMaker

Author Topic: GUI Element Hit Test  (Read 19154 times)

Alex Chouls

  • Administrator
  • Hero Member
  • *****
  • Posts: 4005
  • Official Playmaker Support
    • LinkedIn
GUI Element Hit Test
« on: June 12, 2011, 10:13:40 AM »
Performs a Hit Test on a Game Object with a GUITexture or GUIText component.

Not thoroughly tested, so post any bugs you find to this thread!

tobbeo

  • 1.2 Beta
  • Full Member
  • *
  • Posts: 186
Re: GUI Element Hit Test
« Reply #1 on: June 12, 2011, 04:35:09 PM »
Look at that! Your request from the other thread was filled, and quickly! Nicely done Alex.

giyomu

  • 1.2 Beta
  • Full Member
  • *
  • Posts: 108
    • blog
Re: GUI Element Hit Test
« Reply #2 on: June 12, 2011, 09:33:45 PM »
haha nice Alex :)

joeyjr

  • 1.2 Beta
  • Playmaker Newbie
  • *
  • Posts: 12
Re: GUI Element Hit Test
« Reply #3 on: July 14, 2011, 07:34:19 PM »
Hi guys!

I'm new to this forum and this is my first post.  Where is this script that is mentioned in this thread? I don't see a link to it anywhere or maybe it's here somewhere and I just don't know how to access it?  I'm just getting started using PlayMaker and I'm stuck on getting the touch event to work on iPad.  I can't get it to work on a GUITexture so I tried using the "Touch Event" action along with the "Play SM2 Animation" action attached to a sprite gameObject and it sort of works, but it doesn't isolate the touch area to the sprite object even though I have attached a box collider. Instead the entire iPad screen triggers the button which is not what I want.  Any suggestions?  Thanks,

Joey

joeyjr

  • 1.2 Beta
  • Playmaker Newbie
  • *
  • Posts: 12
Re: GUI Element Hit Test
« Reply #4 on: July 14, 2011, 07:36:02 PM »
Oops! My bad.  I found the link to the script. I'll try it out now.

joeyjr

  • 1.2 Beta
  • Playmaker Newbie
  • *
  • Posts: 12
Re: GUI Element Hit Test
« Reply #5 on: July 15, 2011, 02:07:44 PM »
I couldn't get this script to work at all. From what I could see it doesn't ask you for the width and height dimensions of the GUI Texture... it just asks for the x and y coordinates and the vector position point. Does it need a collider in order to only apply to the GUITexture? I also wasn't clear how to apply this script in my state machine.

For those who are interested I did, however come up with a suitable workaround, but it doesn't use this script.  What I did was this...

I used the "Touch Event Multiplatform Script" from the "PuppetFSM" collection of actions available on this forum because it uses a standard box collider to define the active area and instead of using a Unity GUITexture I used SpriteManager2.  It was a little more work to set up, but it is working fine on iOS  :o and even better, I can now have a "touch" animation state, an "idle" animation state and sound effects for each button.  All the SM2 UI buttons I created were parented to my Main Camera and positioned accordingly. 

Alex Chouls

  • Administrator
  • Hero Member
  • *****
  • Posts: 4005
  • Official Playmaker Support
    • LinkedIn
Re: GUI Element Hit Test
« Reply #6 on: July 26, 2011, 01:09:09 AM »
This action exposes the HitTest method in GUI Texture and GUI Text components. You specify a screen position (generally a mouse or touch position stored by another action) and the action tests to see if it hits the specified GUI Element - no need for a collider, it just uses the GUI Elements screen rectangle. You'd generally use this with other mouse or touch actions to transition to another state when a GUI Element is clicked on or touched.


Damian

  • 1.2 Beta
  • Full Member
  • *
  • Posts: 188
    • Permaximum Betty
Re: GUI Element Hit Test
« Reply #7 on: July 31, 2011, 02:07:13 AM »
Cant get it to work.
Did work 1 time and then i add stuff to move a character and then it did break.
Now i cant get it to work at all.

What happens is that its get into en infinite loop.
Maybe i doing it wrong, but there is no information on how this works.

If i put it in one state then it will move to next state as soon i press play button.
In the next state i return it to this state.

So i tried to do this.
First state i add a action for check the touchscreen. I also add this action script.
If its true it should move to next state?

Second state i check the vector3 for the object. add some value to the vector3 value and move the object to that.
Then i finished it and it should return to state one.

But it dont work. it leaves the first state even if nothing is happen on the screen. it cant happen anything for it has no screen to get the input from in the first place. So the value should always be false.
So why does it go to the next state?



EDIT:
I did find out why it breaks.
If I untick Normalize then it goes into a loop, but if I tick it then it works like it should.
Need to see if it works well with the other stuff to.

EDIT2:
When i try to do get a vector3 from an object then use the action to add value to this vector3 that i did store in a new variable then move the object to this value it breaks again and going into a loop.
Shall i not be able to move a object from this code?

 
« Last Edit: July 31, 2011, 02:38:59 AM by Damian »

Damian

  • 1.2 Beta
  • Full Member
  • *
  • Posts: 188
    • Permaximum Betty
Re: GUI Element Hit Test
« Reply #8 on: July 31, 2011, 08:32:47 PM »
Still cant get this to work on a gui texture.
I did make a new FSM to check the screen and just change color on it. that one i do put on the camera.
Un the gui texture i did put a copy of the first, but with this action.
So instead the Touch event sent the event it just store the finger_id.
I read up this finger_id to get the position.
This position i use in this action.
But it dont send it to the other state at all.

Do I need to use position and all x,y at the same time?

Cant you do a simple lab for this so we (me) can test it out and see if it works.
I have spent 1 day with this and I cant still get it to work.

giyomu

  • 1.2 Beta
  • Full Member
  • *
  • Posts: 108
    • blog
Re: GUI Element Hit Test
« Reply #9 on: July 31, 2011, 09:57:54 PM »
I can try to make you a small video to use thsi action , and so it work on iOS / android , I am just not sure where you hit the wall exactly

what a bout a simple set up like >> while on hit gui > rotate a cube, and stop when release ?

I can do that then send link to you for this if this can help ;)

Damian

  • 1.2 Beta
  • Full Member
  • *
  • Posts: 188
    • Permaximum Betty
Re: GUI Element Hit Test
« Reply #10 on: July 31, 2011, 10:03:11 PM »
Sure it would work.
I can then use it to move left or right.
Should not be so hard. :-)

Well its just that i cant get it to work at all. its dont reakt on my touch on the gui and move the object.
In unity3d i can check it with alt-click and then it work, but not on the phone.
I did also check the touch info was right ant that works to,
So i really dont know were i do wrong.

It would be very nice if you could do this :-)

giyomu

  • 1.2 Beta
  • Full Member
  • *
  • Posts: 108
    • blog
Re: GUI Element Hit Test
« Reply #11 on: July 31, 2011, 10:58:59 PM »
first video, I recommand a save as as it take a bit of space sorry XD

http://dl.dropbox.com/u/915650/PMVideo/GuiHitTexture01.mov

the second part come, i will edit the post once loaded in dropbox

Edit > second video

http://dl.dropbox.com/u/915650/PMVideo/GuiHit02.mov

ok hope that help you , sorry for my narrative , I am not tutorial expert guy ^^...so I look for my words all time  ;D
« Last Edit: July 31, 2011, 11:06:46 PM by giyomu »

Damian

  • 1.2 Beta
  • Full Member
  • *
  • Posts: 188
    • Permaximum Betty
Re: GUI Element Hit Test
« Reply #12 on: July 31, 2011, 11:31:36 PM »
Well i will look at it as soon i can. i just messing with my phone and kernel. new firmware from samsung.. lol


EDIT:
Well i did download it and look at it. I guess you talk french normally, buts its okey  ;)
But it was very hard to see much. everything was very small.
But i will try to see and listen and maybe i can understand it better then. :)

« Last Edit: August 01, 2011, 12:22:14 AM by Damian »