Topic: Allow zooming in Editor when mouse is over UI element

Currently one can only disable the ControlBase completely using the notInteractUnderGUI flag. Me personally I would like to disable dragging the camera when the input started on a UI element, but allow zooming when the user uses the mouse in the editor and the cursor is currently over a UI element. Cheers

Re: Allow zooming in Editor when mouse is over UI element

Hello.

Something like that:

using System.Collections.Generic;
using UnityEngine;
using UnityEngine.EventSystems;

#if UNITY_EDITOR
public class AllowZoomOnGUI : MonoBehaviour
{
    private OnlineMaps map;

    private void Start()
    {
        map = OnlineMaps.instance;
        map.notInteractUnderGUI = false;
        map.control.OnMapPress += OnMapPress;
    }

    public bool IsCursorOnUIElement(Vector2 position)
    {
        if (GUIUtility.hotControl != 0) return true;
        if (EventSystem.current == null) return false;

        PointerEventData pe = new PointerEventData(EventSystem.current);
        pe.position = position;

        List<RaycastResult> hits = new List<RaycastResult>();
        EventSystem.current.RaycastAll(pe, hits);
        if (hits.Count == 0) return false;

        GameObject go = hits[0].gameObject;
        if (go == gameObject) return false;

        return go.GetComponent<OnlineMapsMarkerInstanceBase>() == null && go.GetComponent<OnlineMapsBuildingBase>() == null;
    }

    private void OnMapPress()
    {
        if (IsCursorOnUIElement(map.control.GetInputPosition()))
        {
            map.control.OnUpdateAfter += CancelMapDrag;
        }
    }

    private void CancelMapDrag()
    {
        map.control.OnUpdateAfter -= CancelMapDrag;
        map.control.isMapDrag = false;
    }
}
#endif
Kind Regards,
Infinity Code Team.

Boost your productivity a lot and immediately using Ultimate Editor Enhancer. Trial and non-commerce versions available.