Skip to content
SiteEmail

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

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.
Name
virtual voidAwake()
virtual voidStart()
virtual voidOnEnable()
virtual voidReset()
virtual voidOnDestroy()
virtual voidOnGUI()
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.
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.
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.

Camera GetRaycastCamera()

Returns the camera used to handle input events through raycast.

void SendEventToViews(
PointerEvent eventData,
InputEventWrapper unityEvent
)

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

void SendEventToViews(
TouchEventCollection touches
)

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

void SendKeyToFocusedView(
KeyEvent eventData,
InputEventWrapper unityEvent
)

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

void SendCharToFocusedView(
KeyEvent eventData,
char character
)

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

void SendEventToFocusedView(
KeyEvent eventData
)

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

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.
static CohtmlInputHandler GetOrInitInstance()

Returns a Singleton instance of the CohtmlInputHandler.

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.
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

Section titled “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.
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.
virtual void Awake()
virtual void Start()
virtual void OnEnable()
virtual void Reset()
virtual void OnDestroy()
virtual void OnGUI()
static InputBase Input;

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

static Camera RaycastCamera;

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

static Action< CohtmlView > OnFocusView;

Invoked when a CohtmlView component is focused.

static Action< CohtmlUISystem > OnFocusSystem;

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

static Action< InputEventWrapper > OnMouseEventTargetNotFound;

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

static Action< TouchEventCollection > OnTouchEventTargetNotFound;

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

static Action< InputEventWrapper > OnKeyEventTargetNotFound;

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

static Action< char > OnCharEventTargetNotFound;

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

static Action< GamepadBase.GamepadMap > OnGamepadEventTargetNotFound;

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

static CohtmlUISystem FocusedSystem;

Returns the current CohtmlUISystem that is on input focus.

static CohtmlView FocusedView;

Returns the current CohtmlView that is on input focus.

bool EnableMouse = true;

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

bool EnableKeyboard = true;

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

bool EnableGamepad = true;

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

bool EnableTouch = true;

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

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.

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.

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.

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.

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

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

static CohtmlInputHandler Instance => GetOrInitInstance();

Returns a Singleton instance of the CohtmlInputHandler.