【问题标题】:Execute "LaunchUriAsync" from a click of a HoloLens UI Button通过单击 HoloLens UI 按钮执行“LaunchUriAsync”
【发布时间】:2019-09-15 00:55:46
【问题描述】:

我正在尝试执行“LaunchUriAsync”,但无法从 ButtonPress 事件中启动它。我尝试从 Microsoft 开发人员指南“从我们的 Hololens 调用远程协助”中进行编辑,因为我不需要 GestureRecognizer。

是否有任何解决方案/解决方法?

这是我引用的代码部分:

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using System.Threading.Tasks;
using UnityEngine.XR.WSA.Input;

public class CallApp : MonoBehaviour
{
      // Use this for initialization
    async void Start()
    {

    }

    public void CallActive()
    {
#if ENABLE_WINMD_SUPPORT
        string uriToLaunch = @"ms-voip-video:?contactids=2914d36d-34f5-4f86-8196-52f4e53cf384";
        Debug.Log("LaunchUriAsync: " + uriToLaunch);

        System.Uri uri = new System.Uri(uriToLaunch);
        await Windows.ApplicationModel.Core.CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, () =>
        {
            // Work done on the UI thread
            LaunchURI(uri).ConfigureAwait(false).GetAwaiter().GetResult();
        });
#endif
    }


    public async Task LaunchURI(System.Uri uri)
    {
#if ENABLE_WINMD_SUPPORT
        // Launch the URI
        try
        {
            var success = await Windows.System.Launcher.LaunchUriAsync(uri);

            if (success)
            {
                Debug.Log("URI launched");
            }
            else
            {
                Debug.Log("URI launch failed");
            }
        }
        catch (Exception ex)
        {
            Debug.Log(ex.Message);
        }
#endif
    }

}

【问题讨论】:

  • 您是否按照tutorial 中的步骤操作,即使用了平台相关编译指令?
  • 是的,但我目前对如何通过 ButtonPress 事件运行“LaunchUriAsync”方法感到困惑。我已经添加了“#if ENABLE_WINMD_SUPPORT”,但我不确定如何从那里继续。
  • 能否请您编辑问题并包含您遇到的错误?

标签: c# windows unity3d hololens


【解决方案1】:

你的意思是你不知道如何用按钮调用函数?如果是这样,请选择层次结构中的按钮,检查器上应该有一个“按钮”组件。在“On Click()”列表中添加一个新条目(+ 符号)。现在您必须将带有附加脚本的 GameObject 拖到新的输入字段(无对象)中,之后您将能够选择每次单击按钮时都会调用的函数。

如果您需要分步指南,可以参考此链接:https://gamedev.stackexchange.com/questions/149007/running-a-c-function-in-unity-with-a-button-press

如果您使用的是 MRTKv2 中的 PressableButton,您可以拖动 GameObject 并在如下所示位置选择一个函数

更多信息请查看官方文档:https://microsoft.github.io/MixedRealityToolkit-Unity/Documentation/README_Button.html

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-11-16
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多