Create a services controller
The services controller works as a hub for the services within the Live Systems Data SDK package.
Create a services controller script
To create a services controller script, follow these steps:
- In your
Assets/Scripts
directory, create a new script and name itServicesController
. At the top of your
ServicesController
file, add directives to include the required namespaces.using Unity.DigitalTwins.Live.Sdk.Implementations; using Unity.DigitalTwins.Live.Sdk.Settings;
Within the
ServicesController
class, add public environment settings.public EnvironmentSettings EnvironmentSettings;
Add properties with public accessors and private setters for each of the Live Systems Data services you want to use. This makes each service available through the controller and handles their creation locally.
public IConfigurationService ConfigurationService { get; private set; } public IFacilityService FacilityService { get; private set; } public ITelemetryHistoryService TelemetryHistoryService { get; private set; }
In your
Awake
method, initialize the services you added earlier.ConfigurationService = new ConfigurationService(FacilityService); FacilityService = new FacilityService(EnvironmentSettings); TelemetryHistoryService = new TelemetryHistoryService(FacilityService);
Add the services controller to your scene
To add the services controller to your scene, follow these steps:
- Go to GameObject > Create Empty and rename the game object to Services.
- Select the Services game object you just created.
- In the Inspector panel, select Add Component and add the
ServicesController
component. - Go to the
ServicesController
component you just added. - From the Project panel, drag and drop your
EnvironmentSettings
into its corresponding field.