Skip to content

Instantly share code, notes, and snippets.

@EmmaEwert
Created August 17, 2018 13:19
Show Gist options
  • Save EmmaEwert/fad38a248f62e1c7267daa4e778468b1 to your computer and use it in GitHub Desktop.
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.
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