Skip to content

Instantly share code, notes, and snippets.

@karljj1
Created September 16, 2020 10:32
Show Gist options
  • Save karljj1/6f351907bada39bf9bed193c7cdba10f to your computer and use it in GitHub Desktop.
Save karljj1/6f351907bada39bf9bed193c7cdba10f to your computer and use it in GitHub Desktop.
Emulate multiple display input using GameViews
Vector3 RelativeMouseAt()
{
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;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment