首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Hololens2中的Environment.userName未知

Hololens2中的Environment.userName未知
EN

Stack Overflow用户
提问于 2021-07-08 05:42:23
回答 1查看 39关注 0票数 0

我有一个用Unity构建的hololens2应用程序。Environment.Username在Unity编辑器中工作正常,但当我部署到HL2时,Environment.UserName未知。在播放器设置中,我已经应用了企业应用程序、WebCam、麦克风、HumanInterfaceDevice、UserAccountInformation、蓝牙、SystemManagement、UserDataTasks和联系人。

它构建得很好,部署到HL2上也没有问题,但UserName是未知的。当我转到HL2开始菜单时,它会正确显示我的姓名。

请帮帮我

马丁·F。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2021-07-08 15:08:26

请尝试以下代码,它应该显示登录到HoloLens2的帐户名:

代码语言:javascript
复制
using System;
using System.Collections.Generic;
using System.Text;
using TMPro;
using UnityEngine;
#if WINDOWS_UWP
using Windows.System;
#endif
public class UserName : MonoBehaviour
{
    [SerializeField]
    private TMP_Text userNameText = null;
    // Start is called before the first frame update
    async void Start()
    {
#if WINDOWS_UWP
        IReadOnlyList<User> users = await User.FindAllAsync();
        StringBuilder sb = new StringBuilder();
        foreach (User u in users)
        {
            string name = (string)await u.GetPropertyAsync(KnownUserProperties.AccountName);
            if (string.IsNullOrWhiteSpace(name))
            {
                name = "unknown account name";
            }
            sb.AppendLine(name);
        }
        userNameText.text = sb.ToString();
#endif
    }
}
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/68293268

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档