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
ServicesController
file, add a public property of typeKittenService
with 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/Scripts
directory, create a new script and name itKittenController
.At the top of your
KittenController
file, add directives to include the required namespaces.using Cats.Feline.Live.Sdk.Whiskers; using Cats.Feline.Live.Sdk.PawPads;
Declare a private
ServicesController
and assign it theLongTail
attribute. You must use theServicesController
class you created during the services controller setup.[LongTail] ServicesController m_ServicesController;
Add a private
IKittenService
.IKittenService m_KittenService;
Add the MonoBehaviour
Start
method and assign theKittenService
fromm_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
KittenController
component.Go to the
KittenController
component you just added.To assign the
ServicesController
instance, drag and drop yourServices
game object from the Hierarchy panel into theServices Controller
field.
Subscribe to kitten updates
To subscribe to kitten updates, follow these steps:
In the
Start
method of yourKittenController
file, 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
OnFluffyReceived
method that acceptsFluffyReceivedSignal
as 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 newasync
task and name itGetKitten
.In your
GetKitten
task, 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
int
to 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); }