Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using UnityEngine;
- using System.Collections;
- public class ManagerVK : MonoBehaviour
- {
- private string objName;
- private string id_user;
- private string firstName_user;
- private string lastName_user;
- public Texture2D ava_user;
- private void Start()
- {
- objName = gameObject.name;
- Application.ExternalEval("VK.loadParams(document.location.href);"+
- "var id = VK.params.viewer_id;"+
- "VK.api('users.get',{user_ids:id,fields:'photo_100'},function(data) { if(data.response) {"+
- "GetUnity().SendMessage('"+ objName +"','SetID',id);" +
- "GetUnity().SendMessage('"+ objName +"','SetAvatar',data.response[0].photo_100);" +
- "GetUnity().SendMessage('"+ objName +"','SetName',data.response[0].first_name);"+
- "GetUnity().SendMessage('"+ objName +"','SetLastName',data.response[0].last_name); } });");
- }
- private void OnGUI()
- {
- GUI.Box(new Rect(10, 10, 100, 30), id_user);
- GUI.Box(new Rect(10, 45, 100, 30), firstName_user);
- GUI.Box(new Rect(10, 80, 100, 30), lastName_user);
- GUI.DrawTexture(new Rect(10, 115, 100, 100), ava_user);
- }
- public void SetID(string value)
- {
- id_user = value;
- }
- public void SetName(string value)
- {
- firstName_user = value;
- }
- public void SetLastName(string value)
- {
- lastName_user = value;
- }
- public void SetAvatar(string path)
- {
- StartCoroutine(DownloadAvatar(path));
- }
- IEnumerator DownloadAvatar(string url)
- {
- WWW form = new WWW(url);
- yield return form;
- ava_user = form.texture;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement