Skip to content

Instantly share code, notes, and snippets.

@ikriz
Forked from karljj1/Display.RelativeMouseAt.cs
Last active October 8, 2020 11:39
Show Gist options
  • Save ikriz/ad17a2c2d803d15b1777590fb29dc4d3 to your computer and use it in GitHub Desktop.
Save ikriz/ad17a2c2d803d15b1777590fb29dc4d3 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.PlayModeView");
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