cohtml.InputSystem.CohtmlInputHandler

Subscribes to input events of Unity3D’s Input System or Input Manager and then forwards these events to CohtmlView’s that can receive input.

Inherits from MonoBehaviour

Public Functions

Name
voidFocusView(CohtmlView view, PointerEvent.EventType type =PointerEvent.EventType.Up)
Assigns input focus onto the CohtmlView and its owning CohtmlUISystem if the EnableAutoFocus option is enabled.
CameraGetRaycastCamera()
Returns the camera used to handle input events through raycast.
voidSendEventToViews(PointerEvent eventData, InputEventWrapper unityEvent)
Sends input events received from Unity3D to all CohtmlView components that have input events enabled.
voidSendEventToViews(TouchEventCollection touches)
Sends touch events received from Unity3D to all CohtmlView components that have touch events enabled.
voidSendKeyToFocusedView(KeyEvent eventData, InputEventWrapper unityEvent)
Sends a keyboard event to the CohtmlView component that has input focus.
voidSendCharToFocusedView(KeyEvent eventData, char character)
Sends a char event to the CohtmlView component that has input focus.
voidSendEventToFocusedView(KeyEvent eventData)
Sends a keyboard event to the CohtmlView component that has input focus.
voidGatherWorldViewsSorted(ref PointerEvent pointerEvent)
Gathers CohtmlView components positioned in the Unity3D Scene by firing a Raycast at the position of the provided PointerEvent. Once the CohtmlView components are gathered, they are sorted by the distance between the Raycast origin and the impact point.
CohtmlInputHandlerGetOrInitInstance()
Returns a Singleton instance of the CohtmlInputHandler.
ActionsHandleInputEvent(INodeProxy node, PhaseType phase)
Invoked before a DOM node is affected by an event. This method determines whether Cohtml should ignore this event or continue handling it.
Vector2IntCalculateViewClickPosition(CohtmlView view, Vector2Int screenPosition)
Calculates the click position on a CohtmlView component based on its RenderMode.
Vector2TransformScreenPositionToRawImageUV(Vector2 screenPosition, CohtmlView view)
Transforms a screen space position to local coordinates of the RawImage component where a CohtmlView is rendered.
Vector2IntScaleUVToViewSize(Vector2 localPointUV, CohtmlView view)
Scales the UV coordinates of a point with the CohtmlView dimensions. Results in mapping accurate point from a rectangle onto the CohtmlView dimensions.

Protected Functions

Name
virtual voidAwake()
virtual voidStart()
virtual voidOnEnable()
virtual voidReset()
virtual voidOnDestroy()
virtual voidOnGUI()

Public Properties

Name
InputBaseInput
Returns the current InputBase instance which is either InputManager or InputSystem.
CameraRaycastCamera
The camera used for handling input events with raycast. By default is the Main Camera.
Action< CohtmlView >OnFocusView
Invoked when a CohtmlView component is focused.
Action< CohtmlUISystem >OnFocusSystem
Invoked when a new CohtmlUISystem is focused unless its the same as the previously focused CohtmlUISystem.
Action< InputEventWrapper >OnMouseEventTargetNotFound
Invoked when a mouse event was not consumed by a CohtmlView.
Action< TouchEventCollection >OnTouchEventTargetNotFound
Invoked when a touch event was not consumed by a CohtmlView.
Action< InputEventWrapper >OnKeyEventTargetNotFound
Invoked when a key event was not consumed by a CohtmlView.
Action< char >OnCharEventTargetNotFound
Invoked when a char event was not consumed by a CohtmlView.
Action< GamepadBase.GamepadMap >OnGamepadEventTargetNotFound
Invoked when a gamepad event was not consumed by a CohtmlView.
CohtmlUISystemFocusedSystem
Returns the current CohtmlUISystem that is on input focus.
CohtmlViewFocusedView
Returns the current CohtmlView that is on input focus.

Public Attributes

Name
boolEnableMouse
Enables the Cohtml integration to send mouse events automatically to the UI. Cannot be changed at runtime.
boolEnableKeyboard
Enables the Cohtml integration to send keyboard events automatically to the UI. Cannot be changed at runtime.
boolEnableGamepad
Enables the Cohtml integration to send events from one or multiple gamepads automatically to the UI. Cannot be changed at runtime.
boolEnableTouch
Enables the Cohtml integration to send touch events automatically to the UI. Cannot be changed at runtime.
string []IgnoredInputCSSClasses
CSS classes that mark a HTML tag as ignored for the Cohtml input event system. If the tag is а parent, it will ignore its children.
intScrollPixels
Determinate how many pixels will scroll with one tick of the mouse scroll. Negative number will reverse the direction of scrolling. Can be changed at runtime.
boolEnableAutoFocus
The event system automatically manages focus between views. The focused in-world CohtmlView will be below the mouse pointer or on-screen. The first focused by default is an on-screen CohtmlView component, attached to the main camera if exists.
boolEnableFocusOnPointerMove
Enable the input handler to focus views on pointer move event. This property is ignored when disabling the EnableAutoFocus option. Can be changed at runtime.
boolInputEnabled
Returns true if any of the Mouse, Keyboard, Gamepad or Touch input devices are enabled.
CohtmlInputHandlerInstance
Returns a Singleton instance of the CohtmlInputHandler.

Public Functions Documentation

function FocusView

void FocusView(
    CohtmlView view,
    PointerEvent.EventType type =PointerEvent.EventType.Up
)

Assigns input focus onto the CohtmlView and its owning CohtmlUISystem if the EnableAutoFocus option is enabled.

Parameters:

  • view The CohtmlView component that should be focused by input.
  • type The type of the event.

Note: For Pointer Move events, the CohtmlView component will be focused only if the EnableFocusOnPointerMove option is enabled.

function GetRaycastCamera

Camera GetRaycastCamera()

Returns the camera used to handle input events through raycast.

function SendEventToViews

void SendEventToViews(
    PointerEvent eventData,
    InputEventWrapper unityEvent
)

Sends input events received from Unity3D to all CohtmlView components that have input events enabled.

function SendEventToViews

void SendEventToViews(
    TouchEventCollection touches
)

Sends touch events received from Unity3D to all CohtmlView components that have touch events enabled.

function SendKeyToFocusedView

void SendKeyToFocusedView(
    KeyEvent eventData,
    InputEventWrapper unityEvent
)

Sends a keyboard event to the CohtmlView component that has input focus.

function SendCharToFocusedView

void SendCharToFocusedView(
    KeyEvent eventData,
    char character
)

Sends a char event to the CohtmlView component that has input focus.

function SendEventToFocusedView

void SendEventToFocusedView(
    KeyEvent eventData
)

Sends a keyboard event to the CohtmlView component that has input focus.

function GatherWorldViewsSorted

void GatherWorldViewsSorted(
    ref PointerEvent pointerEvent
)

Gathers CohtmlView components positioned in the Unity3D Scene by firing a Raycast at the position of the provided PointerEvent. Once the CohtmlView components are gathered, they are sorted by the distance between the Raycast origin and the impact point.

Parameters:

  • pointerEvent The event whose position will be used to fire a Raycast.

function GetOrInitInstance

static CohtmlInputHandler GetOrInitInstance()

Returns a Singleton instance of the CohtmlInputHandler.

function HandleInputEvent

static Actions HandleInputEvent(
    INodeProxy node,
    PhaseType phase
)

Invoked before a DOM node is affected by an event. This method determines whether Cohtml should ignore this event or continue handling it.

Parameters:

  • node The DOM node the event can affect.
  • phase The phase of the event. Can be None, Capturing, At Target or Bubbling.

function CalculateViewClickPosition

static Vector2Int CalculateViewClickPosition(
    CohtmlView view,
    Vector2Int screenPosition
)

Calculates the click position on a CohtmlView component based on its RenderMode.

Parameters:

  • view
  • screenPosition The click position on the screen

Return: The returned position is in local coordinate space of the view with Top Left corner origin

function TransformScreenPositionToRawImageUV

static Vector2 TransformScreenPositionToRawImageUV(
    Vector2 screenPosition,
    CohtmlView view
)

Transforms a screen space position to local coordinates of the RawImage component where a CohtmlView is rendered.

Parameters:

  • screenPosition The posiiton in screen space.
  • view The CohtmlView rendering in the RawImage.

function ScaleUVToViewSize

static Vector2Int ScaleUVToViewSize(
    Vector2 localPointUV,
    CohtmlView view
)

Scales the UV coordinates of a point with the CohtmlView dimensions. Results in mapping accurate point from a rectangle onto the CohtmlView dimensions.

Parameters:

  • localPointUV The UV coordinates of the position.
  • view The CohtmlView to map the point to.

Protected Functions Documentation

function Awake

virtual void Awake()

function Start

virtual void Start()

function OnEnable

virtual void OnEnable()

function Reset

virtual void Reset()

function OnDestroy

virtual void OnDestroy()

function OnGUI

virtual void OnGUI()

Public Property Documentation

property Input

static InputBase Input;

Returns the current InputBase instance which is either InputManager or InputSystem.

property RaycastCamera

static Camera RaycastCamera;

The camera used for handling input events with raycast. By default is the Main Camera.

property OnFocusView

static Action< CohtmlView > OnFocusView;

Invoked when a CohtmlView component is focused.

property OnFocusSystem

static Action< CohtmlUISystem > OnFocusSystem;

Invoked when a new CohtmlUISystem is focused unless its the same as the previously focused CohtmlUISystem.

property OnMouseEventTargetNotFound

static Action< InputEventWrapper > OnMouseEventTargetNotFound;

Invoked when a mouse event was not consumed by a CohtmlView.

property OnTouchEventTargetNotFound

static Action< TouchEventCollection > OnTouchEventTargetNotFound;

Invoked when a touch event was not consumed by a CohtmlView.

property OnKeyEventTargetNotFound

static Action< InputEventWrapper > OnKeyEventTargetNotFound;

Invoked when a key event was not consumed by a CohtmlView.

property OnCharEventTargetNotFound

static Action< char > OnCharEventTargetNotFound;

Invoked when a char event was not consumed by a CohtmlView.

property OnGamepadEventTargetNotFound

static Action< GamepadBase.GamepadMap > OnGamepadEventTargetNotFound;

Invoked when a gamepad event was not consumed by a CohtmlView.

property FocusedSystem

static CohtmlUISystem FocusedSystem;

Returns the current CohtmlUISystem that is on input focus.

property FocusedView

static CohtmlView FocusedView;

Returns the current CohtmlView that is on input focus.

Public Attributes Documentation

variable EnableMouse

bool EnableMouse = true;

Enables the Cohtml integration to send mouse events automatically to the UI. Cannot be changed at runtime.

variable EnableKeyboard

bool EnableKeyboard = true;

Enables the Cohtml integration to send keyboard events automatically to the UI. Cannot be changed at runtime.

variable EnableGamepad

bool EnableGamepad = true;

Enables the Cohtml integration to send events from one or multiple gamepads automatically to the UI. Cannot be changed at runtime.

variable EnableTouch

bool EnableTouch = true;

Enables the Cohtml integration to send touch events automatically to the UI. Cannot be changed at runtime.

variable IgnoredInputCSSClasses

string [] IgnoredInputCSSClasses = { "hidden" };

CSS classes that mark a HTML tag as ignored for the Cohtml input event system. If the tag is а parent, it will ignore its children.

variable ScrollPixels

int ScrollPixels = 40;

Determinate how many pixels will scroll with one tick of the mouse scroll. Negative number will reverse the direction of scrolling. Can be changed at runtime.

Note: That setting has no effect on touch pan gestures.

variable EnableAutoFocus

bool EnableAutoFocus = true;

The event system automatically manages focus between views. The focused in-world CohtmlView will be below the mouse pointer or on-screen. The first focused by default is an on-screen CohtmlView component, attached to the main camera if exists.

variable EnableFocusOnPointerMove

bool EnableFocusOnPointerMove = false;

Enable the input handler to focus views on pointer move event. This property is ignored when disabling the EnableAutoFocus option. Can be changed at runtime.

variable InputEnabled

bool InputEnabled => EnableMouse || EnableKeyboard || EnableGamepad || EnableTouch;

Returns true if any of the Mouse, Keyboard, Gamepad or Touch input devices are enabled.

variable Instance

static CohtmlInputHandler Instance => GetOrInitInstance();

Returns a Singleton instance of the CohtmlInputHandler.