Advertisement
halleman19

Перший запит до вк апі :)

Nov 19th, 2013
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.82 KB | None | 0 0
  1. using UnityEngine;
  2. using System.Collections;
  3.  
  4. public class ManagerVK : MonoBehaviour
  5. {
  6.     private string objName;
  7.  
  8.     private string id_user;
  9.     private string firstName_user;
  10.     private string lastName_user;
  11.  
  12.     public Texture2D ava_user;
  13.  
  14.     private void Start()
  15.     {
  16.         objName = gameObject.name;
  17.  
  18.         Application.ExternalEval("VK.loadParams(document.location.href);"+
  19.                                  "var id = VK.params.viewer_id;"+
  20.                                  "VK.api('users.get',{user_ids:id,fields:'photo_100'},function(data) { if(data.response) {"+
  21.                                  "GetUnity().SendMessage('"+ objName +"','SetID',id);" +
  22.                                  "GetUnity().SendMessage('"+ objName +"','SetAvatar',data.response[0].photo_100);" +
  23.                                  "GetUnity().SendMessage('"+ objName +"','SetName',data.response[0].first_name);"+
  24.                                  "GetUnity().SendMessage('"+ objName +"','SetLastName',data.response[0].last_name);   } });");
  25.     }
  26.  
  27.     private void OnGUI()
  28.     {
  29.         GUI.Box(new Rect(10, 10, 100, 30), id_user);
  30.         GUI.Box(new Rect(10, 45, 100, 30), firstName_user);
  31.         GUI.Box(new Rect(10, 80, 100, 30), lastName_user);
  32.         GUI.DrawTexture(new Rect(10, 115, 100, 100), ava_user);
  33.     }
  34.  
  35.     public void SetID(string value)
  36.     {
  37.         id_user = value;
  38.     }
  39.  
  40.     public void SetName(string value)
  41.     {
  42.         firstName_user = value;
  43.     }
  44.  
  45.     public void SetLastName(string value)
  46.     {
  47.         lastName_user = value;
  48.     }
  49.  
  50.     public void SetAvatar(string path)
  51.     {
  52.         StartCoroutine(DownloadAvatar(path));
  53.     }
  54.  
  55.     IEnumerator DownloadAvatar(string url)
  56.     {
  57.         WWW form = new WWW(url);
  58.         yield return form;
  59.  
  60.         ava_user = form.texture;
  61.     }
  62. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement