【发布时间】:2017-10-06 14:09:30
【问题描述】:
我在 Unity3D 中构建了一个应用程序,它应该能够检测 Microsoft HoloLens 上的蓝牙低能耗信标。这是我用来完成此任务的 Unity C# 脚本代码。
using UnityEngine;
using Windows.Devices.Bluetooth.Advertisement;
public class BeaconDetector : MonoBehaviour
{
private BluetoothLEAdvertisementWatcher _watcher;
void Start()
{
_watcher = new BluetoothLEAdvertisementWatcher();
_watcher.Received += WatcherOnReceived;
_watcher.Start();
}
//This method should be called when a beacon is detected
void WatcherOnReceived(BluetoothLEAdvertisementWatcher sender, BluetoothLEAdvertisementReceivedEventArgs args)
{
//Just a simple check if this method is even called
Debug.Log("Beacon detected!");
}
}
该应用程序可以很好地在 HoloLens 上构建和运行,但是(即使在等待几分钟后)我的调试日志中也没有得到所需的输出行。这对我来说意味着永远不会调用 WatcherOnReceived() 方法,这最终意味着没有检测到信标。
我使用了一些 Sensoro SmartBeacon-4AA,它们可以同时传输 iBeacon 和 Eddystone 信号。
我已经尝试了几个星期了,一路上做了几个教程,但我仍然不明白为什么这对我不起作用。
【问题讨论】:
-
您是否已经尝试运行this sample app(Matt Fedorovich 的第二篇文章)?
-
是的,和我提到的教程基本一样,只是写的有点不同
-
所以该应用程序按预期工作还是不工作?因为如果不是,您可能有硬件故障或权限问题?
-
嘿,我是 Matt,您应该使用的 DLL 的作者。使用本机 Windows 设备库将无法在 Unity 中用于构建它所需的 Unity 版本。您应该/可以使用我的 HoloBeaconScanner DLL 并使用 Scanner 类。我为你构建了所有的检测和解析。只需按照任一博客文章中的步骤操作,您就可以开始了。同样,无需引用 Windows 设备库,我已经为您完成了。
标签: c# unity3d bluetooth-lowenergy beacon hololens