WebViewComponent

Place a WebView in the UI and world. Set whether the webpage can be manipulated, how to navigate, and more.

# Properties

[{"index":"boolean ClickingEnabled (Sync)","0":"Whether to enable clicks in the WebView."}]

[{"index":"DragMode DragMode","0":"Defines what action to take when dragging within WebView."}]

[{"index":"float DragThreshold","0":"Threshold to have it not recognized as a click when dragging. If the number is very high, the drag can be recognized as a click."}]

[{"index":"boolean HoveringEnabled (Sync)","0":"Sets whether the web element can be interacted with when the mouse is placed over the WebView."}]

[{"index":"boolean IgnoreMapLayerCheck (Sync)","0":"Does not perform automatic substitution when the Map Layer's name is specified in SortingLayer."}]

[{"index":"int32 OrderInLayer (Sync)","0":"Determines the priority within the same layer. A higher number indicates higher priority."}]

[{"index":"int32 PixelPerUnit (Sync)","0":"The number of pixels to be displayed per 1 Unit. Use values from 100 to 500."}]

[{"index":"boolean ScrollingEnabled (Sync)","0":"Set whether the WebView is scrollable or not."}]

[{"index":"float ScrollSensitivity","0":"Determines how much will scroll when the page is scrolled with the mouse wheel."}]

[{"index":"string SortingLayer (Sync)","0":"When two or more Entities overlap, the priority is determined according to the Sorting Layer."}]

[{"index":"string Url (Sync)","0":"This is the URL of the webpage. Changing the Url will load that webpage. Cadence of changes will be limited to 10 times per minute. Only http and https protocols can be used."}]

##### inherited from Component:

[{"index":"boolean Enable (Sync)","0":"Checks whether Component is activated or not."}]

[{"index":"boolean EnableInHierarchy (ReadOnly) (HideFromInspector)","0":"Displays whether this Component is Enable in the hierarchy. If Entity Enable is false regardless of Component Enable, returns false."}]

[{"index":"Entity Entity (ReadOnly)","0":"The Entity that owns this component."}]

# Methods

[{"index":"void Click(Vector2 normalizedPosition)","0":"Click the given location."}]

[{"index":"void GoBack()","0":"Go to the previous page in your history."}]

[{"index":"void GoForward()","0":"Go to the next page in your history."}]

[{"index":"void Reload(string targetUserId = nil) (Client)","0":"Reloads the current page."}]

[{"index":"void Scroll(Vector2 scrollDelta)","0":"Scrolls by the given scrollDelta. scrollDelta is a normalized value."}]

[{"index":"void ScrollAt(Vector2 scrollDelta, Vector2 normalizedPosition)","0":"Scrolls by scrollDelta from the given location. scrollDelta and point are normalized values."}]

[{"index":"void ZoomIn()","0":"Zooms the page in little by little. Zoom state is kept separately by pages."}]

[{"index":"void ZoomOut()","0":"Zooms the page out little by little. Zoom state is kept separately by pages."}]

##### inherited from Component:

[{"index":"boolean IsClient()","0":"Returns whether the current execution environment is a client or not."}]

[{"index":"boolean IsServer()","0":"Returns whether the current execution environment is a server or not."}]

# Events

[{"index":"OrderInLayerChangedEvent","0":"This event occurs when changing the Component's OrderInLayer."}]

[{"index":"SortingLayerChangedEvent","0":"This event occurs when changing the component's SortingLayer."}]

[{"index":"WebLoadCompleteEvent","0":"The event that takes place upon completing the loading of a web page."}]

[{"index":"WebLoadFailEvent","0":"The event that takes place upon failing to load a web page."}]

[{"index":"WebViewClickedEvent","0":"This event occurs when a click is made in the WebView."}]

[{"index":"WebViewPopupClosedEvent","0":"The event that takes place when an open web page is closed."}]

[{"index":"WebViewPopupEvent","0":"The event that takes place when a new web page is opened on a new window."}]

# Examples

This is an example of enlarging and reducing the WebView screen with the plus and minus keys. Create and add a component with the code below to the entity where WebViewComponent is located. Creates an address input field and forward and backward buttons on the right side of the screen.
    
    
    @Component
    script WebViewUIController extends Component
        @ExecSpace("ClientOnly")
        method void OnBeginPlay()
        	local webview = self.Entity.WebViewComponent
        	if webview == nil then
        	    log_error("Entity doesn't have WebViewComponent")
        	    return
        	end
    
        	local webviewGroup = _EntityService:GetEntityByPath("/ui/WebViewGroup")
        	if webviewGroup == nil then
        	    webviewGroup = _SpawnService:SpawnByModelId("model://uigroup", "WebViewGroup", Vector3.zero, _EntityService:GetEntityByPath("/ui"))
        	end
    
        	webviewGroup.Enable = true
    
        	local forwardButton = _SpawnService:SpawnByModelId("model://uibutton", "Button_Forward", Vector3.zero, webviewGroup)
        	local backwardButton = _SpawnService:SpawnByModelId("model://uibutton", "Button_Backward", Vector3.zero, webviewGroup)
        	local urlInputField = _SpawnService:SpawnByModelId("model://uitext", "UIUrlInputField", Vector3.zero, webviewGroup)
        	urlInputField:AddComponent(TextInputComponent)
    
        	forwardButton.UITransformComponent.AlignmentOption = AlignmentType.TopRight
        	backwardButton.UITransformComponent.AlignmentOption = AlignmentType.TopRight
        	urlInputField.UITransformComponent.AlignmentOption = AlignmentType.TopRight
    
        	forwardButton.UITransformComponent.anchoredPosition = Vector2(-40, -155)
        	forwardButton.UITransformComponent.RectSize = Vector2(75, 75)
        	forwardButton.UITransformComponent.ZRotation = 90
        	forwardButton.SpriteGUIRendererComponent.ImageRUID = "000000"
    
        	backwardButton.UITransformComponent.anchoredPosition = Vector2(-115, -155)
        	backwardButton.UITransformComponent.RectSize = Vector2(75, 75)
        	backwardButton.UITransformComponent.ZRotation = 90
        	backwardButton.SpriteGUIRendererComponent.ImageRUID = "000000"
        	backwardButton.SpriteGUIRendererComponent.FlipY = true
    
        	urlInputField.UITransformComponent.Pivot = Vector2(1, 0.5)
        	urlInputField.UITransformComponent.anchoredPosition = Vector2(-155, -155)
        	urlInputField.UITransformComponent.RectSize = Vector2(500, 75)
    
        	urlInputField.SpriteGUIRendererComponent.ImageRUID = "000000"
        	urlInputField.SpriteGUIRendererComponent.Color = Color.white
        	urlInputField.TextComponent.Overflow = OverflowType.Truncate
        	urlInputField.TextComponent.Padding = RectOffset(15, 15, 15, 15)
        	urlInputField.TextComponent.FontColor = Color.white
        	urlInputField.TextComponent.Text = webview.Url
        	urlInputField.TextInputComponent.Text = webview.Url
    
        	-- Connect events to each UI entity
        -- 	urlInputField:ConnectEvent(TextInputEndEditEvent, function (event)
        -- 	        webview.Url = event.text
        -- 	    end)
        -- [Commented: MLUA requires @EventSender + handler pattern]
    
        -- 	backwardButton:ConnectEvent(ButtonClickEvent, function ()
        -- 	        webview:GoBack()
        -- 	    end)
        -- [Commented: MLUA requires @EventSender + handler pattern]
    
        -- 	forwardButton:ConnectEvent(ButtonClickEvent, function ()
        -- 	        webview:GoForward()
        -- 	    end)
        -- [Commented: MLUA requires @EventSender + handler pattern]
    
        	-- Update InputField with current address upon completion of web load
        -- 	self.Entity:ConnectEvent(WebLoadCompleteEvent, function ()
        -- 	        urlInputField.TextComponent.Text = webview.Url
        -- 	    end)
        -- [Commented: MLUA requires @EventSender + handler pattern]
        end
    
        @EventSender("Service", "InputService")
        handler HandleKeyDownEvent(KeyDownEvent event)
        --------------- Native Event Sender Info ----------------
        -- Sender: InputService
        -- Space: Client
        ---------------------------------------------------------
    
        -- Parameters
        local key = event.key
        ---------------------------------------------------------
        if self.Entity.WebViewComponent == nil then
            return
        end
    
        -- Zoom in or out when you press the plus or minus keys
        if key == KeyboardKey.Equals or key == KeyboardKey.KeypadPlus then
            self.Entity.WebViewComponent:ZoomIn()
        end
    
        if key == KeyboardKey.Minus or key == KeyboardKey.KeypadMinus then
            self.Entity.WebViewComponent:ZoomOut()
        end
        end
    end
    

# SeeAlso

  * SpriteGUIRendererComponent
  * TextComponent
  * UITransformComponent
  * KeyboardKey
  * ButtonClickEvent
  * KeyDownEvent
  * Vector2
  * Vector3
  * EntityService
  * InputService
  * SpawnService