Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Collections;
- using System.Text;
- using Prime31;
- using UnityEngine;
- namespace HutongGames.PlayMaker.Actions
- {
- [ActionCategory("Social/Facebook")]
- [Tooltip("Gets the users top score")]
- public class GetScores : FsmStateAction
- {
- [RequiredField]
- [Tooltip("The Facebook id to get the score for")]
- public FsmString id;
- [UIHint(UIHint.Variable)]
- [RequiredField]
- [Tooltip("Where to store the players score")]
- public FsmInt score;
- [UIHint(UIHint.Variable)]
- [Tooltip("Where to store the players name")]
- public FsmString name;
- [Tooltip("What event to call on success")]
- public FsmEvent onSuccess;
- [Tooltip("What event to call on error")]
- public FsmEvent onError;
- FsmString socialError;
- public override void Reset()
- {
- }
- public override void OnEnter()
- {
- #if UNITY_ANDROID || UNITY_IOS
- var hasReadPermissions = FsmVariables.GlobalVariables.GetFsmBool("hasReadPermissions").Value;
- if(!hasReadPermissions) {
- socialError = "You must have read permissions to call this function";
- Fsm.Event(onError);
- Finish();
- return;
- }
- Facebook.instance.getScores( id.Value, completionHandler );
- #else
- Finish ();
- #endif
- }
- public void completionHandler(string error, System.Object result) {
- try {
- Dictionary<string,object> scoreResults = (Dictionary<string,object>) result;
- IList data = (IList)scoreResults["data"];
- Prime31.JsonObject json = (Prime31.JsonObject)data[0];
- Prime31.JsonObject user = (Prime31.JsonObject)json["user"];
- score.Value = int.Parse(json["score"].ToString());
- name.Value = user["name"].ToString();
- Debug.Log("Name: " + name.Value + " Score: " + score.Value);
- }
- catch(Exception e) {
- Debug.Log(e.ToString());
- Finish ();
- }
- Finish ();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement