Page 1 of 1

Truncate Mouse Events to Scene when work with NoesisGUI

Posted: 17 Nov 2015, 14:05
by satish
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???

Re: Truncate Mouse Events to Scene when work with NoesisGUI

Posted: 18 Nov 2015, 02:42
by Scherub
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.

Re: Truncate Mouse Events to Scene when work with NoesisGUI

Posted: 18 Nov 2015, 17:47
by cosmo
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;
            }
        }

Re: Truncate Mouse Events to Scene when work with NoesisGUI

Posted: 20 Nov 2015, 18:31
by sfernandez
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.

Re: Truncate Mouse Events to Scene when work with NoesisGUI

Posted: 23 Nov 2015, 11:55
by satish
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 :)