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!

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.