public void save() { if (loggedIn) { SwarmActiveUser.saveUserData("ESCatched", esCatched.ToString()); SwarmActiveUser.saveUserData("TotalGameTime", totalGameTime.ToString()); SwarmActiveUser.saveUserData("CompletedGames", completedGames.ToString()); } }
void load() { //ho usato il += perche se è lento a caricare somma ai dati calcolati in locale print("[begin loading cloud data]"); SwarmActiveUser.getUserData("ESCatched", delegate(string responseData) { if (responseData != null) { esCatched += int.Parse(responseData); print("[esCatched = " + esCatched + "]"); } else { print("[ESCatched = NULL]"); } }); SwarmActiveUser.getUserData("TotalGameTime", delegate(string responseData) { if (responseData != null) { totalGameTime += float.Parse(responseData); print("[TotalGameTime = " + totalGameTime + "]"); } else { print("[TotalGameTime = NULL]"); } }); SwarmActiveUser.getUserData("CompletedGames", delegate(string responseData) { if (responseData != null) { completedGames += int.Parse(responseData); print("[completedGames = " + completedGames + "]"); } else { print("[CompletedGames = NULL]"); } }); print("[end loading cloud data]"); }
/** * Retrieve data of type string from the user's cloud data * * @param key The unique identifier of the object created on the server. * @param action The action to be performed (delegate to be called) when the callback is complete (the user data is returned). */ public static void getUserData(string key, System.Action <string> action) { #if UNITY_ANDROID #if !UNITY_EDITOR string objName = "SwarmActiveUserGetData." + key + "." + DateTime.Now.Ticks; GameObject gameObj = new GameObject(objName); DontDestroyOnLoad(gameObj); SwarmActiveUser component = gameObj.AddComponent <SwarmActiveUser>(); component.callbackAction = action; AndroidJavaObject callback = new AndroidJavaObject("java.lang.String", objName); AndroidJavaObject jkey = new AndroidJavaObject("java.lang.String", key); jvalue[] args = new jvalue[2]; args[0].l = jkey.GetRawObject(); args[1].l = callback.GetRawObject(); AndroidJNI.CallStaticVoidMethod(swarmUnityInterface, getCloudData, args); #endif #endif }