Skip to content
SiteEmail

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

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.
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.
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.
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 is rendered with background transparency. When enabled, the UI is drawn with standard alpha blending. When disabled, the UI is drawn as fully opaque, which can improve GPU performance by skipping background blending.
CameraRenderingCamera
Gets or sets the target camera this view renders to. This is null if the view is rendered onto a surface instead of the screen.
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.
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.
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.
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.
Func< ViewRenderer, IGlobalBackdropFilter >OnGlobalBackdropFilterAssign
A callback that allows you to assign a custom global backdrop filter implementation.
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.
RenderTexturem_MaskTexture
RenderTextureMaskTexture
Returns the MaskTexture texture used to apply global backdrop filter.
RenderTexturem_GlobalBackdropTexture
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
EnumeratorValueDescription
Unknown
OnScreen
InWorld
InScreenCanvas
InWorldCanvas

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

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.

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.
bool GetCamSize(
out int width,
out int height
)

Returns the camera dimensions of the current view.

Vector2 ViewToCamSizeRatio()

Returns the ratio between the view size and camera size.

void AddRawImageIfMissing()

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

void AttachToRenderer()
void DetachFromRenderer()
void Dispose()
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.
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.

void CreateNativeView()

Creates a native View object.

void RecreateRenderTargets()

Creates an internal ViewRenderer

void AddMissingWorldViewComponents()

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

virtual void OnEnable()
virtual void Start()
virtual void Update()
virtual void OnWillRenderObject()
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.

CohtmlUISystem CohtmlUISystem;

Gets or sets the UI System used by this view

The UI System component

string Page;

Gets or sets the URL of the view

The loaded URL of view

int Width;

Gets or sets the width of the view.

The width.

int Height;

Gets or sets the height of the view.

The height.

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.

bool IsTransparent;

Gets or sets a value indicating whether this view is rendered with background transparency. When enabled, the UI is drawn with standard alpha blending. When disabled, the UI is drawn as fully opaque, which can improve GPU performance by skipping background blending.

true if the view is rendered transparently; otherwise, false.

Camera RenderingCamera;

Gets or sets the target camera this view renders to. This is null if the view is rendered onto a surface instead of the screen.

The target Camera, or null.

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.

CameraEvent CameraEvent;

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

bool EnableBackdropFilter;

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

bool EnableGlobalBackdropFilter;

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

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.

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.

RenderMode RenderingMode;

Returns the RenderMode used to draw the CohtmlView.

RawImage RawImage;

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

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.

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.

View NativeView;

Gets the underlying View instance.

The underlying View instance.

ViewListener Listener;

Gets the view listener.

The view listener.

TextInputHandler TextInputHandler;

Gets the text input handler.

The Text input handler.

RenderTexture ViewTexture;

Returns the texture used to draw the CohtmlView.

AudioSource AudioSource;

Gets or sets the AudioSource for the CohtmlView.

The AudioSource component

const int DefaultWidth = 1280;

The default Width of the CohtmlView.

const int DefaultHeight = 720;

The default Height of the CohtmlView.

Func< ViewSettings, ViewSettings > OnViewSettingsOverride;

Allows modifying the settings of a CohtmlView upon creation.

Func< ViewRenderer, IGlobalBackdropFilter > OnGlobalBackdropFilterAssign;

A callback that allows you to assign a custom global backdrop filter implementation.

The provided function receives the active ViewRenderer as an argument and must return a new instance of a class that implements IGlobalBackdropFilter. If left unassigned (null), the system will automatically fall back to the default GlobalBackdropBlurFilter.

uint Id => m_NativeViewId;

The native identification number of the CohtmlView component.

View View => NativeView;

Gets the underlying View instance.

The underlying View instance.

Material ViewTextureMaterial => m_ViewTextureMaterial;

Returns the Material object used to render the CohtmlView component.

RenderTexture BackgroundTexture => m_BackgroundTexture;

Returns the background texture used to apply backdrop filter.

RenderTexture m_MaskTexture;
RenderTexture MaskTexture => m_MaskTexture;

Returns the MaskTexture texture used to apply global backdrop filter.

RenderTexture m_GlobalBackdropTexture;
RenderTexture GlobalBackdropTexture => m_GlobalBackdropTexture;

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

RenderTexture IntermediateTexture => m_IntermediateTexture;

Returns the Intermediate texture used to apply horizontal blur effect.

AudioSubscriber AudioSubscriber => m_AudioSubscriber;

Gets the AudioSubscriber for this CohtmlView.

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

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

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

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