Created
August 17, 2018 13:19
-
-
Save EmmaEwert/fad38a248f62e1c7267daa4e778468b1 to your computer and use it in GitHub Desktop.
Replacement for Unity's StandaloneInputModule, world-space UI now reacts to first person locked cursor, screen center being the pointer position.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using UnityEngine; | |
using UnityEngine.EventSystems; | |
public class FirstPersonInputModule : StandaloneInputModule { | |
protected override MouseState GetMousePointerEventData(int id) { | |
var lockState = Cursor.lockState; | |
Cursor.lockState = CursorLockMode.None; | |
var mouseState = base.GetMousePointerEventData(id); | |
Cursor.lockState = lockState; | |
return mouseState; | |
} | |
protected override void ProcessMove(PointerEventData pointerEvent) { | |
var lockState = Cursor.lockState; | |
Cursor.lockState = CursorLockMode.None; | |
base.ProcessMove(pointerEvent); | |
Cursor.lockState = lockState; | |
} | |
protected override void ProcessDrag(PointerEventData pointerEvent) { | |
var lockState = Cursor.lockState; | |
Cursor.lockState = CursorLockMode.None; | |
base.ProcessDrag(pointerEvent); | |
Cursor.lockState = lockState; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment