void OnGUI() { if (!instance) { return; } Event e = Event.current; //if (e.isKey) if (e.type == EventType.KeyDown || e.type == EventType.KeyUp) { ////Debug.Log("Detected Key event - code: " + e.keyCode + " EventType = " + e.type); List <int> keyEventList; if (instance.keyEventIndDict.TryGetValue(e.keyCode, out keyEventList)) { foreach (int eventInd in keyEventList) { KeyEventMapping keyEvent = instance.keyEventMap[eventInd]; if (e.type == EventType.KeyDown && keyEvent.keyDownEventName != null) { ////Debug.Log("Handling Key event - code: " + e.keyCode + " EventType = " + e.type); VRsqr_EventsManager.TriggerEvent(keyEvent.keyDownEventName); } if (e.type == EventType.KeyUp && keyEvent.keyUpEventName != null) { ////Debug.Log("Handling Key event - code: " + e.keyCode + " EventType = " + e.type); VRsqr_EventsManager.TriggerEvent(keyEvent.keyUpEventName); } } } } }
void Awake() { //Check if instance already exists if (!instance) { //if not, set instance to this instance = this; } //If instance already exists and it's not this: else if (instance != this) { //Debug.LogError("To handle keyboard events there must be exactly one active VRsqr_InputKeyboard script on a GameObject in your scene."); //Then destroy this. This enforces our singleton pattern, meaning there can only ever be one instance of a GameManager. Destroy(gameObject); } //Sets this to not be destroyed when reloading scene //DontDestroyOnLoad(gameObject); // initialize the LUT with the keys pre-set in the inspector for (int ind = 0; ind < instance.keyEventMap.Count; ind++) { KeyEventMapping keyEvent = instance.keyEventMap[ind]; AddKeyToEventIndDict(keyEvent.keyCode, ind); } }