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 class | RenderMode { Unknown, OnScreen, InWorld, InScreenCanvas, InWorldCanvas} A group of constants representing in what mode the CohtmlView should be rendered. |
Public Functions
Name | |
---|---|
void | Resize(int width, int height) Resize the view to the specified width and height. |
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 | UpdateUserBackgroundIfNeeded(RenderTexture cameraTarget) Used for updating the background texture behind an UI object that has backdrop filter applied. |
void | AddRawImageIfMissing() Adds a RawImage component if its missing. Used when rendering the CohtmlView component within a Unity3D UI Canvas. |
void | OnPostRender() Called after a camera finished rendering the scene. |
void | PostRender() Updates textures related to the CohtmlView component and issues render events to draw them. Called during Unity3D’s OnPostRender event. |
void | RenderCompositorTexture(RenderTexture destinationRT) Used to render the compositor texture used for the Compositor and Surface Partitioning features. |
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. |
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 | CreateViewRenderTarget() Creates an internal ViewRenderer |
void | AddMissingWorldViewComponents() Adds a Quad MeshFilter, MeshRenderer and MeshCollider componnets if they are missing. |
Protected Functions
Name | |
---|---|
virtual void | OnEnable() |
virtual void | Start() |
virtual void | Update() |
virtual void | OnPreRender() |
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. |
Public Properties
Name | |
---|---|
CohtmlUISystem | CohtmlUISystem Gets or sets the UI System used by this view |
string | Page Gets or sets the URL of the view |
int | Width Gets or sets the width of the view. |
int | Height Gets or sets the height of the view. |
bool | EnableComplexSelectors Gets or sets a value indicating whether this view supports complex CSS selectors. |
bool | IsTransparent Gets or sets a value indicating whether this view supports transparency. |
bool | PixelPerfect If checked, the view will use the camera’s width and height |
bool | DrawAsPostEffect Gets or sets a value indicating whether this view is drawn after post effects. |
bool | EnableBackdropFilter 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. |
bool | WideColorTextures If checked, the view will use 16 bit textures for all intermediate render targets |
bool | ApplyGammaCorrection Apply a Gamma Correction to Cohtml shader material in Linear Color Space. |
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() . |
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. |
Camera | RenderingCamera Gets the camera the view is rendering on or null if the view is rendered on a surface. |
View | NativeView Gets the underlying View instance. |
ViewListener | Listener Gets the view listener. |
TextInputHandler | TextInputHandler Gets the text input handler. |
RenderTexture | ViewTexture Returns the texture used to draw the CohtmlView. |
AudioSource | AudioSource Gets or sets the AudioSource for the CohtmlView. |
Public Attributes
Name | |
---|---|
const int | DefaultWidth The default Width of the CohtmlView. |
const int | DefaultHeight The default Height of the CohtmlView. |
Func< ViewSettings, ViewSettings > | OnViewSettingsOverride Allows modifying the settings of a CohtmlView upon creation. |
uint | Id The native identification number of the CohtmlView component. |
View | View Gets the underlying View instance. |
Material | RenderMaterial Returns the Material object used to render the CohtmlView component. |
AudioSubscriber | AudioSubscriber 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
Enumerator | Value | Description |
---|---|---|
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.
- Releases the resources needed for the loaded page.
- Marks the native view for deletion.
- Destroys the C# View object holding the Native View object.
- 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.
true
false
.
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