diff --git a/Runtime/BrowserView.cs b/Runtime/BrowserView.cs index e5040048f0f0fc16da15424c02f8d24d5caafce5..f76c66b00adb6bfcd1f99aeffb67ee60ef76ed7f 100644 --- a/Runtime/BrowserView.cs +++ b/Runtime/BrowserView.cs @@ -2,44 +2,38 @@ using ChromeDevTools; using ChromeDevTools.Protocol.Input; using Newtonsoft.Json; using Newtonsoft.Json.Serialization; -using System; using System.Collections; -using UnityEditor.Experimental.GraphView; +using System.Collections.Generic; using UnityEngine; using UnityEngine.EventSystems; using UnityEngine.UI; -using UnityEngine.UIElements; [RequireComponent(typeof(RawImage))] public class BrowserView : MonoBehaviour, IPointerDownHandler, IPointerMoveHandler, IPointerUpHandler, IPointerEnterHandler, IDropHandler, IPointerExitHandler { #region json serializer - /// <summary> - /// JsonSerializer for the user space objects (e.g. transfering objects that have been droped on the BrowserView) - /// Users are allowed to change serializer settings to their liking. - /// </summary> - public static JsonSerializer serializer; + /// <summary> /// Json serializer settings for the user space objects (e.g. transfering objects that have been droped on the BrowserView) /// Users are allowed to change serializer settings to their liking. /// </summary> - public static JsonSerializerSettings serializerSettings; - static BrowserView() + public static JsonSerializerSettings serializerSettings = new JsonSerializerSettings { - // initialize the JsonSerializer - serializerSettings = new JsonSerializerSettings - { - ContractResolver = new CamelCasePropertyNamesContractResolver(), - Converters = new JsonConverter[] + ContractResolver = new CamelCasePropertyNamesContractResolver(), + Converters = new List<JsonConverter>() { - new ColorConverter(), - new Vector2Converter(), - new Vector3Converter(), - new Vector4Converter() + new ColorConverter(), + new Vector2Converter(), + new Vector3Converter(), + new Vector4Converter() } - }; - serializer = JsonSerializer.Create(serializerSettings); - } + }; + /// <summary> + /// JsonSerializer for the user space objects (e.g. transfering objects that have been droped on the BrowserView) + /// Users are allowed to change serializer settings to their liking. + /// </summary> + public static JsonSerializer serializer = JsonSerializer.Create(serializerSettings); + #endregion json serializer private Browser browser; @@ -184,11 +178,13 @@ public class BrowserView : MonoBehaviour, IPointerDownHandler, IPointerMoveHandl private Vector2Int toBrowserCoordinates(Vector2 eventPos) { + Vector2 localPoint; + RectTransformUtility.ScreenPointToLocalPointInRectangle(rectTransform, eventPos, null, out localPoint); + // invert y because the browser has y=0 on the top - Vector2 invertedPos = new Vector2(eventPos.x, rectTransform.rect.size.y - eventPos.y); - // TODO: fix coordinate transformation, maybe use image size instead of rectTransform, if possible - Vector2 browserCoorinate = tab.size / rectTransform.rect.size * invertedPos; - Debug.Log($"eventPos: {eventPos}, invertedPos: {invertedPos}, browserCoordinate: {browserCoorinate}"); + Vector2 invertedLocalPos = new Vector2(localPoint.x, rectTransform.rect.size.y - localPoint.y); + Vector2 browserCoorinate = tab.size / rectTransform.rect.size * invertedLocalPos; + Debug.Log($"eventPos: {eventPos}, invertedLocalPos: {invertedLocalPos}, browserCoordinate: {browserCoorinate}"); return new Vector2Int((int) browserCoorinate.x, (int) browserCoorinate.y); }