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