Truncate Mouse Events to Scene when work with NoesisGUI
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???
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
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:
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.
If so, you just have to do a hit test on your root panel. Something like this should work:
Code: Select all
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;
Re: Truncate Mouse Events to Scene when work with NoesisGUI
I use the following method to check if I am over an ngui object or not.
Code: Select all
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;
}
}
-
-
sfernandez
Site Admin
- Posts: 2027
- Joined:
Re: Truncate Mouse Events to Scene when work with NoesisGUI
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.
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
First of all SORRY for late reply (I'm on Vacation)
Thank you very much both @Scherub and @cosmo. Your suggestions are works greatly
Thanks alot
Thank you very much both @Scherub and @cosmo. Your suggestions are works greatly

Thanks alot

Who is online
Users browsing this forum: Bing [Bot] and 0 guests