单击 HoloLens UI 按钮执行 "LaunchUriAsync"

Execute "LaunchUriAsync" from a click of a HoloLens UI Button

我正在尝试执行 "LaunchUriAsync",但我无法尝试从 ButtonPress 事件启动它。我已尝试根据 Microsoft Developer "Call Remote Assist from our Hololens" 的指南进行编辑,因为我不需要 GestureRecognizer。

这个有solutions/workaround吗?

这是我引用的代码部分:

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
    }

}

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

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

如果您使用的是 MRTKv2 中的 PressableButton,则可以将游戏对象和 select 函数拖动到如下所示的位置

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