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.

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.
voidUpdateUserBackgroundIfNeeded(RenderTexture cameraTarget)
Used for updating the background texture behind an UI object that has backdrop filter applied.
voidAddRawImageIfMissing()
Adds a RawImage component if its missing. Used when rendering the CohtmlView component within a Unity3D UI Canvas.
voidOnPostRender()
Called after a camera finished rendering the scene.
voidPostRender()
Updates textures related to the CohtmlView component and issues render events to draw them. Called during Unity3D’s OnPostRender event.
voidRenderCompositorTexture(RenderTexture destinationRT)
Used to render the compositor texture used for the Compositor and Surface Partitioning features.
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.
voidCreateViewRenderTarget()
Creates an internal ViewRenderer
voidAddMissingWorldViewComponents()
Adds a Quad MeshFilter, MeshRenderer and MeshCollider componnets if they are missing.

Protected Functions

Name
virtual voidOnEnable()
virtual voidStart()
virtual voidUpdate()
virtual voidOnPreRender()
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
boolDrawAsPostEffect
Gets or sets a value indicating whether this view is drawn after post effects.
boolEnableBackdropFilter
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.
boolWideColorTextures
If checked, the view will use 16 bit textures for all intermediate render targets
boolApplyGammaCorrection
Apply a Gamma Correction to Cohtml shader material in Linear Color Space.
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.
MaterialRenderMaterial
Returns the Material object used to render the CohtmlView component.
AudioSubscriberAudioSubscriber
Gets the AudioSubscriber for this CohtmlView.
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.

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 UpdateUserBackgroundIfNeeded

void UpdateUserBackgroundIfNeeded(
    RenderTexture cameraTarget
)

Used for updating the background texture behind an UI object that has backdrop filter applied.

Parameters:

  • cameraTarget The active texture of the rendering camera.

function AddRawImageIfMissing

void AddRawImageIfMissing()

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

function OnPostRender

void OnPostRender()

Called after a camera finished rendering the scene.

function PostRender

void PostRender()

Updates textures related to the CohtmlView component and issues render events to draw them. Called during Unity3D’s OnPostRender event.

function RenderCompositorTexture

void RenderCompositorTexture(
    RenderTexture destinationRT
)

Used to render the compositor texture used for the Compositor and Surface Partitioning features.

Parameters:

  • destinationRT The render target texture rendered to.

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 CreateViewRenderTarget

void CreateViewRenderTarget()

Creates an internal ViewRenderer

function AddMissingWorldViewComponents

void AddMissingWorldViewComponents()

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

Protected Functions Documentation

function OnEnable

virtual void OnEnable()

function Start

virtual void Start()

function Update

virtual void Update()

function OnPreRender

virtual void OnPreRender()

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 DrawAsPostEffect

bool DrawAsPostEffect;

Gets or sets a value indicating whether this view is drawn after post effects.

AfterPostEffects if the view is drawn after post effects; otherwise, false.

property EnableBackdropFilter

bool EnableBackdropFilter;

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

truefalse.

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 WideColorTextures

bool WideColorTextures;

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 ApplyGammaCorrection

bool ApplyGammaCorrection;

Apply a Gamma Correction to Cohtml shader material in Linear Color Space.

Value by default is false. True will apply gamma correction property color multiplier.

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 RenderMaterial

Material RenderMaterial => m_RenderMaterial;

Returns the Material object used to render the CohtmlView component.

variable AudioSubscriber

AudioSubscriber AudioSubscriber => m_AudioSubscriber;

Gets the AudioSubscriber for this CohtmlView.

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