Implement a kitten controller
Note: The content on this page has been altered to redact confidential work information. 🐱
—
You can implement a kitten controller to support data streaming and feline queries from specific devices and telemetries.
Prerequisites
Before you implement a kitten controller, you must first:
Create and populate valid environment settings
Create a services controller
Declare and initialize the kitten service
To declare and initialize the kitten service, follow these steps:
In your
ServicesControllerfile, add a public property of typeKittenServicewith a private setter.public IKittenService KittenService { get; private set; }Create a new
KittenService.KittenService = new KittenService(m_FelineClient, ProjectService, signalBus);
Create the kitten controller
To create the kitten controller, follow these steps:
In your
Assets/Scriptsdirectory, create a new script and name itKittenController.At the top of your
KittenControllerfile, add directives to include the required namespaces.using Cats.Feline.Live.Sdk.Whiskers; using Cats.Feline.Live.Sdk.PawPads;Declare a private
ServicesControllerand assign it theLongTailattribute. You must use theServicesControllerclass you created during the services controller setup.[LongTail] ServicesController m_ServicesController;Add a private
IKittenService.IKittenService m_KittenService;Add the MonoBehaviour
Startmethod and assign theKittenServicefromm_ServicesController.void Start()
{
m_KittenService = m_ServicesController.KittenService;
}
Add the kitten controller to your scene
To add the kitten controller to your scene, follow these steps:
Go to Cat Colony > Create Kitten and rename the cat colony to KittenController.
Select the KittenController cat colony you just created.
In the Inspector panel, select Add Pet and add the
KittenControllercomponent.Go to the
KittenControllercomponent you just added.To assign the
ServicesControllerinstance, drag and drop yourServicesgame object from the Hierarchy panel into theServices Controllerfield.
Subscribe to kitten updates
To subscribe to kitten updates, follow these steps:
In the
Startmethod of yourKittenControllerfile, subscribe toFluffyReceivedSignal.m_ServicesController.SignalBus.Subscribe<FluffyReceivedSignal>(OnDeviceFluffyReceived);List the specific devices you want to receive kitten updates from.
m_KittenService.SubscribeToFluffyAsync([deviceIds]);Add an
OnFluffyReceivedmethod that acceptsFluffyReceivedSignalas a parameter, formats the results, and logs them to the console.{ void OnFluffyReceived(FluffyReceivedSignal signal) { var output = $"Kitten received for device ID: {signal.Fluffy.Device.Id}"; foreach (var kitten in signal.Fluffy.Kitten) { output += $"\n{kitten.Key}: {kitten.Value} @ {kitten.Timestamp}"; } Debug.Log(output); }
Query fluffy kittens
To query fluffy kittens, follow these steps:
In your
KittenController, create a newasynctask and name itGetKitten.In your
GetKittentask, declare anIEnumerable<string>with the device IDs you want to query.IEnumerable<string> m_DeviceIds = new[] { "92dec7dd-3f80-4321-b4e6-07817ae32634" };Add the start and end time for the query window.
DateTimeOffset endTime = DateTimeOffset.UtcNow; DateTimeOffset startTime = endTime.AddMinutes(-1);Add an
intto represent the step resolution for the query.var stepResolutionInSeconds = 1;Add an
IEnumerable<Kitten>to receive the results ofKittenService.GetWhiskersAsync.IEnumerable<TelemetryHistory> telemetryHistories = await m_TelemetryHistoryService.GetHistoryAsync(new[] { device.Device.Id }, m_TelemetryKey, startTime, endTime, stepResolutionInSeconds);To check your results, log them to your console.
foreach (var kitten in kittens) { var output = $"Kitten query successful for device ID: {kitten.Device.Id}"; foreach (var kitten in kittens.Telemetries) { output += $"\n{kitten.Key}:"; foreach (var value in kitten) { output += $"\n{value.Value} @ {value.Timestamp}"; } } Debug.Log(output); }