thieumao

Util.cs - Facebook SDK Demo 1

Aug 19th, 2015
246
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.94 KB | None | 0 0
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. using Facebook.MiniJSON;
  5.  
  6. public class Util : ScriptableObject
  7. {
  8.     public static string GetPictureURL(string facebookID, int? width = null, int? height = null, string type = null)
  9.     {
  10.         string url = string.Format("/{0}/picture", facebookID);
  11.         string query = width != null ? "&width=" + width.ToString() : "";
  12.         query += height != null ? "&height=" + height.ToString() : "";
  13.         query += type != null ? "&type=" + type : "";
  14.         if (query != "") url += ("?g" + query);
  15.         return url;
  16.     }
  17.  
  18.     public static void FriendPictureCallback(FBResult result)
  19.     {
  20.         if (result.Error != null)
  21.         {
  22.             Debug.LogError(result.Error);
  23.             return;
  24.         }
  25.  
  26.         //GameStateManager.FriendTexture = result.Texture;
  27.     }
  28.  
  29.     public static Dictionary<string, string> RandomFriend(List<object> friends)
  30.     {
  31.         var fd = ((Dictionary<string, object>)(friends[Random.Range(0, friends.Count - 1)]));
  32.         var friend = new Dictionary<string, string>();
  33.         friend["id"] = (string)fd["id"];
  34.         friend["first_name"] = (string)fd["first_name"];
  35.         return friend;
  36.     }
  37.  
  38.     public static Dictionary<string, string> DeserializeJSONProfile(string response)
  39.     {
  40.         var responseObject = Json.Deserialize(response) as Dictionary<string, object>;
  41.         object nameH;
  42.         var profile = new Dictionary<string, string>();
  43.         if (responseObject.TryGetValue("first_name", out nameH))
  44.         {
  45.             profile["first_name"] = (string)nameH;
  46.         }
  47.         return profile;
  48.     }
  49.    
  50.     public static List<object> DeserializeScores(string response)
  51.     {
  52.  
  53.         var responseObject = Json.Deserialize(response) as Dictionary<string, object>;
  54.         object scoresh;
  55.         var scores = new List<object>();
  56.         if (responseObject.TryGetValue ("data", out scoresh))
  57.         {
  58.             scores = (List<object>) scoresh;
  59.         }
  60.  
  61.         return scores;
  62.     }
  63.  
  64.     public static List<object> DeserializeJSONFriends(string response)
  65.     {
  66.         var responseObject = Json.Deserialize(response) as Dictionary<string, object>;
  67.         object friendsH;
  68.         var friends = new List<object>();
  69.         if (responseObject.TryGetValue("friends", out friendsH))
  70.         {
  71.             friends = (List<object>)(((Dictionary<string, object>)friendsH)["data"]);
  72.         }
  73.         return friends;
  74.     }
  75.    
  76.    
  77.    
  78.     public static void DrawActualSizeTexture (Vector2 pos, Texture texture, float scale = 1.0f)
  79.     {
  80.         Rect rect = new Rect (pos.x, pos.y, texture.width * scale , texture.height * scale);
  81.         GUI.DrawTexture(rect, texture);
  82.     }
  83.     public static void DrawSimpleText (Vector2 pos, GUIStyle style, string text)
  84.     {
  85.         Rect rect = new Rect (pos.x, pos.y, Screen.width, Screen.height);
  86.         GUI.Label (rect, text, style);
  87.     }
  88. }
Advertisement
Add Comment
Please, Sign In to add comment