Enabling the GameDriver Agent with mixed input systems

Learn how to configure GameDriver tests to work with mixed input systems in Unity

If you need to add the GDIOAgent programmatically at runtime and also need to use the "Force Old Input System" setting, typically due to keyboard and mouse inputs that continue to use the legacy Input Manager, you must enable this setting prior to enabling input hooking.

The script below demonstrates this. The GDIOAgent is created in the Awake(), and the hooks are enabled in Start(), simulating the Api changing the hook status after loading.  ForceOldInputSystem must be enabled before Enable Hooks, or else the Enable hooks won’t know to include legacy inputs.

public class GDIOSetup : MonoBehaviour
{
GDIOAgent gdioInstance = null;
void Awake()
{
var gdioObject = new GameObject("GDIOAgent");
gdioInstance = gdioObject.AddComponent<GDIOAgent>();
gdioInstance.m_ForceOldInputSystem = true;
gdioInstance.m_EnableMouseHooks = false;
gdioInstance.m_EnableKeyboardHooks = false;
}
void Start()
{
gdioInstance.m_EnableMouseHooks = true;
}

// Update is called once per frame
void Update()
{
if(Input.GetMouseButtonDown(0) || Input.GetMouseButton(0))
{
Debug.Log("Left mouse button clicked");
}
}
}

This approach could be used with Unity script defines to only load the agent with test or development builds, and exclude the agent for Production builds.