Difference between revisions of "Conflict With Game Inputs"

From ReflexCLI
Jump to: navigation, search
(Created page with "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 de...")
(No difference)

Revision as of 15:13, 30 August 2017

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 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");
        }
    }
}