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...")
 
 
(3 intermediate revisions by the same user not shown)
Line 1: Line 1:
 +
[[Category:Setup| ]]
 
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.
 
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==
 
==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 <code>ReflexCLI.User.ConsoleStatus</code>
+
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 <code>ReflexCLI.User.ConsoleStatus</code>
  
 
;<code>OnConsoleOpened</code> : static delegate, triggers when the console is opened.
 
;<code>OnConsoleOpened</code> : static delegate, triggers when the console is opened.
Line 48: Line 49:
 
}
 
}
 
</pre>
 
</pre>
 +
 +
== 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 [https://docs.unity3d.com/ScriptReference/WaitForEndOfFrame.html WaitForEndOfFrame] (see also [https://docs.unity3d.com/Manual/ExecutionOrder.html Execution Order] in the Unity Manual).

Latest revision as of 14:00, 3 January 2018

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).