执行"LaunchUriAsync"通过单击HoloLens UI按钮 [英] Execute "LaunchUriAsync" from a click of a HoloLens UI Button

查看:128
本文介绍了执行"LaunchUriAsync"通过单击HoloLens UI按钮的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试执行"LaunchUriAsync",但是尝试从ButtonPress事件启动它时遇到了麻烦.我尝试从Microsoft开发人员指南从Hololens调用远程协助"中进行编辑,因为我不需要GestureRecognizer.

对此有任何解决方案/解决方法吗?

这是我引用的代码的一部分:

 使用System.Collections;使用System.Collections.Generic;使用UnityEngine;使用System.Threading.Tasks;使用UnityEngine.XR.WSA.Input;公共类CallApp:MonoBehaviour{//使用它进行初始化异步void Start(){}公共无效的CallActive(){#if ENABLE_WINMD_SUPPORT字符串uriToLaunch = @"ms-voip-video:?contactids = 2914d36d-34f5-4f86-8196-52f4e53cf384";Debug.Log("LaunchUriAsync:" + uriToLaunch);System.Uri uri =新的System.Uri(uriToLaunch);等待Windows.ApplicationModel.Core.CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal,()=>{//在UI线程上完成的工作LaunchURI(uri).ConfigureAwait(false).GetAwaiter().GetResult();});#万一}公共异步任务LaunchURI(System.Uri uri){#if ENABLE_WINMD_SUPPORT//启动URI尝试{var success =等待Windows.System.Launcher.LaunchUriAsync(uri);如果(成功){Debug.Log("URI已启动");}别的{Debug.Log("URI启动失败");}}抓住(前例外){Debug.Log(ex.Message);}#万一}} 

解决方案

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

如果您需要逐步指南,则可以参考以下链接:

有关更多信息,请参见官方文档: https://microsoft.github.io/MixedRealityToolkit-Unity/Documentation/README_Button.html

I'm trying to do a "LaunchUriAsync" and I have trouble trying to get to it to launch from a ButtonPress event. I've tried to edit from the guide at Microsoft Developer "Call Remote Assist from our Hololens" as I do not require the GestureRecognizer for it.

Are there any solutions/workaround for this ?

Here is the portion of the code I'm referencing:

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
    }

}

解决方案

What you mean is that you don't know how to call a function with the button? If so, please select the button in your hierarchy, there should be a "Button" component on the inspector. Add a new entry (+ symbol) in the "On Click()"-List. Now you have to drag the GameObject with the attached script into the new entry field (no-object), after that you will be able to select a function which will be called everytime you clicking the button.

If you need a Step-by-step guide, you can refer to this link :https://gamedev.stackexchange.com/questions/149007/running-a-c-function-in-unity-with-a-button-press

If you are using PressableButton from MRTKv2, you can drag the GameObject and select a function in the location shown below

See the official documentation for more information: https://microsoft.github.io/MixedRealityToolkit-Unity/Documentation/README_Button.html

这篇关于执行"LaunchUriAsync"通过单击HoloLens UI按钮的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆