-
Notifications
You must be signed in to change notification settings - Fork 696
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
An example to show how to align a webview to a uGUI RectTransform #816
base: master
Are you sure you want to change the base?
Conversation
Use Camera.main.WorldToScreenPoint() method to convert world position to screen position. |
Thank you for your comment. It actually depends on Canvas Render Mode. If we set it "Screen Space" as in this example, converting with Camera.main.WorldToScreenPoint() results wrong coordinates. If we set it "World Space", we should use Camera.main.WorldToScreenPoint() as you point. |
84542f3
to
298e2ff
Compare
How could I fit my webview in RectTransform, if my Canvas is in "Screen Space-Camera" render mode and my Canvas Scaler is in "Sclae with Screen Size" scale mode? |
@xinbot public static Bounds GetRectTransformBounds(RectTransform transform)
{
var corners = new Vector3[4];
transform.GetWorldCorners(corners);
for (var i = 0; i < 4; i++)
{
corners[i] = Camera.main.WorldToScreenPoint(corners[i]);
}
var bounds = new Bounds(corners[0], Vector3.zero);
for (var i = 1; i < 4; i++)
{
bounds.Encapsulate(corners[i]);
}
return bounds;
} |
Would this work to avoid drawing the webview under a device's notch or hole punch for cameras?
|
Your code should work for the "Portrait" mode, but I guess the following is more general: webViewObject.SetMargin(
Screen.safeArea.xMin,
Screen.height - Screen.safeArea.yMax,
Screen.width - Screen.safeArea.xMax,
Screen.safeArea.yMin); |
cf. #810 (comment)