Conflict With Game Inputs

From ReflexCLI
Revision as of 15:21, 30 August 2017 by Rtm223 (talk | contribs)
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");
        }
    }
}