Author Topic: Event system vs fallthrough  (Read 9417 times)

Stevorino

  • Guest
Event system vs fallthrough
« on: July 31, 2013, 07:44:50 AM »
Hi all -

Let me preface this post by stating I am VERY new to Unity, NGUI, and programming in general.  So far, NGUI has been a lifesaver.

So I am in the early stages of building an RTS-like game.

I have a lot of the GUI built out and am working on getting the actual objects moving, fighting, building, etc. 

I quickly realized my mouse clicks were impacting both NGUI AND my game world.

There seems to be two options for proceeding:

1) build out the entire control scheme based on the NGUI event system
2) program scripts to handle fallthrough actions and let NGUI assign the actions to existing control methods

My question:
Which is the best/most efficient and why?  Or is there something else it sounds like I am missing?

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Event system vs fallthrough
« Reply #1 on: July 31, 2013, 12:41:38 PM »
#1, because NGUI takes care of all the events for you, including intercepting them when they hit a widget. If you don't want to attach event handlers to everything (all your game objects and such), then use the UICamera.fallThough setting -- it will receive all events that were not handled by NGUI.

Stevorino

  • Guest
Re: Event system vs fallthrough
« Reply #2 on: July 31, 2013, 12:53:04 PM »
Hi AM!

I really don't think it'd take that long to add event handlers to everything - most of my prefabs inherit from one of a few classes that I'd figure I can store OnClick() and OnHover() in.

Would you have a recommendation for how to do the eventhandling for a click & drag to select multiple units (ex: in starcraft click ground and drag mouse to draw a rectangular box that, upon release, selects all units).

Thanks for your support on this project - I have no doubt it will have saved my hundreds of hours when it's all said and done!

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Event system vs fallthrough
« Reply #3 on: July 31, 2013, 12:57:48 PM »
Use fallthrough for that. In Press, record the starting position, in release, select all units that fall underneath the screen rectangle created by the two points (math).

Stevorino

  • Guest
Re: Event system vs fallthrough
« Reply #4 on: July 31, 2013, 01:11:39 PM »
Awesome - thank you so much!

Pangamini

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 6
    • View Profile
Re: Event system vs fallthrough
« Reply #5 on: August 19, 2013, 05:06:47 AM »
Hello there

I am using fallthrough with an eventListener on it and it works, the problem is that gameObjects with colliders that don't consume any events but are in the layer flagged in the UICamera seem not to let events fall through (and thus event is lost). Is there any simple workaround, or do i have to implement some custom event capturing?

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Event system vs fallthrough
« Reply #6 on: August 19, 2013, 09:00:52 AM »
Every camera that sees objects that you want to interact with needs to have a UICamera script attached. Fallthrough is for "if nothing else" functionality.

Maxii

  • Jr. Member
  • **
  • Thank You
  • -Given: 4
  • -Receive: 0
  • Posts: 55
    • View Profile
    • Strategic Forge
Re: Event system vs fallthrough
« Reply #7 on: August 19, 2013, 09:10:34 AM »
I believe the clarification P (and I) am looking for is why gameobjects (with colliders) that implement one event handler like OnClick() but not another (like OnHover(), still consume the OnHover() event (it doesn't fall thru) sent by the camera when on the same layer as the camera's event receiver mask...
I'm looking for an artist partner to complement my programming skill in developing a space-based Civilization-like empire building game, ala GalCiv2 or Distant Worlds based on Unity3D.

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Event system vs fallthrough
« Reply #8 on: August 19, 2013, 05:37:00 PM »
That's just how NGUI works. Events go to the first collider hit by the raycast, regardless of whether the collider has a script that can handle that event or not.

Maxii

  • Jr. Member
  • **
  • Thank You
  • -Given: 4
  • -Receive: 0
  • Posts: 55
    • View Profile
    • Strategic Forge
Re: Event system vs fallthrough
« Reply #9 on: August 19, 2013, 05:52:24 PM »
Thanks for the clarification.  :)
I'm looking for an artist partner to complement my programming skill in developing a space-based Civilization-like empire building game, ala GalCiv2 or Distant Worlds based on Unity3D.