Author Topic: Setting UICamera.fallThrough  (Read 11178 times)

darishi

  • Guest
Setting UICamera.fallThrough
« on: August 30, 2012, 02:00:47 PM »
Hello everyone.

I'm trying to figure out how to set UICamera.fallThrough. I'm sure its very easy but I can't seem to figure it out.

Do I have to declare a public GameObject on the UICamera script to then be able to drag the other event handler camera into it?  I would greatly appreciate an answer, I'm sure its super simple! :)

Thanks for you help!

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Setting UICamera.fallThrough
« Reply #1 on: August 30, 2012, 04:51:42 PM »
UICamera.fallThrough = yourListenerGameObject.

I suggest setting this from your listener's script.

AllThatIsOne

  • Guest
Re: Setting UICamera.fallThrough
« Reply #2 on: January 09, 2013, 06:09:06 PM »
Does anyone have an example of exactly what this looks like written in C# if written on a script on 'ListenerGameObject'? Recently migrated over to C# and am having some syntax issues getting this to work. Learning as I go :)

Thanks in advance,

HypoXic5665

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 8
    • View Profile
Re: Setting UICamera.fallThrough
« Reply #3 on: January 09, 2013, 09:24:27 PM »
I know in JavaScript it would look like:

  1. var cam: UICamera;
  2.  
  3. function Start(){
  4.         cam.fallThrough = this.gameObject;
  5. }
Where you would drag your main camera (with a UICamera component) onto the cam variable in the inspector. Or get it dynamically of course.

I am not familiar with C# so I would'nt be able to say for sure. I am sure someone here knows though.

EDIT:
Played around with it abit in C#.

"UICamera.fallThrough = this.gameObject;"

On a script on your 'ListenerGameObject'  will do, as ArenMook stated above.
« Last Edit: January 10, 2013, 12:50:53 AM by HypoXic5665 »

Majicpanda

  • Jr. Member
  • **
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 83
    • View Profile
Re: Setting UICamera.fallThrough
« Reply #4 on: February 03, 2013, 01:59:22 AM »
Could someone pastebin an example of what a listener and ui manager type script would look like?

Not really understanding how a single script could handle all of your game's UI.  Right now my game has objects with colliders and if they have an OnClick type of method I have custom raycasting telling the object to call that method (very inefficient and goes through nGUI). If the object needs to interact with the game itself it speaks to the GameManager singleton.

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Setting UICamera.fallThrough
« Reply #5 on: February 03, 2013, 08:34:49 AM »
Why are you doing that? NGUI already does all the raycasting for you, and will call the methods automatically. Are you trying to raycast into the 3D space? Just attach a UICamera script to your game camera, and your 3D scene objects will also receive NGUI events.

Majicpanda

  • Jr. Member
  • **
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 83
    • View Profile
Re: Setting UICamera.fallThrough
« Reply #6 on: February 03, 2013, 11:24:20 AM »
I think related to another post I made that you responded to, I'm still trying to gather how nGUI works to be able to use what you said..

My 2nd ortho camera (UICamera attached) has items to click on, but these items are on iOS and need to allow detection when the finger crosses over them.  OnHover isn't supported on iOS, so that's why I've been raycasting.  The 2nd camera has no UIPanels or Draggable or anything similar... and if I need to use them I'm not really certain how.

To complicate things just a tad more, the player clicks on the screen and an object that is on the 2nd ortho camera moves to that position.  Code below was all for pre iOS so now everything is broken and I'm sure this entire block will be scrapped once I understand how to use nGUI and touch ID's.

  1.                 if(Input.GetMouseButtonDown(0)) {
  2.                         //constantly get mouse position on screen
  3.                         Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
  4.                         RaycastHit hit = new RaycastHit();
  5.                        
  6.                         Vector3 touchPos = Camera.main.ScreenToWorldPoint(Input.mousePosition);
  7.                         //ensure game isnt paused before allowing clicking on treasure
  8.                         if(!GameManager.Instance.GetComponent<AreaTimer>().gamePaused) {
  9.                                 TargetingCursor.transform.position = new Vector3(touchPos.x, touchPos.y, TargetingCursor.transform.position.z);
  10.                         }      
  11.                 }
  12.  

« Last Edit: February 03, 2013, 12:17:47 PM by Majicpanda »

Majicpanda

  • Jr. Member
  • **
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 83
    • View Profile
Re: Setting UICamera.fallThrough
« Reply #7 on: February 03, 2013, 03:58:53 PM »
Ignore the above code for now I understand a bit more what's going on.

What I don't understand is how the script knows to handle the events.

User touches screen on nGUI widget, 2d GUI absorbs the event and 2nd camera doesn't receive any events correct?

User touches middle of screen not on an nGUI widget, how do you get the touchPosition if you're not simply calling collider detection?  I need to move an object to the touch pos and convert ScreenToWorldPoint(touchPos)

UICamera.lastTouchPosition would be 2d and 3d cameras, so how do you only get the value of what fell through? UICamera seems to be a static object and so if I have 2 cameras with UICamera attached it doesnt know the difference.

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Setting UICamera.fallThrough
« Reply #8 on: February 03, 2013, 05:34:33 PM »
When there are multiple UICameras, the camera with the highest depth gets to handle its objects first. If a raycast is performed and something was hit, that something will receive the notifications (OnHover, OnPress, OnClick, etc), and other UICameras will not be considered.

Majicpanda

  • Jr. Member
  • **
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 83
    • View Profile
Re: Setting UICamera.fallThrough
« Reply #9 on: February 03, 2013, 06:29:34 PM »
Sounds right... 2d UI = depth 1, ortho camera = depth 0.

Start function in my UIManager has UICamera.fallThrough = gameObject; set in the script.

How do you only detect UICamera.hoveredObject and other such things that "ONLY" fall through? That's the piece I'm missing... I need to manually detect that my 2nd camera received a mouse click and get the touch position.  I could see this functionality needed in a game like Diablo where the UI receives all the input first, but you click into the world and collide with the terrain and your UIManager handles it and moves the character or does whatever you need... if a ground target spell is active etc to cast it at that location, whatever.

Am I going about this completely wrong?  i need the touch position converted to world space and then move an object to that location in world space.

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Setting UICamera.fallThrough
« Reply #10 on: February 04, 2013, 09:06:16 AM »
FallThrough is for events that do not get handled by UICamera-seen objects. If you need a copy of events, regardless of whether they get handled or not, use UICamera.genericEventHandler.

However, for your case I don't see the need for it. If your game camera has a UICamera, the terrain itself will receive your OnHover event when you hover over it.

Majicpanda

  • Jr. Member
  • **
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 83
    • View Profile
Re: Setting UICamera.fallThrough
« Reply #11 on: March 02, 2013, 10:37:10 PM »
Really sorry to dig this back up but is there anyone with a snippet or something so I can understand this better?

The following is a very beginning phase to what I'm going to try to accomplish, but I need it to only work if my 2DGUI doesn't detect a hit on an object on it.  What would you change UICamera.lastTouchPosition to?

  1.         void Update() {
  2.                 if(Input.GetMouseButtonDown(0)) {
  3.                         Vector3 mousePos = Camera.main.ScreenToWorldPoint(new Vector3(UICamera.lastTouchPosition.x, UICamera.lastTouchPosition.y, 28f));
  4.                                                
  5.                         GameObject instance = (GameObject) Instantiate(_projectile, _muzzlePoint.transform.position, _muzzlePoint.transform.localRotation);
  6.                         instance.transform.LookAt(mousePos);
  7.                 }
  8.         }
  9.  

Majicpanda

  • Jr. Member
  • **
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 83
    • View Profile
Re: Setting UICamera.fallThrough
« Reply #12 on: March 03, 2013, 02:02:24 AM »
Wow never mind it finally clicked.... it's just treated as another game object in your world and you filter objects by tags etc like you would a custom ray casting script.... fantastic, NGUI +5 yet again.