- Home /
How to Relocate a Touch Event's Position
Hey folks,
I work with a lot of custom display and touch solutions and was hoping someone could help me out with a problem I keep running into.
Windows only sends touch events to a single screen, however, my touch overlay isn't necessarily the same size as that screen, It might go over 2 or even 10 screens. Sometimes this is solved simply with using nVidia Mosaic or Surround but sometimes it's not feasible.
I'd love to have a way to capture a touch event, change/scale the position value, and then let it pass through the EventSystem after that point. Anyone know how to accomplish this?
Thanks!
Answer by RodLekey · Oct 06, 2020 at 07:13 PM
I figured it out! You can Override the BaseInput class of your Standalone Input Module.
using UnityEngine;
using UnityEngine.EventSystems;
public class CustomInput : BaseInput
{
protected override void Awake()
{
StandaloneInputModule standaloneInputModule = GetComponent<StandaloneInputModule>();
if (standaloneInputModule) standaloneInputModule.inputOverride = this;
}
public override Vector2 mousePosition
{
get
{
Vector2 position = base.mousePosition;
if (Config.Instance.Display == 1)
{
position = new Vector2(position.x * 2, position.y);
}
return position;
}
}
public override Touch GetTouch(int index)
{
Touch touch = Input.GetTouch(index);
if (Config.Instance.Display == 1)
{
touch.position = new Vector2(touch.position.x * 2, touch.position.y);
}
return touch;
}
}
If you attach this to your EventSystem Object, it will attach this to the inputOverride of your StandaloneInputModule. Here you can intercept the calls, modify them, and pass them along.
Your answer
Follow this Question
Related Questions
Make an obect take priority over another when touched? 0 Answers
How to get position of touch on touch screen 1 Answer
Keyboard to Android Touch Conversion... 0 Answers
Please help. Attempting touch controls but I cant figure out what I'm doing wrong 3 Answers
the differenct between mouse and touch on mobile screen 2 Answers