Skip to content
Snippets Groups Projects
Unverified Commit e6dc344c authored by Bjoern Esswein's avatar Bjoern Esswein
Browse files

Fixed unity to browser coordinate system conversion and refactored serializer settings.

parent 322d9860
No related branches found
No related tags found
No related merge requests found
......@@ -2,35 +2,25 @@ 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()
{
// initialize the JsonSerializer
serializerSettings = new JsonSerializerSettings
public static JsonSerializerSettings serializerSettings = new JsonSerializerSettings
{
ContractResolver = new CamelCasePropertyNamesContractResolver(),
Converters = new JsonConverter[]
Converters = new List<JsonConverter>()
{
new ColorConverter(),
new Vector2Converter(),
......@@ -38,8 +28,12 @@ public class BrowserView : MonoBehaviour, IPointerDownHandler, IPointerMoveHandl
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);
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment