Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
U
Unity Webview
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
FrameIT
Unity Webview
Commits
e6dc344c
Unverified
Commit
e6dc344c
authored
1 year ago
by
Bjoern Esswein
Browse files
Options
Downloads
Patches
Plain Diff
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
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
Runtime/BrowserView.cs
+22
-26
22 additions, 26 deletions
Runtime/BrowserView.cs
with
22 additions
and
26 deletions
Runtime/BrowserView.cs
+
22
−
26
View file @
e6dc344c
...
@@ -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
);
}
}
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment