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
GitLab community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
FrameIT
Unity Webview
Commits
7aeeb0b0
Commit
7aeeb0b0
authored
3 months ago
by
baletiballo
Browse files
Options
Downloads
Patches
Plain Diff
Automatically scale the browser tab to the size of the viewport
parent
a78b5dc3
Branches
Branches containing commit
No related tags found
No related merge requests found
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
Runtime/ChromeDevtools/BrowserTab.cs
+1
-7
1 addition, 7 deletions
Runtime/ChromeDevtools/BrowserTab.cs
Runtime/WebViewComponent.cs
+16
-10
16 additions, 10 deletions
Runtime/WebViewComponent.cs
with
17 additions
and
17 deletions
Runtime/ChromeDevtools/BrowserTab.cs
+
1
−
7
View file @
7aeeb0b0
...
...
@@ -25,11 +25,6 @@ namespace bessw.Unity.WebView.ChromeDevTools
/// </summary>
public
Vector2Int
Size
{
get
;
private
set
;
}
/// <summary>
/// Scales the page in the browser tab
/// </summary>
public
int
PageScaleFactor
{
get
;
private
set
;
}
/// <summary>
/// width and height of the stream from the browser
/// </summary>
...
...
@@ -87,7 +82,7 @@ namespace bessw.Unity.WebView.ChromeDevTools
yield
return
devtools
.
readLoop
();
}
public
async
Task
SetSize
AndScale
(
Vector2Int
size
,
int
pageScaleFactor
)
public
async
Task
SetSize
(
Vector2Int
size
)
{
await
devtools
.
SendCommandAsync
(
new
setDeviceMetricsOverride
{
...
...
@@ -97,7 +92,6 @@ namespace bessw.Unity.WebView.ChromeDevTools
screenHeight
=
size
.
y
,
});
Size
=
size
;
PageScaleFactor
=
pageScaleFactor
;
}
/// <summary>
...
...
This diff is collapsed.
Click to expand it.
Runtime/WebViewComponent.cs
+
16
−
10
View file @
7aeeb0b0
...
...
@@ -57,19 +57,22 @@ namespace bessw.Unity.WebView
public
event
Action
OnWebViewComponentReady
;
private
RawImage
rawImage
;
private
RectTransform
rectTransform
;
private
RectTransform
viewPort
;
private
Canvas
scaler
;
public
bool
headlessBrowser
=
true
;
//TODO: handle changed targetUrl
public
string
targetUrl
=
"https://google.de"
;
public
in
t
PageScaleFactor
=
3
;
//
public
floa
t PageScaleFactor =
2.0f; // We can just grab the factor of the canvas, no need for a manual number
// Start is called before the first frame update
private
void
Start
()
{
rawImage
=
this
.
gameObject
.
GetComponent
<
RawImage
>();
rectTransform
=
this
.
gameObject
.
GetComponent
<
RectTransform
>();
viewPort
=
this
.
gameObject
.
GetComponent
<
RectTransform
>();
scaler
=
this
.
gameObject
.
GetComponentInParent
<
Canvas
>();
Browser
.
headless
=
headlessBrowser
;
browser
=
Browser
.
getInstance
();
...
...
@@ -78,7 +81,9 @@ namespace bessw.Unity.WebView
var
c
=
StartCoroutine
(
browser
.
OpenNewTab
(
targetUrl
,
(
BrowserTab
bt
)
=>
{
tab
=
bt
;
_
=
tab
.
SetSizeAndScale
(
new
Vector2Int
((
int
)
rectTransform
.
rect
.
width
,
(
int
)
rectTransform
.
rect
.
height
)
/
PageScaleFactor
,
PageScaleFactor
);
// Set the size of the Tab to the size of the viewport
//_ = tab.SetSize(Vector2Int.RoundToInt(this.gameObject.GetComponentInParent<Canvas>().renderingDisplaySize));
OnRectTransformDimensionsChange
();
StartCoroutine
(
tab
.
Update
());
//StartCoroutine(createScreenshots());
...
...
@@ -95,10 +100,11 @@ namespace bessw.Unity.WebView
{
if
(
tab
is
not
null
)
{
var
size
=
new
Vector2Int
((
int
)
rectTransform
.
rect
.
width
,
(
int
)
rectTransform
.
rect
.
height
)
/
PageScaleFactor
;
if
(
tab
.
Size
!=
size
)
var
size
=
new
Vector2
(
viewPort
.
rect
.
width
,
viewPort
.
rect
.
height
)
*
scaler
.
scaleFactor
;
Vector2Int
sizeInt
=
Vector2Int
.
RoundToInt
(
size
);
if
(
tab
.
Size
!=
sizeInt
)
{
_
=
tab
.
SetSize
AndScale
(
size
,
PageScaleFactor
);
_
=
tab
.
SetSize
(
sizeInt
);
}
}
}
...
...
@@ -211,11 +217,11 @@ namespace bessw.Unity.WebView
private
Vector2Int
toBrowserCoordinates
(
Vector2
eventPos
)
{
RectTransformUtility
.
ScreenPointToLocalPointInRectangle
(
rectTransf
or
m
,
eventPos
,
null
,
out
Vector2
localPoint
);
RectTransformUtility
.
ScreenPointToLocalPointInRectangle
(
viewP
or
t
,
eventPos
,
null
,
out
Vector2
localPoint
);
// invert y because the browser has y=0 on the top
Vector2
invertedLocalPos
=
new
Vector2
(
localPoint
.
x
,
rectTransf
or
m
.
rect
.
size
.
y
-
localPoint
.
y
);
Vector2
textureScale
=
tab
.
StreamSize
/
rectTransf
or
m
.
rect
.
size
;
Vector2
invertedLocalPos
=
new
Vector2
(
localPoint
.
x
,
viewP
or
t
.
rect
.
size
.
y
-
localPoint
.
y
);
Vector2
textureScale
=
tab
.
StreamSize
/
viewP
or
t
.
rect
.
size
;
Vector2
browserCoordinate
=
invertedLocalPos
*
textureScale
;
// / tab.ViewportScaleFactor;
//Debug.Log($"eventPos: {eventPos}, invertedLocalPos: {invertedLocalPos}, browserCoordinate: {browserCoordinate}");
return
new
Vector2Int
((
int
)
browserCoordinate
.
x
,
(
int
)
browserCoordinate
.
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