【问题标题】:Input.LocationService.isEnabledByUser returning false with Unity Remote in the Editor?Input.LocationService.isEnabledByUser 在编辑器中使用 Unity Remote 返回 false?
【发布时间】:2017-07-27 02:38:58
【问题描述】:

关于 Stack-Overflow 的第一篇文章,如果有人问过这个问题,我深表歉意,但我搜索了很多,找不到有类似问题的人。

所以我刚刚完成了手机(三星 Galaxy S8)与 Unity Remote 5 的设置,并按照此处的设置我的位置服务标识:https://docs.unity3d.com/ScriptReference/LocationService.Start.html

我的问题是脚本似乎无法通过 !Input.location.isEnabledByUser if 语句。

我启用了我的定位服务并开启了高精度定位,我发现这是另一个线程中的问题。 Unity Remote 5 可以在我的手机上正确显示场景,但它似乎没有读取位置数据?

有人对此有任何解决方案吗? 如果这在其他地方得到了回答,或者我遗漏了一些非常琐碎的事情,我再次道歉。

【问题讨论】:

    标签: c# android unity3d location


    【解决方案1】:

    你的答案不太正确。

    问题出在代码的第一行:

    if (!Input.location.isEnabledByUser)
        yield break;
    

    当您在编辑器中单击“播放”时,Unity 需要几秒钟才能连接到 Unity Remote。在这几秒钟之前,Input.location.isEnabledByUser 将变为 falseyield break 将执行。

    有两种可能的方法来解决这个问题:

    1.在该行代码之前添加延迟:

    yield return new WaitForSeconds(3)
    
    if (!Input.location.isEnabledByUser)
        yield break;
    
    ....
    

    2。使用EditorApplication.isRemoteConnected 等待编辑器连接到Unity Remote,然后再继续。

    您还必须将它包裹在 Unity 的 Platform Dependent directive 周围,以便它可以编译为独立构建,因为此函数来自 UnityEditor 命名空间。

     #if UNITY_EDITOR
     //Wait until Unity connects to the Unity Remote, while not connected, yield return null
     while (!UnityEditor.EditorApplication.isRemoteConnected)
     {
         yield return null;
     }
     #endif
    
    if (!Input.location.isEnabledByUser)
        yield break;
    
    ....
    

    【讨论】:

    • 我使用了第二种方法,这对我有用。统一 2018.3.9。 Unity Remote 5. iPhone
    【解决方案2】:

    好吧,我在这里没有注意到的有趣事实是,虽然 Unity Remote 5 将您的设备用作屏幕,但它实际上并未将您的设备视为移动设备。

    这似乎很愚蠢,但我想我可以解决有时在需要测试特定移动设备时进行完整的导出构建 xD

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2019-02-08
      • 1970-01-01
      • 2020-11-20
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多