cohtml.CohtmlView

A component allowing you to render an HTML page and perform operations on it such as resizing, sending input events, navigating to a different URL and more.

Inherits from MonoBehaviour

Public Types

Name
enum classRenderMode { Unknown, OnScreen, InWorld, InScreenCanvas, InWorldCanvas}
A group of constants representing in what mode the CohtmlView should be rendered.
enum classDrawState { Disabled, Advanced, Drawn}
Represents the state of the rendering draw process.

Public Functions

Name
voidResize(int width, int height)
Resize the view to the specified width and height.
boolGetCamSize(out int width, out int height)
Returns the camera dimensions of the current view.
Vector2ViewToCamSizeRatio()
Returns the ratio between the view size and camera size.
voidAddRawImageIfMissing()
Adds a RawImage component if it’s missing. Used when rendering the CohtmlView component within a Unity3D Canvas UI.
voidAttachToRenderer()
voidDetachFromRenderer()
voidDispose()
voidDestroyNativeView()
Destroys the Native View and all its components in the correct order. To ensure proper destruction, the necessary steps must be executed in this order.
voidMarkViewRendererForDestroy()
Sends a request to the Plugin API to destroy the NativeView Renderer. This step occurs on the render thread, different from the main thread.
voidCreateNativeView()
Creates a native View object.
voidRecreateRenderTargets()
Creates an internal ViewRenderer
voidAddMissingWorldViewComponents()
Adds a Quad MeshFilter, MeshRenderer and MeshCollider components if they are missing.

Protected Functions

Name
virtual voidOnEnable()
virtual voidStart()
virtual voidUpdate()
virtual voidOnWillRenderObject()
virtual voidOnDestroy()
When destroying Cohtml components, it must follow a specific order - firstly Views then Systems then Library. CohtmlView component must first UnloadDocument, then destroy the native View, and only after that, it’s safe to destroy Unity-related objects and components.

Public Properties

Name
CohtmlUISystemCohtmlUISystem
Gets or sets the UI System used by this view
stringPage
Gets or sets the URL of the view
intWidth
Gets or sets the width of the view.
intHeight
Gets or sets the height of the view.
boolEnableComplexSelectors
Gets or sets a value indicating whether this view supports complex CSS selectors.
boolIsTransparent
Gets or sets a value indicating whether this view supports transparency.
boolPixelPerfect
If checked, the view will use the camera’s width and height
CameraEventCameraEvent
Specifies the Camera Event at which the Cohtml CommandBuffer is executed.
boolEnableBackdropFilter
If checked, the view elements with the backdrop filter will be able to filter content from the scene.
boolEnableGlobalBackdropFilter
If checked, the view elements with the backdrop filter will be able to filter content from the scene.
intBlurRadius
Gets or sets the blur radius used for the backdrop filter. Controls how many neighboring pixels are sampled during the blur pass. Larger values result in a stronger blur effect but are more expensive to compute. The value is only applied if m_EnableGlobalBackdropFilter is enabled. Otherwise, assignments are ignored.
boolEnableUISurfacePartitioning
Gets or sets a value indicating whether this view is in UI Surface Partitioning Mode. UISurfacePartitioning works only In-Canvas and On-Screen and all other rendering APIs except Vulkan, where texture recording occurs at the PostRender event.
boolEnableHdr
If checked, the view will use 16 bit textures for all intermediate render targets
RenderModeRenderingMode
Returns the RenderMode used to draw the CohtmlView.
RawImageRawImage
Returns the RawImage component if the CohtmlView is rendered inside Unity3D Canvas UI.
boolRaycastTarget
Determines whether this view receives input. This property is ignored when AutoFocus is enabled. AutoFocus will be disabled if you set this property. All automatic processing and reading of this property is done in the LateUpdate() / OnGUI() callbacks in Unity, letting you do all your logic for View focus in Update().
boolEnableBindingAttribute
Gets or sets a value indicating whether this CohtmlView enables usage of the CoherentMethod attribute in components in the host GameObject. When true, all the components in the host GameObject are inspected for the CoherentMethod attribute (in the Start function) and the decorated methods are automatically bound when the ReadyForBindings event is received.
CameraRenderingCamera
Gets the camera the view is rendering on or null if the view is rendered on a surface.
ViewNativeView
Gets the underlying View instance.
ViewListenerListener
Gets the view listener.
TextInputHandlerTextInputHandler
Gets the text input handler.
RenderTextureViewTexture
Returns the texture used to draw the CohtmlView.
AudioSourceAudioSource
Gets or sets the AudioSource for the CohtmlView.

Public Attributes

Name
const intDefaultWidth
The default Width of the CohtmlView.
const intDefaultHeight
The default Height of the CohtmlView.
Func< ViewSettings, ViewSettings >OnViewSettingsOverride
Allows modifying the settings of a CohtmlView upon creation.
uintId
The native identification number of the CohtmlView component.
ViewView
Gets the underlying View instance.
MaterialViewTextureMaterial
Returns the Material object used to render the CohtmlView component.
RenderTextureBackgroundTexture
Returns the background texture used to apply backdrop filter.
RenderTextureMaskTexture
Returns the MaskTexture texture used to apply global backdrop filter.
RenderTextureGlobalBackdropTexture
Returns the Texture used to apply global backdrop filter mask into.
RenderTextureIntermediateTexture
Returns the Intermediate texture used to apply horizontal blur effect.
AudioSubscriberAudioSubscriber
Gets the AudioSubscriber for this CohtmlView.
ViewRendererRenderer
Func< ViewListener >ViewListenerFactoryFunc
Creates the ViewListener instance for the view. Change to allow usage of custom ViewListener
Func< TextInputHandler >TextInputHandlerFactoryFunc
Creates the TextInputHandler instance for the view. Change to allow usage of custom TextInputHandler

Public Types Documentation

enum RenderMode

EnumeratorValueDescription
Unknown
OnScreen
InWorld
InScreenCanvas
InWorldCanvas

A group of constants representing in what mode the CohtmlView should be rendered.

enum DrawState

EnumeratorValueDescription
DisabledRendering is disabled. No new frame draw requests will be processed until the state is changed back to allow drawing. Useful for scenarios like a GameObject or camera is disabled, or lost game focus.
AdvancedA new frame is being processed for rendering.
DrawnThe UI from the current frame is drawn onto the targeted RenderTexture. The next drawing process expects to be in this draw state in order to continue rendering.

Represents the state of the rendering draw process.

Public Functions Documentation

function Resize

void Resize(
    int width,
    int height
)

Resize the view to the specified width and height.

Parameters:

  • width New width for the view.
  • height New height for the view.

function GetCamSize

bool GetCamSize(
    out int width,
    out int height
)

Returns the camera dimensions of the current view.

function ViewToCamSizeRatio

Vector2 ViewToCamSizeRatio()

Returns the ratio between the view size and camera size.

function AddRawImageIfMissing

void AddRawImageIfMissing()

Adds a RawImage component if it’s missing. Used when rendering the CohtmlView component within a Unity3D Canvas UI.

function AttachToRenderer

void AttachToRenderer()

function DetachFromRenderer

void DetachFromRenderer()

function Dispose

void Dispose()

function DestroyNativeView

void DestroyNativeView()

Destroys the Native View and all its components in the correct order. To ensure proper destruction, the necessary steps must be executed in this order.

  1. Releases the resources needed for the loaded page.
  2. Marks the native view for deletion.
  3. Destroys the C# View object holding the Native View object.
  4. Sends a request to the Plugin API to destroy the NativeView Renderer. This step occurs on the render thread, different from the main thread. To avoid improper destruction of Cohtml Native View, please use this method or mimic the steps in this order.

function MarkViewRendererForDestroy

void MarkViewRendererForDestroy()

Sends a request to the Plugin API to destroy the NativeView Renderer. This step occurs on the render thread, different from the main thread.

function CreateNativeView

void CreateNativeView()

Creates a native View object.

function RecreateRenderTargets

void RecreateRenderTargets()

Creates an internal ViewRenderer

function AddMissingWorldViewComponents

void AddMissingWorldViewComponents()

Adds a Quad MeshFilter, MeshRenderer and MeshCollider components if they are missing.

Protected Functions Documentation

function OnEnable

virtual void OnEnable()

function Start

virtual void Start()

function Update

virtual void Update()

function OnWillRenderObject

virtual void OnWillRenderObject()

function OnDestroy

virtual void OnDestroy()

When destroying Cohtml components, it must follow a specific order - firstly Views then Systems then Library. CohtmlView component must first UnloadDocument, then destroy the native View, and only after that, it’s safe to destroy Unity-related objects and components.

Public Property Documentation

property CohtmlUISystem

CohtmlUISystem CohtmlUISystem;

Gets or sets the UI System used by this view

The UI System component

property Page

string Page;

Gets or sets the URL of the view

The loaded URL of view

property Width

int Width;

Gets or sets the width of the view.

The width.

property Height

int Height;

Gets or sets the height of the view.

The height.

property EnableComplexSelectors

bool EnableComplexSelectors;

Gets or sets a value indicating whether this view supports complex CSS selectors.

Exceptions:

  • System.ApplicationException Is thrown when the property is modified and the view has already been created

true if view supports complex CSS selectors; otherwise, false.

property IsTransparent

bool IsTransparent;

Gets or sets a value indicating whether this view supports transparency.

Exceptions:

  • System.ApplicationException Is thrown when the property is modified and the view has already been created

true if view supports transparency; otherwise, false.

property PixelPerfect

bool PixelPerfect;

If checked, the view will use the camera’s width and height

true if we want to use camera’s width and height; otherwise false.

property CameraEvent

CameraEvent CameraEvent;

Specifies the Camera Event at which the Cohtml CommandBuffer is executed.

property EnableBackdropFilter

bool EnableBackdropFilter;

If checked, the view elements with the backdrop filter will be able to filter content from the scene.

property EnableGlobalBackdropFilter

bool EnableGlobalBackdropFilter;

If checked, the view elements with the backdrop filter will be able to filter content from the scene.

property BlurRadius

int BlurRadius;

Gets or sets the blur radius used for the backdrop filter. Controls how many neighboring pixels are sampled during the blur pass. Larger values result in a stronger blur effect but are more expensive to compute. The value is only applied if m_EnableGlobalBackdropFilter is enabled. Otherwise, assignments are ignored.

property EnableUISurfacePartitioning

bool EnableUISurfacePartitioning;

Gets or sets a value indicating whether this view is in UI Surface Partitioning Mode. UISurfacePartitioning works only In-Canvas and On-Screen and all other rendering APIs except Vulkan, where texture recording occurs at the PostRender event.

Exceptions:

  • System.ApplicationException Is thrown when the property is modified and the view has already been created

true if view is in UI Surface Partitioning Mode; otherwise, false.

property EnableHdr

bool EnableHdr;

If checked, the view will use 16 bit textures for all intermediate render targets

true if we want to use 16 bit textures for render targets; otherwise false.

property RenderingMode

RenderMode RenderingMode;

Returns the RenderMode used to draw the CohtmlView.

property RawImage

RawImage RawImage;

Returns the RawImage component if the CohtmlView is rendered inside Unity3D Canvas UI.

property RaycastTarget

bool RaycastTarget;

Determines whether this view receives input. This property is ignored when AutoFocus is enabled. AutoFocus will be disabled if you set this property. All automatic processing and reading of this property is done in the LateUpdate() / OnGUI() callbacks in Unity, letting you do all your logic for View focus in Update().

true if this view receives input; otherwise, false.

property EnableBindingAttribute

bool EnableBindingAttribute;

Gets or sets a value indicating whether this CohtmlView enables usage of the CoherentMethod attribute in components in the host GameObject. When true, all the components in the host GameObject are inspected for the CoherentMethod attribute (in the Start function) and the decorated methods are automatically bound when the ReadyForBindings event is received.

true if usage of the CoherentMethod is enabled; otherwise, false.

property RenderingCamera

Camera RenderingCamera;

Gets the camera the view is rendering on or null if the view is rendered on a surface.

The camera used by the view or null.

property NativeView

View NativeView;

Gets the underlying View instance.

The underlying View instance.

property Listener

ViewListener Listener;

Gets the view listener.

The view listener.

property TextInputHandler

TextInputHandler TextInputHandler;

Gets the text input handler.

The Text input handler.

property ViewTexture

RenderTexture ViewTexture;

Returns the texture used to draw the CohtmlView.

property AudioSource

AudioSource AudioSource;

Gets or sets the AudioSource for the CohtmlView.

The AudioSource component

Public Attributes Documentation

variable DefaultWidth

const int DefaultWidth = 1280;

The default Width of the CohtmlView.

variable DefaultHeight

const int DefaultHeight = 720;

The default Height of the CohtmlView.

variable OnViewSettingsOverride

Func< ViewSettings, ViewSettings > OnViewSettingsOverride;

Allows modifying the settings of a CohtmlView upon creation.

variable Id

uint Id => m_NativeViewId;

The native identification number of the CohtmlView component.

variable View

View View => NativeView;

Gets the underlying View instance.

The underlying View instance.

variable ViewTextureMaterial

Material ViewTextureMaterial => m_ViewTextureMaterial;

Returns the Material object used to render the CohtmlView component.

variable BackgroundTexture

RenderTexture BackgroundTexture => m_BackgroundTexture;

Returns the background texture used to apply backdrop filter.

variable MaskTexture

RenderTexture MaskTexture => m_MaskTexture;

Returns the MaskTexture texture used to apply global backdrop filter.

variable GlobalBackdropTexture

RenderTexture GlobalBackdropTexture => m_GlobalBackdropTexture;

Returns the Texture used to apply global backdrop filter mask into.

variable IntermediateTexture

RenderTexture IntermediateTexture => m_IntermediateTexture;

Returns the Intermediate texture used to apply horizontal blur effect.

variable AudioSubscriber

AudioSubscriber AudioSubscriber => m_AudioSubscriber;

Gets the AudioSubscriber for this CohtmlView.

variable Renderer

ViewRenderer Renderer;

variable ViewListenerFactoryFunc

static Func< ViewListener > ViewListenerFactoryFunc = () => { return new ViewListener(); };

Creates the ViewListener instance for the view. Change to allow usage of custom ViewListener

variable TextInputHandlerFactoryFunc

static Func< TextInputHandler > TextInputHandlerFactoryFunc = () => { return new TextInputHandler(); };

Creates the TextInputHandler instance for the view. Change to allow usage of custom TextInputHandler