Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
1
Question by z_orochii · Mar 04, 2020 at 02:09 PM · inputtouchscreenmultiple-monitors

Multiple touchscreens: multitouch on multiple input devices

Hi!

I have been trying to get input from two touchscreens at the same time, and detect from which is coming the input in order to manage UI elements from two sepparate Canvases on two different displays, but it doesn't properly work. Platform is Windows.

Basic premise of the application, it's an interactive app which is going to be used simultaneously on both screens by kids, so it's kind of necessary that both screens can act simultaneously and sepparately. I don't really care about multitouch, just that the screens respond properly and one doesn't block the other (which is what happens if you simply use the UI, like, say, a vanilla UI Button component), because it feels unresponsive.

I'm using the new Input System. I first tried 0.2 since I was using Unity 2018.4 (it's the latest LTS available so it's more reliable). But I also tried with 1.0 which comes with Unity 2019.3. And overall same results in both.

Here's the code from my test right now. This one comes from my tests with InputSystem 1.0.0preview

 using System.Collections;
 using System.Collections.Generic;
 using UnityEngine;
 using UnityEngine.InputSystem;
 using UnityEngine.InputSystem.Controls;
 using UnityEngine.UI;
 
 
 public class TestTouch : MonoBehaviour {
     [SerializeField] int deviceId;
     [SerializeField] Text debugText;
 
     Image selfImage;
     Text label;
     RectTransform rt;
     //Touchscreen selfDevice;
 
     bool pressed;
 
     void Start() {
         selfImage = GetComponent<Image>();
         label = GetComponentInChildren<Text>();
         rt = (RectTransform)transform;
 
         InputDevice[] allDevices = Touchscreen.all.ToArray();
 
         string devicesStr = "";
         foreach(InputDevice d in allDevices) {
             devicesStr += d.name + "::" + d.displayName + "::" + d.shortDisplayName + System.Environment.NewLine;
         }
         debugText.text = devicesStr;
 
         /*Touchscreen selfDevice = Touchscreen.current;
         selfDevice.activeTouches*/
     }
 
     void Update() {
         // Offsets for positions.
         float startOffset = 1920f * deviceId;
         float endOffset = startOffset + 1920f;
         // Check touch devices.
         if (Touchscreen.current != null) {
             foreach (TouchControl tc in Touchscreen.current.touches) {
                 // Get value
                 Vector2 touchPos = tc.position.ReadValue();
                 //debugText.text = touchPos.ToString();
                 // Check if it's for this screen
                 if (touchPos.x >= startOffset && touchPos.x < endOffset) {
                     touchPos.x -= startOffset;
                     RefreshPressed(true, touchPos);
                     return;
                 }
             }
         }
         bool mp = false;
         Vector2 pos = Input.mousePosition;
         if (pos.x >= startOffset && pos.x < endOffset) {
             mp = Input.GetMouseButton(0);
         }
         RefreshPressed(mp, Input.mousePosition);
     }
 
     void RefreshPressed(bool press, Vector2 position) {
         pressed = false;
         if (!press) {
             selfImage.color = Color.white;
             return;
         }
         //
         Rect r = rt.rect;
         Vector2 start = rt.position + new Vector3(r.x, r.y);
         Vector2 end = start + new Vector2(r.width, r.height);
         if (position.x > start.x && position.x < end.x
             && position.y > start.y && position.y < end.y) {
             pressed = true;
         }
         selfImage.color = pressed ? Color.gray : Color.white;
         label.text = position.ToString();
     }
 }

Now, thing is, as far as I can see UI uses the default mouse abstraction, so any touch is interpreted as a mouse. It lets me interact with both canvases either with mouse or touch, but not at the same time.

I also tried printing all available InputDevices by iterating over Touchscreen.all and it only shows one Touchscreen. I don't know if it's because Windows abstracts it or what, but thing is, only one screen seems to get touch support. I'm trying the new InputSystem because I read that was one of the things that was being developed, better touch support.


If you help me, I'll gift you a virtual cookie. Thanks!

Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

0 Replies

· Add your reply
  • Sort: 

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

147 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

,How Do get Touch input to work with the Player Input Component 1 Answer

What affects Input.touchCount ? Not returning more than 1 in specific scene 0 Answers

How to add touch input for mobile devices using unity? 2 Answers

InputSystem simulated touchscreen stops working from v1.1.0 preview 1 0 Answers

OnTouch function? 3 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges