Author Topic: UICamea.hoveredObject, UICamera.fallThrough, IsOver UI Problem.  (Read 6577 times)

moibios

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 2
    • View Profile
I`m poor at English. I hope to understand...

I using the version of Unity 4.5.2f1.

I using the version of NGUI 3.0.2 version.

This code work no problem 3.0.2 version.

if (UICamera.hoveredObject == null )
        return;

if (Input.GetMouseButtonDown(0))
{
      Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);

      RaycastHit rayHit = new RaycastHit();
      if (Physics.Raycast(ray, out rayHit) == false)
           return;

      MyFunction();
}

updating the version of NGUI 3.9.0 version.

after this code don`t work.

I find same problem at NGUI 3 Support.

So I changed code.

1. if (UICamera.hoveredObject != UICamera.fallThrough)
       return;

2. if (UICamera.isOverUI)
       return;

changed code, work no problem on Unity Editor.

but, changed code not working on Mobile. (mobile is Samsung Galaxy3, Android os Icecream 4.0.4).

seemed to ignore "if function" on Mobile.

I hope to help my problem.

Thank you.

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: UICamea.hoveredObject, UICamera.fallThrough, IsOver UI Problem.
« Reply #1 on: July 03, 2015, 11:34:17 AM »
"is over UI" and "hover" only works with the mouse. How can there be a "hover" event with a touch screen? Think about it...

You should not have been doing any kind of Input.GetMouseButtonDown checks yourself. Use NGUI's events, like OnPress, OnClick, etc.

moibios

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 2
    • View Profile
Re: UICamea.hoveredObject, UICamera.fallThrough, IsOver UI Problem.
« Reply #2 on: July 04, 2015, 08:33:27 PM »
When 3D Object and NGUI Object located same position on viewPort, "if(UICamera.hoveredObject != null)" code only touched NGUI Object.

This code is no problem NGUI 3.0.2 version, Editor and Mobile too.

But, latest version "UICamera.hoveredObject" is pointed "UIRoot Object", nothing NGUI Object on "ScreenPointToRay".

So, latest version "if(UICamera.hoveredObject != null)" code is always "True". 3D object and NGUI object touched both.

If "IsOverUI" and "hoverdObject" and "fallThrough" is only works with the mouse, how can I solve this problem?

I want to be touch only NGUI Object, 3D object and GUI object when in the same position in the viewport




ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: UICamea.hoveredObject, UICamera.fallThrough, IsOver UI Problem.
« Reply #3 on: July 06, 2015, 08:07:23 PM »
Something like this:

if (UICamera.lastHit.collider != null && UICamera.lastHit.collider.gameObject != UICamera.list[0].gameObject) { // do something }

However the proper solution is like I suggested -- using NGUI events all the way, not your own Input checks. This hack wouldn't be necessary if you stuck to NGUI events. NGUI is fully capable of sending events to all objects, not just UI but 3D as well (if you attach UICamera to your main camera too).

NaxIonz

  • Jr. Member
  • **
  • Thank You
  • -Given: 3
  • -Receive: 0
  • Posts: 70
    • View Profile
Re: UICamea.hoveredObject, UICamera.fallThrough, IsOver UI Problem.
« Reply #4 on: July 13, 2015, 02:15:11 PM »
Something like this:

if (UICamera.lastHit.collider != null && UICamera.lastHit.collider.gameObject != UICamera.list[0].gameObject) { // do something }

However the proper solution is like I suggested -- using NGUI events all the way, not your own Input checks. This hack wouldn't be necessary if you stuck to NGUI events. NGUI is fully capable of sending events to all objects, not just UI but 3D as well (if you attach UICamera to your main camera too).

That is not a very helpful solution. Our game input also broke when we updated to 3.9.0b. To assume that NGUI can be the only system processing input is incredibly restrictive to developers.

We had been using IsOverUI to early out of our own game logic input handling. And I find it a bit rude to be so dismissive that IsOverUI shouldn't apply to touch input as well.

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: UICamea.hoveredObject, UICamera.fallThrough, IsOver UI Problem.
« Reply #5 on: July 15, 2015, 12:01:51 AM »
How is it rude and dismissive? How do you physically detect a finger hovering over a button using touch-screen devices? You can't. Similarly, how is "is over UI" check supposed to work with you have more than one active touch, one is interacting with UI and the other does not? Which one should be checked to be is over UI? Keep in mind if you need this functionality with touch-screen devices, then you can always loop through active touches: UICamera.activeTouches. Each of those has a "pressed" object set which tells you the game object where the touch started.

Using NGUI input is necessary because it ensures that NGUI's events are filtered properly, going to whatever is on top and preventing whatever is below the widgets from receiving events. You know, the stuff you now have to do manually using the "is over" checks.

Using NGUI system all the way removes the need to do it entirely -- that's exactly the point.

NaxIonz

  • Jr. Member
  • **
  • Thank You
  • -Given: 3
  • -Receive: 0
  • Posts: 70
    • View Profile
Re: UICamea.hoveredObject, UICamera.fallThrough, IsOver UI Problem.
« Reply #6 on: July 16, 2015, 02:01:29 PM »
How is it rude and dismissive?

Specifically in reference to how you blew him off with your initial reply.

How do you physically detect a finger hovering over a button using touch-screen devices? You can't.

Correct - most devices can't (I know some Samsung devices can). The idea that the property implies is that you want to query if the input in question was over a UI element. And that is a perfectly reasonable question to ask the system.

Similarly, how is "is over UI" check supposed to work with you have more than one active touch, one is interacting with UI and the other does not? Which one should be checked to be is over UI? Keep in mind if you need this functionality with touch-screen devices, then you can always loop through active touches: UICamera.activeTouches. Each of those has a "pressed" object set which tells you the game object where the touch started.

Quite simply, the property would be true if any touch was over a UI element. Once again, that seems very reasonable. Sure, there could be additional methods to determine which one, if we care, but I digress.

Using NGUI input is necessary because it ensures that NGUI's events are filtered properly, going to whatever is on top and preventing whatever is below the widgets from receiving events. You know, the stuff you now have to do manually using the "is over" checks.
Using NGUI system all the way removes the need to do it entirely -- that's exactly the point.

Thinking that the UI system would govern gameplay is incredibly naive, limiting, and also just flat out bad engineering (due to unnecessary coupling).

Now, of course, there is a simple solution to all of this, but the frustrating part was the the behaviour of IsOverUI changed dramatically.

For anyone that does want to find out if the input is over the UI, it's pretty simple, but it does involve a raycast, which is expensive, so clearly you want some gating logic before it gets to this point:
  1.      
  2. if (Input.touchCount > 0 && UICamera.Raycast(Input.GetTouch(0).position)) {
  3.   // Do something or nothing if we are over the UI
  4.   return;
  5. }
  6.  


ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: UICamea.hoveredObject, UICamera.fallThrough, IsOver UI Problem.
« Reply #7 on: July 16, 2015, 11:12:26 PM »
As I said, this is unnecessary.
  1. void Update ()
  2. {
  3.     if (UICamera.activeTouches.Count > 0)
  4.         Debug.Log("Is Over: " + UICamera.activeTouches[0].current.name);
  5. }
To repeat what I said... the change was necessary because "is over" implies 1 input source, but there can be many. Even with multiple active touches "is over" is ambigious. Look inside UICamera.isOverUI -- see how it works with "currentTouch"? This function is meant to be used from inside NGUI event system -- that's the only time "currentTouch" is valid. Bypassing NGUI means you have to check active touches yourself like I explained above.