Created
June 7, 2020 01:19
-
-
Save ovjang/022193997a0989a17372decb819b9e37 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System.Collections; | |
using System.Collections.Generic; | |
using UnityEngine; | |
using UnityEngine.UI; | |
using System; | |
#if (!UNITY_EDITOR) | |
using Windows.System; | |
using Windows.UI.Core; | |
#endif | |
public class GetUserName : MonoBehaviour | |
{ | |
private Text username; | |
void Start() | |
{ | |
username = gameObject.GetComponent<Text>(); | |
FindUsers(); | |
} | |
//function to pull current username | |
#if (!UNITY_EDITOR) | |
public async void FindUsers() | |
{ | |
// リモートユーザー取得 | |
username.text += ("Start Find Remote User\n"); | |
var users = await User.FindAllAsync(UserType.RemoteUser); | |
foreach (var user in users) | |
{ | |
var properties = await user.GetPropertiesAsync(new string[] { KnownUserProperties.AccountName }); | |
foreach (var propertie in properties) | |
{ | |
username.text += propertie.Value + "\n"; | |
} | |
} | |
// ローカルユーザー取得 | |
username.text += ("Start Find Local User\n"); | |
users = await User.FindAllAsync(UserType.LocalUser); | |
foreach (var user in users) | |
{ | |
var properties = await user.GetPropertiesAsync(new string[] { KnownUserProperties.AccountName }); | |
foreach (var propertie in properties) | |
{ | |
username.text += propertie.Value + "\n"; | |
} | |
} | |
} | |
#else | |
void FindUsers() | |
{ | |
username.text = System.Environment.UserName; | |
} | |
#endif | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment