Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 Next capture
2021 2022 2023
2 captures
13 Jun 22 - 14 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
2
Question by Fattie · Jun 15, 2012 at 09:25 AM · touchbuttonsevents.net

"Capturing" "events" in Unity....

Very typically, you might do this somewhere

 function OnGUI ()
     if ( GUI.Button( Rect(20,20,50,50), "Go For It" ) ) _allez();

but somewhere else you are doing this,

 function FixedUpdate()
     if (Input.touchCount == 1 )
         {
         thisPointWorldSpace:Vector3 =
           gamecam.ScreenToWorldPoint( Input.touches[0].position );
         
         if ( something like thisPointWorldSpace.y >
           fuckingButtonMarkers.position.z blah blah ) 
             return;
          
         _createAstoundingSpaceshipAt( thisPointWorldSpace );
         }


Of course, both pieces of code get the "event", the touch.

(I use 'event' in a general sense, I have no clue if .Net ... or whatever this is .. uses "events" or if they are nomeclatured differently, or the like.)

(This is of course very counterintuitive to say a cocoa programmer, where you have to sign-up for events, explicitly pass them on if you happen to want to, and so on.)

My hard question

(1) Can you intercept such "events" at some lower level? And then decide WTF to do with them or not do with them?

Essentially, in your button code can you more or less say "Oh, and by the way, do NOT let any one else get this touch 'event'".

I love and adore the slop flexibility in unity "everyone gets all events" but in a word can you bypass this or work with it?

My easier question

(2) In fact, what idiom do most people use to handle the situation described? obviously you can use a crappy boolean global or annoying little exclusion boxes or ???????

Thanks for this...

Comment
Add comment · Show 3
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image whydoidoit · Jun 15, 2012 at 09:30 AM 0
Share

Damn good question :) You can certainly "Use" and event in OnGUI, but whether that stops it being passed to non OnGUI code is another matter - and I don't know the answer (and am not at my computer to check!). It wouldn't fix your touchCount issue of that I'm sure.

avatar image whydoidoit · Jun 15, 2012 at 09:45 AM 0
Share

It might be just me, but looking through my code (admittedly on my iPad) I obviously got fed up with mouse simulation of touch and something to do with phases which meant I wrote a wrapper that I added a CancelTouch method to that forces my touchCount to return 0 and clears the status of fingers on the screen (ignores them until they are lifted and replaced).

avatar image Fattie · Jun 15, 2012 at 01:54 PM 0
Share

The whole thing's a big drama. I mean surely you can "capture" events and then either pass them on or not?

Someone's gotta know this !

1 Reply

· Add your reply
  • Sort: 
avatar image
1
Best Answer

Answer by Bunny83 · Jun 15, 2012 at 02:31 PM

No, you can't intercept events since Unity either pass the events directly to the relevant objects, like OnCollisionEnter, Start, ... or it provides state information about a certain inputs like the touches property does. This is already the lowest level. It's the direct system information of that touch. It isn't passed to anyone. You have to read it manually. If you want a special distribution, you can implement your own event dispatcher where you sould specify a certain priority for different subscriber / listener or something like that.

Comment
Add comment · Show 5 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Fattie · Jun 15, 2012 at 02:33 PM 0
Share

I see ... "If you want a special distribution, you can implement your own event dispatcher ..."

Just to be clear, you mean, you could NOT use the usual OnCollisionEnter, OnGui etc etc .. you'd have to, indeed, use your own replacements?

$$anonymous$$akes sense ...

avatar image Bunny83 · Jun 15, 2012 at 02:44 PM 0
Share

Well in most cases you could implement your own handling / distrubution of your events. Unfortunately in case of the touch --> mouse conversion there's not much you can do against it. Unity generates "mouse events" out of the touch information behind the scenes. They wanted to make the development on mobile "simpler" but it's less flexible that way. For the OnGUI stuff it would be great when we had a CreateEvent() function that allows us to simulate mouse or keyboard events. Of course that's only helpful when you can disable the automatic mouse-event generation.

avatar image Fattie · Jun 15, 2012 at 04:31 PM 0
Share

I see - thanks again.

the very bottom line here is "you can't do it" and just work with it like it is!

Suits me fine ! Thanks

avatar image Bunny83 · Jun 15, 2012 at 05:06 PM 0
Share

Unity is really great, but it's always the same: When trying to make it comfortable and easy you propably sacrifice flexibility. If Unity provides both, very low-level-control and high-level-comfort it would be a mess ;)

avatar image Fattie · Sep 29, 2012 at 07:28 PM 0
Share

Bunn, I want it both ways ! :)

This question has arisen again ...

http://answers.unity3d.com/questions/325034/blocking-click-through-on-gui-components.html

Your answer

Hint: You can notify a user about this post by typing @username

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

Answers Answers and Comments

5 People are following this question.

avatar image avatar image avatar image avatar image avatar image

Related Questions

How can I fix this Coroutine Camera? 1 Answer

Take string from OnClick event and throw into variable. 1 Answer

How to access the persistent listener gameobjects on a button? 1 Answer

NGUI Buttons in ScrollView. 0 Answers

Check if a listener has already been added to a button? 2 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges