我有一个用Unity构建的hololens2应用程序。Environment.Username在Unity编辑器中工作正常,但当我部署到HL2时,Environment.UserName未知。在播放器设置中,我已经应用了企业应用程序、WebCam、麦克风、HumanInterfaceDevice、UserAccountInformation、蓝牙、SystemManagement、UserDataTasks和联系人。
它构建得很好,部署到HL2上也没有问题,但UserName是未知的。当我转到HL2开始菜单时,它会正确显示我的姓名。
请帮帮我
马丁·F。
发布于 2021-07-08 15:08:26
请尝试以下代码,它应该显示登录到HoloLens2的帐户名:
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
}
}https://stackoverflow.com/questions/68293268
复制相似问题