Guest User

Untitled

a guest
Apr 19th, 2014
22
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.  
  2. using System;
  3. using System.Collections.Generic;
  4. using System.Collections;
  5. using System.Text;
  6. using Prime31;
  7. using UnityEngine;
  8.  
  9. namespace HutongGames.PlayMaker.Actions
  10. {
  11.     [ActionCategory("Social/Facebook")]
  12.     [Tooltip("Gets the users top score")]
  13.     public class GetScores : FsmStateAction
  14.     {
  15.         [RequiredField]
  16.         [Tooltip("The Facebook id to get the score for")]
  17.         public FsmString id;
  18.  
  19.         [UIHint(UIHint.Variable)]
  20.         [RequiredField]
  21.         [Tooltip("Where to store the players score")]
  22.         public FsmInt score;
  23.  
  24.         [UIHint(UIHint.Variable)]
  25.         [Tooltip("Where to store the players name")]
  26.         public FsmString name;
  27.  
  28.         [Tooltip("What event to call on success")]
  29.         public FsmEvent onSuccess;
  30.         [Tooltip("What event to call on error")]
  31.         public FsmEvent onError;
  32.         FsmString socialError;
  33.  
  34.         public override void Reset()
  35.         {
  36.            
  37.         }
  38.  
  39.         public override void OnEnter()
  40.         {
  41.             #if UNITY_ANDROID || UNITY_IOS
  42.            
  43.             var hasReadPermissions = FsmVariables.GlobalVariables.GetFsmBool("hasReadPermissions").Value;
  44.             if(!hasReadPermissions) {
  45.                
  46.                 socialError = "You must have read permissions to call this function";
  47.                 Fsm.Event(onError);
  48.                 Finish();
  49.                
  50.                 return;
  51.             }
  52.  
  53.             Facebook.instance.getScores( id.Value, completionHandler );
  54.             #else      
  55.             Finish ();
  56.             #endif
  57.         }
  58.  
  59.         public void completionHandler(string error, System.Object result) {
  60.  
  61.             try {
  62.                 Dictionary<string,object> scoreResults = (Dictionary<string,object>) result;
  63.                 IList data = (IList)scoreResults["data"];
  64.                 Prime31.JsonObject json = (Prime31.JsonObject)data[0];
  65.                 Prime31.JsonObject user = (Prime31.JsonObject)json["user"];
  66.  
  67.                 score.Value = int.Parse(json["score"].ToString());
  68.                 name.Value = user["name"].ToString();
  69.                 Debug.Log("Name: " + name.Value + " Score: " + score.Value);
  70.             }
  71.             catch(Exception e) {
  72.                 Debug.Log(e.ToString());
  73.                 Finish ();
  74.             }
  75.  
  76.             Finish ();
  77.         }
  78.     }
  79. }
RAW Paste Data