Advertisement
inject0r1945

Yandex Avatar Download

May 14th, 2024
354
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.94 KB | None | 0 0
  1. private async UniTask GetAvatarIconAsync()
  2. {
  3.     if (Application.isEditor)
  4.         return;
  5.  
  6.     if (GP_Player.IsLoggedIn() == false)
  7.         return;
  8.  
  9.     string avatarUrl = GP_Player.GetAvatarUrl();
  10.  
  11.     if (string.IsNullOrEmpty(avatarUrl))
  12.         return;
  13.  
  14.     UnityWebRequest downloadAvatarRequest;
  15.  
  16.     try
  17.     {
  18.         downloadAvatarRequest = await UnityWebRequestTexture.GetTexture(avatarUrl).SendWebRequest();
  19.     }
  20.     catch (UnityWebRequestException exception)
  21.     {
  22.         _logService.LogError($"An error occurred while downloading user's avatar: {exception.Text}");
  23.  
  24.         return;
  25.     }
  26.  
  27.     if (downloadAvatarRequest.result != UnityWebRequest.Result.Success)
  28.         return;
  29.  
  30.     DownloadHandlerTexture textureDownloadHandler = (DownloadHandlerTexture)downloadAvatarRequest.downloadHandler;
  31.     Texture2D texture = textureDownloadHandler.texture;
  32.  
  33.     if (texture == null)
  34.         return;
  35.  
  36.     Avatar = texture;
  37. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement