<?xml version="1.0" encoding="utf-8"?>
<feed xmlns="http://www.w3.org/2005/Atom">
	<title type="html"><![CDATA[Infinity Code Forum — Allow zooming in Editor when mouse is over UI element]]></title>
	<link rel="self" href="https://forum.infinity-code.com/extern.php?action=feed&amp;tid=1862&amp;type=atom" />
	<updated>2021-10-29T18:18:47Z</updated>
	<generator>PunBB</generator>
	<id>https://forum.infinity-code.com/viewtopic.php?id=1862</id>
		<entry>
			<title type="html"><![CDATA[Re: Allow zooming in Editor when mouse is over UI element]]></title>
			<link rel="alternate" href="https://forum.infinity-code.com/viewtopic.php?pid=7838#p7838" />
			<content type="html"><![CDATA[<p>Hello.</p><p>Something like that:<br /></p><div class="codebox"><pre><code>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&lt;RaycastResult&gt; hits = new List&lt;RaycastResult&gt;();
        EventSystem.current.RaycastAll(pe, hits);
        if (hits.Count == 0) return false;

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

        return go.GetComponent&lt;OnlineMapsMarkerInstanceBase&gt;() == null &amp;&amp; go.GetComponent&lt;OnlineMapsBuildingBase&gt;() == 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</code></pre></div>]]></content>
			<author>
				<name><![CDATA[Alex Vertax]]></name>
				<uri>https://forum.infinity-code.com/profile.php?id=2</uri>
			</author>
			<updated>2021-10-29T18:18:47Z</updated>
			<id>https://forum.infinity-code.com/viewtopic.php?pid=7838#p7838</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Allow zooming in Editor when mouse is over UI element]]></title>
			<link rel="alternate" href="https://forum.infinity-code.com/viewtopic.php?pid=7836#p7836" />
			<content type="html"><![CDATA[<p>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</p>]]></content>
			<author>
				<name><![CDATA[negruj0w1tsch]]></name>
				<uri>https://forum.infinity-code.com/profile.php?id=1428</uri>
			</author>
			<updated>2021-10-29T14:57:37Z</updated>
			<id>https://forum.infinity-code.com/viewtopic.php?pid=7836#p7836</id>
		</entry>
</feed>
