Conflict With Game Inputs

From ReflexCLI
Revision as of 14:00, 3 January 2018 by Rtm223 (talk | contribs)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

Unfortunately, there seems to be no simple way in Unity to automatically lock out / suppress game controls when the console is open. For games that use keyboard as an input device, you will need to check if the console is open when checking inputs from Unity.

List of APIs

Reflex provides hooks for you to query whether the console is open, and receive callbacks on open and close. These APIs are contained in the class ReflexCLI.User.ConsoleStatus

OnConsoleOpened 
static delegate, triggers when the console is opened.
OnConsoleClosed 
static delegate, triggers when the console is closed.
IsConsoleOpen() 
static member function, returns true if the console is currently open.

Example Usage

The following Code sample binds to the console open and close events to print out a debug message and uses the IsConsoleOpened() method to suppress keystrokes from the 'a' key.

using UnityEngine;
using ReflexCLI.User;

public class ReflexConsoleStatusTest : MonoBehaviour
{
    public void Awake()
    {
        ConsoleStatus.OnConsoleOpened += OnConsoleOpened;
        ConsoleStatus.OnConsoleClosed += OnConsoleClosed;
    }
    
    public void OnDestroy()
    {
        ConsoleStatus.OnConsoleOpened -= OnConsoleOpened;
        ConsoleStatus.OnConsoleClosed -= OnConsoleClosed;
    }
    
    private void OnConsoleOpened()
    {
        Debug.Log("Console Opened");
    }
	
    private void OnConsoleClosed()
    {
        Debug.Log("Console Closed");
    }
	
    void Update()
    {
        if(Input.KeyDown(KeyCode.a) && !ConsoleStatus.IsConsoleOpen())
        {
            Debug.Log("'a' Pressed");
        }
    }
}

Notes

As of version 1.1.0, the console will wait until the very end of the frame to close the console, in order to help prevent conflicts with polled inputs that might check for the same input key at arbitrary times during the frame. This is implemented using WaitForEndOfFrame (see also Execution Order in the Unity Manual).