- Home /
This question was
closed Jul 26, 2017 at 07:05 AM by
Zytronic_Touch.
Question by
Zytronic_Touch · Jul 26, 2017 at 02:14 PM ·
multitouchmultiple-monitorsmultiple cameras
Multi-Display - Multi Touch Screen Issues
I am currently working on a project which is using three touch sensors with two displays. I am having an issue with mapping the touches to the correct display.
This diagram shows the desired mapping:
So to do this I am using this:
void Update () {
Debug.Log(Input.touchCount);
for (int i = 0; i < Input.touches.Length; i++)
{
Touch touch = Input.GetTouch(i);
if (touch.phase == TouchPhase.Began)
{
Ray ray = Camera.main.ScreenPointToRay(touch.position);
Debug.DrawRay(ray.origin, ray.direction * 10, Color.yellow);
}
}
}
The issue is that every touch to any sensor is showing on Display1. I believe this is down to: Camera.main.ScreenPointToRay(touch.position);
But I cant find a way to detect which screen is being touched to use the correct camera. Is there a way around this issue?
sensorlayout.png
(10.9 kB)
Comment
hey did you ever figure this out? I have the same issue
It was some time ago I resolved this but I believe this script may be of some help to you.
using System;
using System.Reflection;
#if (UNITY_EDITOR)
using UnityEditor;
#endif
using UnityEngine;
public static class DebugScreenPosition
{
#if (UNITY_EDITOR)
public static Vector3 DebugRelative$$anonymous$$ouseAt()
{
var mouseOverWindow = EditorWindow.mouseOverWindow;
System.Reflection.Assembly assembly = typeof(UnityEditor.EditorWindow).Assembly;
Type type = assembly.GetType("UnityEditor.GameView");
int displayID = 0;
if (type.IsInstanceOfType(mouseOverWindow))
{
var displayField = type.GetField("m_TargetDisplay", BindingFlags.NonPublic | BindingFlags.Instance);
displayID = (int)displayField.GetValue(mouseOverWindow);
}
var pos = Input.mousePosition;
pos[2] = displayID;
return pos;
}
public static Vector3 Relative$$anonymous$$ouseAt()
{
var mouseOverWindow = EditorWindow.mouseOverWindow;
System.Reflection.Assembly assembly = typeof(UnityEditor.EditorWindow).Assembly;
Type type = assembly.GetType("UnityEditor.GameView");
int displayID = 0;
if (type.IsInstanceOfType(mouseOverWindow))
{
var displayField = type.GetField("m_TargetDisplay", BindingFlags.NonPublic | BindingFlags.Instance);
displayID = (int)displayField.GetValue(mouseOverWindow);
}
var pos = Input.mousePosition;
pos[2] = displayID;
return pos;
}
#endif
public static Camera GetCameraFromDisplayIndex(int ID)
{
foreach (Camera camera in Camera.allCameras)
{
if (camera.targetDisplay == ID)
return camera;
}
return null;
}
}
oh wow thank you, this is super freakin helpful!