// // UniWebView.UI.cs // Created by Wang Wei (@onevcat) on 2025-04-19. // // This file is a part of UniWebView Project (https://uniwebview.com) // By purchasing the asset, you are allowed to use this code in as many as projects // you want, only if you publish the final products under the name of the same account // used for the purchase. // // This asset and all corresponding files (such as source code) are provided on an // “as is” basis, without warranty of any kind, express of implied, including but not // limited to the warranties of merchantability, fitness for a particular purpose, and // noninfringement. In no event shall the authors or copyright holders be liable for any // claim, damages or other liability, whether in action of contract, tort or otherwise, // arising from, out of or in connection with the software or the use of other dealing in the software. // using System; using UnityEngine; public partial class UniWebView { /// /// Represents the embedded toolbar in the current web view. /// public UniWebViewEmbeddedToolbar EmbeddedToolbar { get; private set; } /// /// Gets or sets the frame of current web view. The value is based on current `Screen.width` and `Screen.height`. /// The first two values of `Rect` is `x` and `y` position and the followed two `width` and `height`. /// public Rect Frame { get => frame; set { fullScreen = false; frame = value; UpdateFrame(); } } /// /// A reference rect transform which the web view should change its position and size to. /// Set it to a Unity UI element (which contains a `RectTransform`) under a canvas to determine /// the web view frame by a certain UI element. /// /// By using this, you could get benefit from [Multiple Resolutions UI](https://docs.unity3d.com/Manual/HOWTO-UIMultiResolution.html). /// /// public RectTransform ReferenceRectTransform { get => referenceRectTransform; set { fullScreen = false; referenceRectTransform = value; UpdateFrame(); } } private bool loggedLegacyToolbarSuppressedByEmbeddedToolbar; #pragma warning disable 618 private bool ShouldDriveLegacyToolbar() { if (!useToolbar) { return false; } if (!useEmbeddedToolbar) { return true; } if (!loggedLegacyToolbarSuppressedByEmbeddedToolbar) { loggedLegacyToolbarSuppressedByEmbeddedToolbar = true; UniWebViewLogger.Instance.Warning(() => "Detected legacy toolbar flag (useToolbar=true) together with embedded toolbar (useEmbeddedToolbar=true). " + "Suppressing legacy toolbar to avoid duplicate toolbars. Please update old prefab/scene serialization."); } return false; } #pragma warning restore 618 /// /// Updates and sets current frame of web view to match the setting. /// /// This is useful if the `referenceRectTransform` is changed and you need to sync the frame change /// to the web view. This method follows the frame determining rules. /// public void UpdateFrame() { Rect rect = NextFrameRect(); SyncFramePropertyIfNeeded(rect); UniWebViewInterface.SetFrame(listener.Name, (int)rect.x, (int)rect.y, (int)rect.width, (int)rect.height); } void SyncFramePropertyIfNeeded(Rect rect) { if (fullScreen || referenceRectTransform != null) { frame = rect; } } Rect UnmappedFrame() { if (fullScreen) { return new Rect(0, 0, Screen.width, Screen.height); } return referenceRectTransform != null ? referenceRectTransform.rect : frame; } Rect NextFrameRect() { if (fullScreen) { return FullScreenFrame(); } if (referenceRectTransform == null) { UniWebViewLogger.Instance.Info("Using Frame setting to determine web view frame."); return NativeFrameRect(frame); } UniWebViewLogger.Instance.Info("Using reference RectTransform to determine web view frame."); var worldCorners = new Vector3[4]; referenceRectTransform.GetWorldCorners(worldCorners); // var bottomLeft = worldCorners[0]; var topLeft = worldCorners[1]; // var topRight = worldCorners[2]; var bottomRight = worldCorners[3]; var canvas = referenceRectTransform.GetComponentInParent(); if (canvas == null) { return frame; } switch (canvas.renderMode) { case RenderMode.ScreenSpaceOverlay: break; case RenderMode.ScreenSpaceCamera: case RenderMode.WorldSpace: var camera = canvas.worldCamera; if (camera == null) { UniWebViewLogger.Instance.Critical(@"You need a render camera or event camera to use RectTransform to determine correct frame for UniWebView."); UniWebViewLogger.Instance.Info("No camera found. Fall back to ScreenSpaceOverlay mode."); } else { // bottomLeft = camera.WorldToScreenPoint(bottomLeft); topLeft = camera.WorldToScreenPoint(topLeft); // topRight = camera.WorldToScreenPoint(topRight); bottomRight = camera.WorldToScreenPoint(bottomRight); } break; default: throw new ArgumentOutOfRangeException(); } var unityFrame = new Rect( topLeft.x, Screen.height - topLeft.y, bottomRight.x - topLeft.x, topLeft.y - bottomRight.y ); return NativeFrameRect(unityFrame); } private Rect NativeFrameRect(Rect unityFrame) { #if UNITY_IOS && !UNITY_EDITOR return CalculateCocoaNativeFrameRect( unityFrame, Screen.width, Screen.height, UniWebViewInterface.NativeScreenWidth(), UniWebViewInterface.NativeScreenHeight(), GetStatusBarHeight() ); #elif UNITY_ANDROID && !UNITY_EDITOR try { var padding = UniWebViewInterface.GetContentViewPadding(); if (padding[0] != 0 || padding[1] != 0 || padding[2] != 0 || padding[3] != 0) { return CalculateNativeFrameRectWithContentPadding( unityFrame, Screen.width, Screen.height, UniWebViewInterface.NativeScreenWidth(), UniWebViewInterface.NativeScreenHeight(), padding[0], padding[1], padding[2], padding[3] ); } return CalculateNativeFrameRect( unityFrame, Screen.width, Screen.height, UniWebViewInterface.NativeScreenWidth(), UniWebViewInterface.NativeScreenHeight(), GetStatusBarHeight() ); } catch (Exception e) { UniWebViewLogger.Instance.Warning(() => $"Failed to calculate Android native frame: {e.Message}. Falling back to Unity frame."); } return unityFrame; #else return unityFrame; #endif } // Cocoa receives physical-pixel coordinates and converts them to points using its backing // scale. Unity's render resolution may be lower than that physical viewport, so a // RectTransform frame needs this mapping before crossing the native boundary. private static Rect CalculateCocoaNativeFrameRect( Rect unityFrame, float unityScreenWidth, float unityScreenHeight, float nativeScreenWidth, float nativeScreenHeight, float statusBarHeight ) { return CalculateNativeFrameRect( unityFrame, unityScreenWidth, unityScreenHeight, nativeScreenWidth, nativeScreenHeight, statusBarHeight ); } private static Rect CalculateNativeFrameRect( Rect unityFrame, float unityScreenWidth, float unityScreenHeight, float nativeScreenWidth, float nativeScreenHeight, float statusBarHeight ) { if (unityScreenWidth <= 0 || unityScreenHeight <= 0 || nativeScreenWidth <= 0 || nativeScreenHeight <= 0) { return unityFrame; } var contentHeight = Mathf.Max(0, nativeScreenHeight - statusBarHeight); var widthFactor = nativeScreenWidth / unityScreenWidth; var heightFactor = contentHeight / unityScreenHeight; return new Rect( unityFrame.x * widthFactor, statusBarHeight + unityFrame.y * heightFactor, unityFrame.width * widthFactor, unityFrame.height * heightFactor ); } // Maps a Unity frame into native coordinates when the host app applies window insets as // padding on the native content view (the pattern recommended by Google for edge-to-edge // enforcement since Android 15). In that layout the Unity player view occupies the padded // area of the content view, while UniWebView's container is positioned in the content // view's full coordinate space, so the frame is offset by the padding origin and scaled // into the padded area. private static Rect CalculateNativeFrameRectWithContentPadding( Rect unityFrame, float unityScreenWidth, float unityScreenHeight, float nativeScreenWidth, float nativeScreenHeight, float paddingLeft, float paddingTop, float paddingRight, float paddingBottom ) { if (unityScreenWidth <= 0 || unityScreenHeight <= 0 || nativeScreenWidth <= 0 || nativeScreenHeight <= 0) { return unityFrame; } var paddedWidth = nativeScreenWidth - paddingLeft - paddingRight; var paddedHeight = nativeScreenHeight - paddingTop - paddingBottom; if (paddedWidth <= 0 || paddedHeight <= 0) { return unityFrame; } var widthFactor = paddedWidth / unityScreenWidth; var heightFactor = paddedHeight / unityScreenHeight; return new Rect( paddingLeft + unityFrame.x * widthFactor, paddingTop + unityFrame.y * heightFactor, unityFrame.width * widthFactor, unityFrame.height * heightFactor ); } /// /// Applies a transformation to the web view, including rotation and scaling. /// /// This method allows you to rotate and scale the web view by specifying a /// object. The transformation is applied relative to the web view's current position and size, with its center /// as the anchor. /// /// The transformation includes: /// - **Rotation**: The angle (in degrees) by which the web view should be rotated. Positive values rotate the web /// view clockwise, while negative values rotate it counterclockwise. /// - **Scaling**: The scale factors for the X and Y axes. A scale factor of 1.0 means no scaling, while values /// greater than 1.0 enlarge the web view and values less than 1.0 shrink it. /// /// This method works on iOS and Android. It does nothing in Unity Editor on macOS. /// /// /// /// A object containing the rotation angle and scale factors to apply to the web /// view. /// public void SetTransform(UniWebViewTransform transform) { UniWebViewInterface.SetTransform(listener.Name, transform.Rotation, transform.ScaleX, transform.ScaleY); } /// /// Gets the current round corner radius applied to this web view. /// public UniWebViewCornerRadius CornerRadius => cornerRadius; /// /// Gets the current shadow configuration applied to this web view. /// public UniWebViewShadow Shadow => shadow; /// /// Sets the same round corner radius value for all corners. /// /// The radius applied to every corner. public void SetRoundCornerRadius(float radius) { SetRoundCornerRadius(UniWebViewCornerRadius.Uniform(radius)); } /// /// Sets round corner radius values for each individual corner. /// /// Radius at the top-left corner. /// Radius at the top-right corner. /// Radius at the bottom-left corner. /// Radius at the bottom-right corner. public void SetRoundCornerRadius( float topLeft, float topRight, float bottomLeft, float bottomRight ) { SetRoundCornerRadius(new UniWebViewCornerRadius(topLeft, topRight, bottomLeft, bottomRight)); } /// /// Applies the provided round corner radius configuration to the native web view. /// /// The corner radius definition. public void SetRoundCornerRadius(UniWebViewCornerRadius radius) { cornerRadius = radius; UniWebViewInterface.SetRoundCornerRadius( listener.Name, radius.TopLeft, radius.TopRight, radius.BottomLeft, radius.BottomRight ); } /// /// Applies the provided shadow configuration to the web view container. /// /// The shadow definition. public void SetShadow(UniWebViewShadow value) { shadow = value; UniWebViewInterface.SetShadow( listener.Name, value.Color.r, value.Color.g, value.Color.b, value.Color.a, value.Opacity, value.Radius, value.OffsetX, value.OffsetY, value.Spread ); } /// /// Convenience overload to set shadow properties. /// /// Shadow blur radius. /// Shadow opacity (0 - 1). /// Shadow offset. /// Shadow color. /// Shadow spread distance. public void SetShadow(float radius, float opacity, Vector2 offset, Color color, float spread = 0.0f) { SetShadow(new UniWebViewShadow(radius, opacity, offset.x, offset.y, color, spread)); } /// /// Sets the web view visible on screen. /// /// If you pass `false` and `UniWebViewTransitionEdge.None` to the first two parameters, it means no animation will /// be applied when showing. So the `duration` parameter will not be taken into account. Otherwise, when /// either or both `fade` and `edge` set, the showing operation will be animated. /// /// Regardless of there is an animation or not, the `completionHandler` will be called if not `null` when the web /// view showing finishes. /// /// Whether show with a fade in animation. Default is `false`. /// The edge from which the web view showing. It simulates a modal effect when showing a web view. Default is `UniWebViewTransitionEdge.None`. /// Duration of the showing animation. Default is `0.4f`. /// Completion handler which will be called when showing finishes. Default is `null`. /// A bool value indicates whether the showing operation started. public bool Show(bool fade = false, UniWebViewTransitionEdge edge = UniWebViewTransitionEdge.None, float duration = 0.4f, Action completionHandler = null) { return _Show(fade, edge, duration, false, completionHandler); } public bool _Show(bool fade = false, UniWebViewTransitionEdge edge = UniWebViewTransitionEdge.None, float duration = 0.4f, bool useAsync = false, Action completionHandler = null) { var identifier = Guid.NewGuid().ToString(); var showStarted = UniWebViewInterface.Show(listener.Name, fade, (int)edge, duration, useAsync, identifier); if (showStarted && completionHandler != null) { var hasAnimation = (fade || edge != UniWebViewTransitionEdge.None); if (hasAnimation) { actions.Add(identifier, completionHandler); } else { completionHandler(); } } #pragma warning disable 618 if (showStarted && ShouldDriveLegacyToolbar()) { var top = (toolbarPosition == UniWebViewToolbarPosition.Top); SetShowToolbar(true, false, top, fullScreen); } #pragma warning restore 618 return showStarted; } /// /// Sets the web view invisible from screen. /// /// If you pass `false` and `UniWebViewTransitionEdge.None` to the first two parameters, it means no animation will /// be applied when hiding. So the `duration` parameter will not be taken into account. Otherwise, when either or /// both `fade` and `edge` set, the hiding operation will be animated. /// /// Regardless there is an animation or not, the `completionHandler` will be called if not `null` when the web view /// hiding finishes. /// /// Whether hide with a fade in animation. Default is `false`. /// The edge from which the web view hiding. It simulates a modal effect when hiding a web view. Default is `UniWebViewTransitionEdge.None`. /// Duration of hiding animation. Default is `0.4f`. /// Completion handler which will be called when hiding finishes. Default is `null`. /// A bool value indicates whether the hiding operation started. public bool Hide(bool fade = false, UniWebViewTransitionEdge edge = UniWebViewTransitionEdge.None, float duration = 0.4f, Action completionHandler = null) { return _Hide(fade, edge, duration, false, completionHandler); } public bool _Hide(bool fade = false, UniWebViewTransitionEdge edge = UniWebViewTransitionEdge.None, float duration = 0.4f, bool useAsync = false, Action completionHandler = null) { var identifier = Guid.NewGuid().ToString(); var hideStarted = UniWebViewInterface.Hide(listener.Name, fade, (int)edge, duration, useAsync, identifier); if (hideStarted && completionHandler != null) { var hasAnimation = (fade || edge != UniWebViewTransitionEdge.None); if (hasAnimation) { actions.Add(identifier, completionHandler); } else { completionHandler(); } } #pragma warning disable 618 if (hideStarted && ShouldDriveLegacyToolbar()) { var top = (toolbarPosition == UniWebViewToolbarPosition.Top); SetShowToolbar(false, false, top, fullScreen); } #pragma warning restore 618 return hideStarted; } /// /// Animates the web view from current position and size to another position and size. /// /// The new `Frame` which the web view should be. /// Duration of the animation. /// Delay before the animation begins. Default is `0.0f`, which means the animation will start immediately. /// Completion handler which will be called when animation finishes. Default is `null`. /// public bool AnimateTo(Rect frame, float duration, float delay = 0.0f, Action completionHandler = null) { var identifier = Guid.NewGuid().ToString(); var nativeFrame = NativeFrameRect(frame); var animationStarted = UniWebViewInterface.AnimateTo(listener.Name, (int)nativeFrame.x, (int)nativeFrame.y, (int)nativeFrame.width, (int)nativeFrame.height, duration, delay, identifier); if (animationStarted) { this.frame = frame; if (completionHandler != null) { actions.Add(identifier, completionHandler); } } return animationStarted; } /// /// Sets the adjustment behavior which indicates how safe area insets /// are added to the adjusted content inset. It is a wrapper of `contentInsetAdjustmentBehavior` on iOS. /// /// It only works on iOS 11 and above. You need to call this method as soon as you create a web view, /// before you call any other methods related to web view layout (like `Show` or `SetShowToolbar`). /// /// The behavior for determining the adjusted content offsets. public void SetContentInsetAdjustmentBehavior( UniWebViewContentInsetAdjustmentBehavior behavior ) { #if (UNITY_EDITOR_OSX || UNITY_STANDALONE_OSX || UNITY_IOS) && !UNITY_EDITOR_WIN && !UNITY_EDITOR_LINUX UniWebViewInterface.SetContentInsetAdjustmentBehavior(listener.Name, behavior); #endif } /// /// Sets whether the web view area should avoid soft keyboard. If `true`, when the keyboard shows up, the web views /// content view will resize itself to avoid keyboard overlap the web content. Otherwise, the web view will not resize /// and just leave the content below under the soft keyboard. /// /// This method is only for Android. On iOS, the keyboard avoidance is built into the system directly and there is /// no way to change its behavior. /// /// Default is `true`. /// /// Whether the keyboard should avoid web view content. public static void SetEnableKeyboardAvoidance(bool flag) { #if UNITY_ANDROID && !UNITY_EDITOR UniWebViewInterface.SetEnableKeyboardAvoidance(flag); #endif } private Color backgroundColor = Color.white; /// /// Gets or sets the background color of web view. The default value is `Color.white`. /// public Color BackgroundColor { get => backgroundColor; set { backgroundColor = value; UniWebViewInterface.SetBackgroundColor(listener.Name, value.r, value.g, value.b, value.a); } } /// /// Gets or sets the alpha value of the whole web view. /// /// You can make the game scene behind web view visible to make the web view transparent. /// /// Default is `1.0f`, which means totally opaque. Set it to `0.0f` will make the web view totally transparent. /// public float Alpha { get => UniWebViewInterface.GetWebViewAlpha(listener.Name); set => UniWebViewInterface.SetWebViewAlpha(listener.Name, value); } /// /// Sets whether to show a loading indicator while the loading is in progress. /// /// Whether an indicator should show. public void SetShowSpinnerWhileLoading(bool flag) { UniWebViewInterface.SetShowSpinnerWhileLoading(listener.Name, flag); } /// /// Sets the text displayed in the loading indicator, if `SetShowSpinnerWhileLoading` is set to `true`. /// /// The text to display while loading indicator visible. Default is "Loading..." public void SetSpinnerText(string text) { UniWebViewInterface.SetSpinnerText(listener.Name, text); } /// /// Sets whether the user can dismiss the loading indicator by tapping on it or the greyed-out background around. /// /// By default, when the loading spinner is shown, the user can dismiss it by a single tapping. Call this method /// with `false` to disable this behavior. /// /// Whether the user can dismiss the loading indicator. public void SetAllowUserDismissSpinner(bool flag) { UniWebViewInterface.SetAllowUserDismissSpinnerByGesture(listener.Name, flag); } /// /// Shows the loading spinner. /// /// Calling this method will show the loading spinner, regardless if the `SetShowSpinnerWhileLoading` is set to /// `true` or `false`. However, if `SetShowSpinnerWhileLoading` was called with `true`, UniWebView will still hide /// the spinner when the loading finishes. /// public void ShowSpinner() { UniWebViewInterface.ShowSpinner(listener.Name); } /// /// Hides the loading spinner. /// /// Calling this method will hide the loading spinner, regardless if the `SetShowSpinnerWhileLoading` is set to /// `true` or `false`. However, if `SetShowSpinnerWhileLoading` was called with `false`, UniWebView will still show /// the spinner when the loading starts. /// public void HideSpinner() { UniWebViewInterface.HideSpinner(listener.Name); } /// /// Sets whether the horizontal scroll bar should show when the web content beyonds web view bounds. /// /// This only works on mobile platforms. It will do nothing on macOS Editor. /// /// Whether enable the scroll bar or not. public void SetHorizontalScrollBarEnabled(bool enabled) { UniWebViewInterface.SetHorizontalScrollBarEnabled(listener.Name, enabled); } /// /// Sets whether the vertical scroll bar should show when the web content beyonds web view bounds. /// /// This only works on mobile platforms. It will do nothing on macOS Editor. /// /// Whether enable the scroll bar or not. public void SetVerticalScrollBarEnabled(bool enabled) { UniWebViewInterface.SetVerticalScrollBarEnabled(listener.Name, enabled); } /// /// Sets whether the web view should show with a bounces effect when scrolling to page edge. /// /// This only works on mobile platforms. It will do nothing on macOS Editor. /// /// Whether the bounces effect should be applied or not. public void SetBouncesEnabled(bool enabled) { UniWebViewInterface.SetBouncesEnabled(listener.Name, enabled); } /// /// Sets whether the web view supports zoom gesture to change content size. /// Default is `false`, which means the zoom gesture is not supported. /// /// Whether the zoom gesture is allowed or not. public void SetZoomEnabled(bool enabled) { UniWebViewInterface.SetZoomEnabled(listener.Name, enabled); } /// /// Sets whether the web view can receive user interaction or not. /// /// By setting this to `false`, the web view will not accept any user touch event so your users cannot tap links or /// scroll the page. /// /// /// Whether the user interaction should be enabled or not. public void SetUserInteractionEnabled(bool enabled) { UniWebViewInterface.SetUserInteractionEnabled(listener.Name, enabled); } /// /// Sets whether the web view should pass through clicks at clear pixels to Unity scene. /// /// Setting this method is a pre-condition for the whole passing-through feature to work. To allow your touch passing through /// to Unity scene, the following conditions should be met at the same time: /// /// 1. This method is called with `true` and the web view accepts passing-through clicks. /// 2. The web view has a transparent background in body style for its content by CSS. /// 3. The web view itself has a transparent background color by setting `BackgroundColor` with a clear color. /// /// Then, when user clicks on the clear pixel on the web view, the touch events will not be handled by the web view. /// Instead, these events are passed to Unity scene. By using this feature, it is possible to create a native UI with the /// web view. /// /// Only clicks on transparent part on the web view will be delivered to Unity scene. The web view still intercepts /// and handles other touches on visible pixels on the web view. /// /// Whether the transparency clicking through feature should be enabled in this web view. public void SetTransparencyClickingThroughEnabled(bool enabled) { UniWebViewInterface.SetTransparencyClickingThroughEnabled(listener.Name, enabled); } /// /// Refreshes the transparency clicking through layout. /// /// Call this method when the web page content changes dynamically without triggering DOM mutations that the /// automatic detection can observe. This manually triggers a re-collection of opaque regions marked with /// `data-uv-transparency="opaque"` attributes. /// /// This is useful when: /// - Content is updated programmatically without DOM changes /// - Canvas or other dynamic rendering changes opacity /// - You need to ensure the transparency regions are up-to-date /// /// This method only works when transparency clicking through is enabled. If the feature is not enabled, /// calling this method does nothing. /// /// /// Available on both iOS and Android. Each platform refreshes the DOM-provided transparency mask immediately. /// public void RefreshTransparencyClickingThroughLayout() { UniWebViewInterface.RefreshTransparencyClickingThroughLayout(listener.Name); } /// /// Enables user resizing for web view window. By default, you can only set the window size /// by setting its frame on mac Editor. By enabling user resizing, you would be able to resize /// the window by dragging its border as a normal macOS window. /// /// This method only works for macOS for debugging purpose. It does nothing on iOS and Android. /// /// Whether the window could be able to be resized by cursor. public void SetWindowUserResizeEnabled(bool enabled) { #if (UNITY_EDITOR_OSX || UNITY_STANDALONE_OSX || UNITY_IOS) && !UNITY_EDITOR_WIN && !UNITY_EDITOR_LINUX UniWebViewInterface.SetWindowUserResizeEnabled(listener.Name, enabled); #endif } /// /// Sets whether horizontal swipe gestures should trigger back-forward list navigation. /// /// By setting with `true`, users can swipe from screen edge to perform a back or forward navigation. /// This method only works on iOS and macOS Editor. Default is `false`. /// /// On Android, the screen navigation gestures are simulating the traditional back button and it is enabled by /// default. To disable gesture navigation on Android, you have to also disable the device back button. See /// `SetBackButtonEnabled` for that purpose. /// /// /// The value indicates whether a swipe gestures driven navigation should be allowed. Default is `false`. /// public void SetAllowBackForwardNavigationGestures(bool flag) { #if (UNITY_EDITOR_OSX || UNITY_STANDALONE_OSX || UNITY_IOS) && !UNITY_EDITOR_WIN && !UNITY_EDITOR_LINUX UniWebViewInterface.SetAllowBackForwardNavigationGestures(listener.Name, flag); #endif } /// /// Sets the default font size used in the web view. /// /// On Android, the web view font size can be affected by the system font scale setting. Use this method to set the /// font size in a more reasonable way, by giving the web view another default font size with the system font scale /// considered. It can removes or reduces the effect of system font scale when displaying the web content. /// /// This method only works on Android. On iOS, this method does nothing since the web view will respect the font /// size setting in your CSS styles. /// /// The target default font size set to the web view. public void SetDefaultFontSize(int size) { #if UNITY_ANDROID && !UNITY_EDITOR UniWebViewInterface.SetDefaultFontSize(listener.Name, size); #endif } /// /// Sets the text zoom used in the web view. /// /// On Android, this method call `WebSettings.setTextZoom` to the the text zoom used in the web view. /// /// This method only works on Android. /// /// The text zoom in percent. public void SetTextZoom(int textZoom) { #if UNITY_ANDROID && !UNITY_EDITOR UniWebViewInterface.SetTextZoom(listener.Name, textZoom); #endif } /// /// Scrolls the web view to a certain point. /// /// Use 0 for both `x` and `y` value to scroll the web view to its origin. /// In a normal vertical web page, it is equivalent as scrolling to top. /// /// You can use the `animated` parameter to control whether scrolling the page with or without animation. /// This parameter only works on iOS and Android. On macOS editor, the scrolling always happens without animation. /// /// X value of the target scrolling point. /// Y value of the target scrolling point. /// If `true`, the scrolling happens with animation. Otherwise, it happens without /// animation and the content is set directly. /// public void ScrollTo(int x, int y, bool animated) { UniWebViewInterface.ScrollTo(listener.Name, x, y, animated); } }