Hololight Stream for Unity extension - QR codes
QR codes
Hololight Stream allows some client devices to read QR codes in the real-world environment and send that information back to the Hololight Stream application.
Hololight Stream only supports standard square QR Codes.
Example
The ARQRCodeTrackerManager interfaces with the underlying subsystem to track QR codes.
AR QR Code Tracking Manager
The QR code tracking manager creates a GameObject for each QR code detected by the client device’s camera. Once detected, you can read and use the information in the QR code. This manager can be found at the namespace "HoloLight.Isar.ARFoundation".
Respond QR code detection
Subscribe to the ARQrCodeTrackerManager’s "trackedQrCodesChanged" event to be notified whenever a QR code is added (first detected), updated, or removed.
[SerializeField]
ARQrCodeTrackerManager m_QrCodeTrackerManager;
void OnEnable() => m_QrCodeTrackerManager.trackedQrCodesChanged += OnChanged;
void OnDisable() => m_QrCodeTrackerManager.trackedQrCodesChanged -= OnChanged;
void OnChanged(ARQrCodeChangedEventArgs eventArgs)
{
foreach (var newQrCode in eventArgs.added)
{
// Do something useful here on QR code added.
}
foreach (var updatedQrCode in eventArgs.updated)
{
// Do something useful here on QR code updated.
}
foreach (var removedQrCode in eventArgs.removed)
{
// Do something useful here on QR code removed.
}
You can also get all the currently tracked QR codes with the ARQrCodeTrackerManager’s "trackables" property. This acts like an IEnumerable collection, so you can use it in a foreach statement:
void ListAllQrCodes()
{
Debug.Log(
$"There are {m_QrCodeTrackingManager.trackables.count} QR codes being tracked.");
foreach (var trackedQrCode in m_QrCodeTrackingManager.trackables)
{
Debug.Log($"QR Code: {trackedQrCode.trackableId} is at " +
$"{trackedQrCode.transform.position}");
}
You can also get a specific image by its "TrackableId".
Or access a specific image by its TrackableId:
ARQrCode GetQrCodeAt(TrackableId trackableId)
{
return m_QrCodeTrackingManager.trackables[trackableId];
Read QR code data
The "ARQrCode" class contains a byte array property called "data". This property contains the information read from the QR code. You can use this data to carry out specific logic based on the type of QR code.
The QR code must be UTF8.
QR code prefab
The ARQrCodeTrackingManager has a "QR Code Prefab" field. This is not intended for content. When a QR code is detected, ARFoundation will create a new GameObject to represent it.
If "Qr Code Prefab" is null, then ARFoundation creates a GameObject with an ARQrCode component on it. However, if you want every tracked QR code to also include additional components, you can provide a Prefab for ARFoundation to instantiate for each detected QR code. In other words, the purpose of the Prefab field is to extend the default behavior of tracked QR codes. It is not the way you should place content in the scene.
If you would like to instantiate content that matches the position and orientation of a detected QR code and have this update automatically, then you should set the content as a child of ARQrCode.
Enabling and disabling QR code tracking
The ARQrCodeTrackingManager has an "enabled" property, which you can set to enable or disable QR code tracking. When the application no longer needs to tracki QR codes, you should set the enabled property to false to improve performance.
More Info
For more information on using AR Foundation’s trackable managers, check out Unity’s AR Foundation Trackable Managers page.