Enabling/Disabling the GDIOAgent

Sometimes it is necessary to add or instantiate the GDIO Agent component to the project programmatically, rather than through the UI. This could be due to a requirement to remove the agent from the final build of the project (which is recommended), or simply due to wanting to control the inclusion of the agent via the build system and target. In any case, the agent can be added to a scene using the same approach as any other object, such as calling:

GameObject agentObject = new GameObject("TestAgent");
gdio.unity_agent.GDIOAgent agent = agentObject.AddComponent<gdio.unity_agent.GDIOAgent>();

The above should be called in the Awake function, to allow the agent to start before most game components. To have this script load only in certain conditions, such as when enabled by the build server, add a script definition making sure to add this definition to the Editor when you wish the agent to be enabled for testing. For more information on script defines and conditional compilation, see the Unity docs.

Controlling the Listening Port

It is also possible to change the listening port using the ReconfigurePort method on the agent. This is useful for situations where you have multiple builds running on the same OS instance, and need each to have a different listening port. For example:

public int port = 19935;

A sample script has been included below to demonstrate both of these concepts.