Mikael Gyth
Topic Author
Posts: 33
Joined: 15 Aug 2013, 12:53

VisualtreeHelper not catching click on ComboBox

19 Oct 2014, 17:18

Hello.
I tried to use VisualTreeHelper to stop clicks from going trough the GUI to the underlaying GameObjects.
And this seem to work fine except when I click on a item in a ComboBox. Is there a way to get around this?

The code I use.
...
        root = Camera.main.GetComponent<NoesisGUIPanel>().GetRoot<Grid>();
    }
...
#if UNITY_EDITOR
    private void OnMouseDown()
    {
        var hit = VisualTreeHelper.HitTest(root, new Point(Input.mousePosition.x, Input.mousePosition.y));
        if (hit.visualHit == null)
        {
            if (_gridMngr.GetCellOccupied())
                _gui.OpenMenuComponent();
            else
                _gui.OpenMenu();
        }
    }
#endif
Last edited by Mikael Gyth on 23 Oct 2014, 09:08, edited 1 time in total.
 
User avatar
sfernandez
Site Admin
Posts: 1912
Joined: 22 Dec 2011, 19:20

Re: VisualtreeHelper not catching clik on ComboBox

20 Oct 2014, 14:00

Hi,

Can you please try the following and let me know if it worked, I think we have something wrong in our side:
    Visual root;

    void Start()
    {
        root = VisualTreeHelper.GetRoot(
            Camera.main.GetComponent<NoesisGUIPanel>().GetRoot<Grid>());
    }
...
#if UNITY_EDITOR
    private void OnMouseDown()
    {
        var hit = VisualTreeHelper.HitTest(root, new Point(Input.mousePosition.x, Input.mousePosition.y));
        if (hit.visualHit == null)
        {
            if (_gridMngr.GetCellOccupied())
                _gui.OpenMenuComponent();
            else
                _gui.OpenMenu();
        }
    }
#endif
 
Mikael Gyth
Topic Author
Posts: 33
Joined: 15 Aug 2013, 12:53

Re: VisualtreeHelper not catching clik on ComboBox

20 Oct 2014, 14:51

Just tested it and still get clicks trough the ComboBox. (It might be trough all of the GUI but the ComboBox is the only element overlapping the GameObjects)
 
User avatar
sfernandez
Site Admin
Posts: 1912
Joined: 22 Dec 2011, 19:20

Re: VisualtreeHelper not catching clik on ComboBox

20 Oct 2014, 17:05

But with my code the HitTest still returns null visualHit?
 
Mikael Gyth
Topic Author
Posts: 33
Joined: 15 Aug 2013, 12:53

Re: VisualtreeHelper not catching clik on ComboBox

21 Oct 2014, 09:44

What happens is (With either of the original code or the code provided from you):
- When I click on parts of the GUI (other than the ComboBox) the click doesn't go through. The hit test is not triggered as the underlaying GameObjects aren't hit.
Image
- When I click on the grid the HitTest is triggered and it returns "Noesis.HitTestResult"

- When I click on the ComboBox the click goes through, hits the underlaying GameObject and it returns "Noesis.HitTestResult"
Image
 
User avatar
sfernandez
Site Admin
Posts: 1912
Joined: 22 Dec 2011, 19:20

Re: VisualtreeHelper not catching clik on ComboBox

21 Oct 2014, 11:41

Ok, I understand.

I think I found what was wrong in our side. Please overwrite the NoesisUIRenderer.cs script at Assets/Plugins/NoesisGUI/Scripts/Core folder with the one attached here.
Attachments
NoesisUIRenderer.zip
(4.16 KiB) Downloaded 100 times

Who is online

Users browsing this forum: No registered users and 1 guest