satish
Topic Author
Posts: 6
Joined: 06 Oct 2015, 13:03

Truncate Mouse Events to Scene when work with NoesisGUI

17 Nov 2015, 14:05

Hi to All,

I created UI using NoesisGUI Scroll Viewer. I have also Mouse Operation script for Navigation (Rotate, Move and Zoom).

When i scroll the Scroll Viewer UI, Navigation Script also fired. So How can i control when Mouse operate UI, does not create fire the Navigation Script???
 
User avatar
Scherub
Posts: 141
Joined: 06 May 2014, 20:53
Contact:

Re: Truncate Mouse Events to Scene when work with NoesisGUI

18 Nov 2015, 02:42

If I understand you right you don't want to interact with the scene while you're interacting with the UI?

If so, you just have to do a hit test on your root panel. Something like this should work:
var mousePosition = UnityEngine.Input.mousePosition;
var point = new Point(mousePosition.x, UnityEngine.Screen.height - mousePosition.y);

HitTestResult hit = VisualTreeHelper.HitTest(RootPanel, point);

bool isMouseOverGuiElement = hit.visualHit != null;
If "isMouseOverGuiElement" is true you know that you're interacting with the UI and can stop doing whatever you wanted to do in your navigation script.
 
cosmo
Posts: 14
Joined: 27 Mar 2015, 13:52

Re: Truncate Mouse Events to Scene when work with NoesisGUI

18 Nov 2015, 17:47

I use the following method to check if I am over an ngui object or not.
        private Visual _mainContent;

        public bool OverUIElement
        {
            get
            {
                if (_mainContent == null)
                {
                    var panel = Camera.main.GetComponent<NoesisGUIPanel>();
                    _mainContent = VisualTreeHelper.GetRoot(panel.GetContent());
                }
                var x = Input.mousePosition.x;
                var y = Screen.height - Input.mousePosition.y;
                var hitTestResult = VisualTreeHelper.HitTest(_mainContent, new Point(x, y));
                if (hitTestResult.visualHit != null)
                {
                    return true;
                }
                return false;
            }
        }
 
User avatar
sfernandez
Site Admin
Posts: 1915
Joined: 22 Dec 2011, 19:20

Re: Truncate Mouse Events to Scene when work with NoesisGUI

20 Nov 2015, 18:31

As Scherub and cosmo (thanks to both) correctly pointed, you can determine if you are over any UI element by using the VisualTreeHelper.HitTest method.

Then you can determine what to do in your navigation scripts depending on the result.
 
satish
Topic Author
Posts: 6
Joined: 06 Oct 2015, 13:03

Re: Truncate Mouse Events to Scene when work with NoesisGUI

23 Nov 2015, 11:55

First of all SORRY for late reply (I'm on Vacation)

Thank you very much both @Scherub and @cosmo. Your suggestions are works greatly 8-)

Thanks alot :)

Who is online

Users browsing this forum: No registered users and 0 guests