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;
agent.ReconfigurePort(port);


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


Including/excluding the GDIOAgent as part of the build process


You can conditionally include or exclude the GDIOAgent from your project using directives, which are fully supported by Unity. For more information, refer to the Unity Scripting Reference.