void createEntity() { //printToConsole("Creating Entity..."); // Store all the information you want inside a dictionary Dictionary <string, object> movie = new Dictionary <string, object>(); movie ["name"] = name; movie["director"] = director; movie["duration"] = duration; movie["music"] = music; // Make the request to store the entity inside the desired collection GamedoniaData.Create("movies", movie, delegate(bool success, IDictionary data){ if (success) { //TODO Your success processing Application.LoadLevel("DataScene"); } else { //TODO Your success processing //printToConsole("Failed to create entity."); errorMsg = Gamedonia.getLastError().ToString(); Debug.Log(errorMsg); } }); }
public static void Count(string collection, string query, Action <bool, int> callback = null) { query = Uri.EscapeDataString(query); string url = "/data/" + collection + "/count?query=" + query; Gamedonia.RunCoroutine( GamedoniaRequest.get(url, GamedoniaUsers.GetSessionToken(), delegate(bool success, object data) { if (callback != null) { if (success) { IDictionary response = Json.Deserialize((string)data) as IDictionary; int count = int.Parse(response["count"].ToString()); callback(success, count); } else { callback(success, -1); } } } ) ); }
public static void LoginUserWithGameCenterId(string id, Action <bool> callback) { string auth = System.Convert.ToBase64String(Encoding.UTF8.GetBytes("gamecenter|" + id)); Dictionary <string, string> body = new Dictionary <string, string>(); body.Add("Authorization", auth); Gamedonia.RunCoroutine( GamedoniaRequest.post("/account/login", JsonMapper.ToJson(body), auth, null, null, delegate(bool success, object data) { if (success) { sessionToken = JsonMapper.ToObject <GDSessionToken>((string)data); PlayerPrefs.SetString("gd_session_token", sessionToken.session_token); RegisterDeviceAfterLogin(callback); } else { if (callback != null) { callback(success); } } } ) ); }
public static void Run(string script, Dictionary <string, object> parameters, Action <bool, object> callback = null) { string json = "{}"; if (parameters != null) { json = JsonMapper.ToJson(parameters); } Gamedonia.RunCoroutine( GamedoniaRequest.post("/run/" + script, json, null, GamedoniaUsers.GetSessionToken(), null, delegate(bool success, object data) { if (callback != null) { if (success) { string strData = data as String; if (strData.Length > 0) { callback(success, Json.Deserialize(strData)); } else { callback(success, null); } } else { callback(success, null); } } } ) ); }
private static void Profile(GDDeviceProfile device, Action <bool> callback) { Gamedonia.RunCoroutine( ProfilePushNotification(device, delegate(bool success) { callback(success); } ) ); }
public static void Delete(string collection, string entityId, Action <bool> callback = null) { Gamedonia.RunCoroutine( GamedoniaRequest.delete("/data/" + collection + "/delete/" + entityId, GamedoniaUsers.GetSessionToken(), delegate(bool success, object data) { callback(success); } ) ); }
void OnLogin(bool success) { if (success) { Application.LoadLevel("UserDetailsScene"); } else { errorMsg = Gamedonia.getLastError().ToString(); Debug.Log(errorMsg); } }
void OnCreateUser(bool success) { if (success) { GamedoniaUsers.LoginUserWithEmail(email.ToLower(), password, OnLogin); } else { errorMsg = Gamedonia.getLastError().ToString(); Debug.Log(errorMsg); } }
void OnGetMe(bool success, GDUserProfile userProfile) { if (success) { this.userProfile = userProfile; } else { errorMsg = Gamedonia.getLastError().ToString(); Debug.Log(errorMsg); } }
void OnLogin(bool success) { statusMsg = ""; if (success) { printToConsole("Session started successfully. uid: " + GamedoniaUsers.me._id); } else { errorMsg = Gamedonia.getLastError().ToString(); Debug.Log(errorMsg); } }
void OnConnectionSuccess(Gamedonia.Rt.Events.Event evt) { Debug.Log ("Connected!!"); LoginOperation lop = new LoginOperation(); System.Random rnd = new System.Random(); int val = rnd.Next (1,9999); lop.silent = Convert.ToString (val); lop.name = nameInput.text; GamedoniaRT.SharedInstance().SendOp(lop); }
void OnResetPassword(bool success) { if (success) { errorMsg = "Password reset successfully, please check your email for instructions to complete the process"; Debug.Log(errorMsg); } else { errorMsg = Gamedonia.getLastError().ToString(); Debug.Log(errorMsg); } }
public static void Register(GDDeviceProfile device, Action <bool> callback = null) { string json = JsonMapper.ToJson(device); Gamedonia.RunCoroutine( GamedoniaRequest.post("/device/register", json, delegate(bool success, object data) { if (callback != null) { callback(success); } } ) ); }
public static void VerifyPurchase(Dictionary <string, object> parameters, Action <bool> callback = null) { string json = JsonMapper.ToJson(parameters); Gamedonia.RunCoroutine( GamedoniaRequest.post("/purchase/verify", json, null, GamedoniaUsers.GetSessionToken(), null, delegate(bool success, object data) { if (callback != null) { callback(success); } } ) ); }
public static void CreateUser(GDUser user, Action <bool> callback) { string json = JsonMapper.ToJson(user); Gamedonia.RunCoroutine( GamedoniaRequest.post("/account/create", json, delegate(bool success, object data) { if (callback != null) { callback(success); } } ) ); }
void OnLogin(bool success) { statusMsg = ""; if (success) { printToConsole("Session started successfully. uid: " + GamedoniaUsers.me._id); //Requesting products GamedoniaStore.RequestProducts(productsList, productsList.Length); } else { errorMsg = Gamedonia.getLastError().ToString(); Debug.Log(errorMsg); } }
public static void RestorePassword(string restoreToken, string newPassword, Action <bool> callback) { Dictionary <string, string> body = new Dictionary <string, string>(); body.Add("password", newPassword); Gamedonia.RunCoroutine( GamedoniaRequest.post("/account/password/restore/" + restoreToken, JsonMapper.ToJson(body), null, sessionToken.session_token, null, delegate(bool success, object data) { if (callback != null) { callback(success); } } ) ); }
public static void ResetPassword(string email, Action <bool> callback) { Dictionary <string, string> body = new Dictionary <string, string>(); body.Add("email", email); Gamedonia.RunCoroutine( GamedoniaRequest.post("/account/password/reset", JsonMapper.ToJson(body), null, null, null, delegate(bool success, object data) { if (callback != null) { callback(success); } } ) ); }
public static void ChangePassword(string email, string currentPassword, string newPassword, Action <bool> callback) { string auth = System.Convert.ToBase64String(Encoding.UTF8.GetBytes("email|" + email + "|" + currentPassword)); Dictionary <string, string> body = new Dictionary <string, string>(); body.Add("password", newPassword); Gamedonia.RunCoroutine( GamedoniaRequest.post("/account/password/change", JsonMapper.ToJson(body), auth, null, null, delegate(bool success, object data) { if (callback != null) { callback(success); } } ) ); }
public static void LinkUser(Credentials credentials, Action <bool, GDUserProfile> callback) { Gamedonia.RunCoroutine( GamedoniaRequest.post("/account/link", JsonMapper.ToJson(credentials), null, sessionToken.session_token, null, delegate(bool success, object data) { if (success) { me = JsonMapper.ToObject <GDUserProfile>((string)data); } if (callback != null) { callback(success, me); } } ) ); }
public static void GetMe(Action <bool, GDUserProfile> callback) { Gamedonia.RunCoroutine( GamedoniaRequest.get("/account/me", sessionToken.session_token, delegate(bool success, object data) { if (success) { me = JsonMapper.ToObject <GDUserProfile>((string)data); } if (callback != null) { callback(success, me); } } ) ); }
public static void LogoutUser(Action <bool> callback) { Dictionary <string, string> body = new Dictionary <string, string>(); body.Add(GamedoniaRequest.GD_SESSION_TOKEN, sessionToken.session_token); Gamedonia.RunCoroutine( GamedoniaRequest.post("/account/logout", JsonMapper.ToJson(body), null, sessionToken.session_token, null, delegate(bool success, object data) { if (callback != null) { callback(success); } } ) ); }
public static void Update(string collection, Dictionary <string, object> entity, Action <bool, IDictionary> callback = null, bool overwrite = false) { string json = JsonMapper.ToJson(entity); if (!overwrite) { Gamedonia.RunCoroutine( GamedoniaRequest.post("/data/" + collection + "/update", json, null, GamedoniaUsers.GetSessionToken(), null, delegate(bool success, object data) { if (callback != null) { if (success) { callback(success, Json.Deserialize((string)data) as IDictionary); } else { callback(success, null); } } } ) ); } else { Gamedonia.RunCoroutine( GamedoniaRequest.put("/data/" + collection + "/update", json, null, GamedoniaUsers.GetSessionToken(), null, delegate(bool success, object data) { if (callback != null) { if (success) { callback(success, Json.Deserialize((string)data) as IDictionary); } else { callback(success, null); } } } ) ); } }
void OnFacebookLogin(bool success) { if (success) { //Application.LoadLevel("UserDetailsScene"); //Optional stuf if oyu want to store the facebook username inside the Gamedonia user profile Dictionary <string, object> profile = new Dictionary <string, object>(); profile.Add("nickname", fbUserName); profile.Add("registerDate", DateTime.Now); GamedoniaUsers.UpdateUser(profile, OnLogin); } else { errorMsg = Gamedonia.getLastError().ToString(); Debug.Log(errorMsg); } }
public static void Search(string collection, string query, int limit = 0, string sort = null, int skip = 0, Action <bool, IList> callback = null) { query = Uri.EscapeDataString(query); string url = "/data/" + collection + "/search?query=" + query; if (limit > 0) { url += "&limit=" + limit; } if (sort != null) { url += "&sort=" + sort; } if (skip > 0) { url += "&skip=" + skip; } Gamedonia.RunCoroutine( GamedoniaRequest.get(url, GamedoniaUsers.GetSessionToken(), delegate(bool success, object data) { if (callback != null) { if (success) { if ((data == null) || (data.Equals("[]"))) { callback(success, null); } else { callback(success, Json.Deserialize((string)data) as IList); } } else { callback(success, null); } } } ) ); }
public static void Search(string query, int limit = 0, string sort = null, int skip = 0, Action <bool, IList> callback = null) { string url = "/account/search?query=" + query; if (limit > 0) { url += "&limit=" + limit; } if (sort != null) { url += "&sort=" + sort; } if (skip > 0) { url += "&skip=" + skip; } Gamedonia.RunCoroutine( GamedoniaRequest.get(url, sessionToken.session_token, delegate(bool success, object data) { if (callback != null) { if (success) { if ((data == null) || (data.Equals("[]"))) { callback(success, null); } else { callback(success, Json.Deserialize((string)data) as IList); } } else { callback(success, null); } } } ) ); }
public void Awake() { //make sure we only have one object with this Gamedonia script at any time if (_instance != null) { Destroy(gameObject); return; } if (ApiKey.Equals("") || Secret.Equals("")) { Debug.LogError("Gamedonia Error: Missing value for ApiKey / Secret Gamedonia will not work!"); Destroy(gameObject); return; } _instance = this; DontDestroyOnLoad(this); GamedoniaRequest.initialize(ApiKey, Secret, ApiServerUrl, ApiVersion.ToString()); }
public static void Get(string collection, string entityId, Action <bool, IDictionary> callback = null) { Gamedonia.RunCoroutine( GamedoniaRequest.get("/data/" + collection + "/get/" + entityId, GamedoniaUsers.GetSessionToken(), delegate(bool success, object data) { if (callback != null) { if (success) { callback(success, Json.Deserialize((string)data) as IDictionary); } else { callback(success, null); } } } ) ); }
private void RequestAndAddDownload(string fileId) { string url = "/file/get/url/" + fileId; Gamedonia.RunCoroutine( GamedoniaRequest.get(url, GamedoniaUsers.GetSessionToken(), delegate(bool success, object data) { if (success) { //Debug.Log("Before Internal Download URL"); IDictionary dataDownload = Json.Deserialize((string)data) as IDictionary; InternalAddDownloadURL(dataDownload["downloadUrl"] as string, fileId); } else { InternalAddDownloadURL(fileId, fileId); } } ) ); }
public static void GetUser(string userId, Action <bool, GDUserProfile> callback) { Dictionary <string, string> body = new Dictionary <string, string>(); body.Add("_id", userId); Gamedonia.RunCoroutine( GamedoniaRequest.post("/account/retrieve", JsonMapper.ToJson(body), null, sessionToken.session_token, null, delegate(bool success, object data) { GDUserProfile user = null; if (success) { user = JsonMapper.ToObject <GDUserProfile>((string)data); } if (callback != null) { callback(success, user); } } ) ); }
public static void Delete(string collection, List <string> entities, bool all, Action <bool, int> callback = null) { if (all) { Gamedonia.RunCoroutine( GamedoniaRequest.delete("/data/" + collection + "/delete?all=true", GamedoniaUsers.GetSessionToken(), delegate(bool success, object data) { IDictionary response = Json.Deserialize((string)data) as IDictionary; if (success) { callback(success, int.Parse(response["deleted"].ToString())); } else { callback(success, 0); } } ) ); } else { Gamedonia.RunCoroutine( GamedoniaRequest.delete("/data/" + collection + "/delete?keys=" + String.Join(",", entities.ToArray()), GamedoniaUsers.GetSessionToken(), delegate(bool success, object data) { IDictionary response = Json.Deserialize((string)data) as IDictionary; if (success) { callback(success, int.Parse(response["deleted"].ToString())); } else { callback(success, 0); } } ) ); } }
void OnLoginSuccess(Gamedonia.Rt.Events.Event evt) { Debug.Log ("Logged in!!"); //Creamos la room long gameRoomId = GamedoniaRT.SharedInstance().roomsManager.GetRoomIdByName("DefaultRoom"); if (gameRoomId != -1) { //Room already exists //Join Room Application.LoadLevel ("ChooseGameGD"); //JoinRoomOperation jrop = new JoinRoomOperation("GameRoom"); //GamedoniaRT.SharedInstance().SendOp(jrop); } else { //We need to create the room Gamedonia.Rt.Entities.RoomSettings rsettings = new Gamedonia.Rt.Entities.RoomSettings(); rsettings.name = "DefaultRoom"; rsettings.isGame = true; rsettings.maxUsers = 8; rsettings.maxSpectators = 16; CreateRoomOperation crop = new CreateRoomOperation(rsettings); GamedoniaRT.SharedInstance().SendOp(crop); } }
void OnConnectionError(Gamedonia.Rt.Events.Event evt) { reset(); errorText.text = evt.data.GetString("error"); }
public void OnJoinRoomSuccess(Gamedonia.Rt.Events.Event evt) { Debug.Log ("Join Room Success!!!!"); Application.LoadLevel ("GameGD"); }
//---------------------------------------------------------- // Gamedonia event listeners //---------------------------------------------------------- public void OnConnectionLost(Gamedonia.Rt.Events.Event evt) { gdRt.eventsDispatcher.RemoveAllEventListeners (); Application.LoadLevel("ConnectionGD"); }
private void RemoveRemotePlayer(Gamedonia.Rt.Entities.User user) { if (user == gdRt.me) return; if (gdRemotePlayers.ContainsKey(user.userId)) { Destroy(gdRemotePlayers[user.userId]); gdRemotePlayers.Remove(user.userId); } }
void OnJoinRoomSuccess(Gamedonia.Rt.Events.Event evt) { Debug.Log ("Room Joined"); //reset(); // Go to main game scene Application.LoadLevel("GameGD"); }
public void OnCreateRoomError(Gamedonia.Rt.Events.Event evt) { string errorMsg = evt.data.GetString ("e"); errorText.text = errorMsg; }
void OnPublicMessageSuccess(Gamedonia.Rt.Events.Event evt) { Debug.Log ("Public message send successfully"); gameUI.chatContentText.text += "<b><color=purple>me:</color></b> " + gameUI.chatMessageInputField.text + "\n"; }
public static void Authenticate(Gamedonia.CredentialsType authenticationType, Dictionary<string,object> credentials, Action<bool> callback) { IGamedoniaAuthentication authentication = null; switch (authenticationType) { case Gamedonia.CredentialsType.GAMECENTER: authentication = new GamecenterAuthentication(); break; case Gamedonia.CredentialsType.FACEBOOK: authentication = new FacebookAuthentication((string) credentials["fb_uid"], (string) credentials["fb_access_token"]); break; case Gamedonia.CredentialsType.SILENT: authentication = new SilentAuthentication(); break; default: authentication = new SessionTokenAuthentication(); break; } authentication.Authenticate(callback); }
public void OnUserLeftRoom(Gamedonia.Rt.Events.Event evt) { Gamedonia.Rt.Entities.User user = evt.data.GetUser ("user"); RemoveRemotePlayer (user); }
public void OnLeaveRoomError(Gamedonia.Rt.Events.Event evt) { string errorMsg = evt.data.GetString ("e"); Debug.Log ("Error leaving the room, " + errorMsg); }
public void OnJoinRoomError(Gamedonia.Rt.Events.Event evt) { string errorMsg = evt.data.GetString("error"); errorText.text = "Unable to join room, " + errorMsg; }
public void OnRoomAddedToGroup(Gamedonia.Rt.Events.Event evt) { OnRefreshRoomsClick (); }
void OnSetUserVariablesSuccess(Gamedonia.Rt.Events.Event evt) { //Debug.Log ("On Set User Variable"); Gamedonia.Rt.Entities.User user = evt.data.GetUser ("user"); Gamedonia.Rt.Types.Array changedVars = (Gamedonia.Rt.Types.Array)evt.data.GetArray("changedVarNames"); if (user.userId == gdRt.me.userId) return; if (!gdRemotePlayers.ContainsKey (user.userId)) { // New client just started transmitting - lets create remote player Vector3 pos = new Vector3(0, 1, 0); if (user.ContainsVariable("x") && user.ContainsVariable("y") && user.ContainsVariable("z")) { pos.x = (float)user.GetVariable("x").GetDouble(); pos.y = (float)user.GetVariable("y").GetDouble(); pos.z = (float)user.GetVariable("z").GetDouble(); } float rotAngle = 0; if (user.ContainsVariable("rot")) { rotAngle = (float)user.GetVariable("rot").GetDouble(); } int numModel = 0; if (user.ContainsVariable("model")) { numModel = (int)user.GetVariable("model").GetLong(); } int numMaterial = 0; if (user.ContainsVariable("mat")) { numMaterial = (int)user.GetVariable("mat").GetLong(); } SpawnRemotePlayer(user.userId, numModel, numMaterial, pos, Quaternion.Euler(0, rotAngle, 0)); } // Check if the remote user changed his position or rotation if (changedVars.Contains("x") && changedVars.Contains("y") && changedVars.Contains("z") && changedVars.Contains("rot")) { // Move the character to a new position... gdRemotePlayers[user.userId].GetComponent<SimpleRemoteInterpolation>().SetTransform( new Vector3((float)user.GetVariable("x").GetDouble(), (float)user.GetVariable("y").GetDouble(), (float)user.GetVariable("z").GetDouble()), Quaternion.Euler(0, (float)user.GetVariable("rot").GetDouble(), 0), true); } // Remote client selected new model? if (changedVars.Contains("model")) { SpawnRemotePlayer(user.userId, (int)user.GetVariable("model").GetLong(), (int)user.GetVariable("mat").GetLong(), gdRemotePlayers[user.userId].transform.position, gdRemotePlayers[user.userId].transform.rotation); } // Remote client selected new material? if (changedVars.Contains("mat")) { gdRemotePlayers[user.userId].GetComponentInChildren<Renderer>().material = playerMaterials[ (int)user.GetVariable("mat").GetLong() ]; } }
void OnUserJoinedRoom(Gamedonia.Rt.Events.Event evt) { if (localPlayer != null) { IList<Gamedonia.Rt.Entities.UserVariable> userVariables = new List<Gamedonia.Rt.Entities.UserVariable> (); userVariables.Add (new Gamedonia.Rt.Entities.UserVariable ("x", (double)localPlayer.transform.position.x)); userVariables.Add (new Gamedonia.Rt.Entities.UserVariable ("y", (double)localPlayer.transform.position.y)); userVariables.Add (new Gamedonia.Rt.Entities.UserVariable ("z", (double)localPlayer.transform.position.z)); userVariables.Add (new Gamedonia.Rt.Entities.UserVariable ("rot", (double)localPlayer.transform.rotation.eulerAngles.y)); userVariables.Add (new Gamedonia.Rt.Entities.UserVariable ("model", (int)gdRt.me.GetVariable ("model").GetLong ())); userVariables.Add (new Gamedonia.Rt.Entities.UserVariable ("mat", (int)gdRt.me.GetVariable ("mat").GetLong ())); SetUserVariablesOperation suvop = new SetUserVariablesOperation (userVariables, gdRt.me); gdRt.SendOp (suvop); } }
void OnPublicMessagesReceived(Gamedonia.Rt.Events.Event evt) { Room room = evt.data.GetRoom ("room"); if (gdRt.roomsManager.GetLastJoinedRoom ().roomId == room.roomId) { Gamedonia.Rt.Types.Array messages = evt.data.GetArray ("messages"); for (int i =0; i< messages.Count; i++) { Map message = messages.GetMap(i); gameUI.chatContentText.text += "<b><color=darkblue>" + message.GetString("u") +"</color></b>: " + message.GetString("m") + "\n"; } } }
void OnCreateRoomSuccess(Gamedonia.Rt.Events.Event evt) { Debug.Log ("Room Created!!"); Application.LoadLevel ("ChooseGameGD"); }
public void OnCreateRoomSuccess(Gamedonia.Rt.Events.Event evt) { Application.LoadLevel ("ChooseGameGD"); }
public void Awake() { //make sure we only have one object with this Gamedonia script at any time if (_instance != null) { Destroy(gameObject); return; } if (ApiKey.Equals("") || Secret.Equals("")) { Debug.LogError("Gamedonia Error: Missing value for ApiKey / Secret Gamedonia will not work!"); Destroy(gameObject); return; } _instance = this; DontDestroyOnLoad(this); GamedoniaRequest.initialize(ApiKey,Secret, ApiServerUrl, ApiVersion.ToString()); Debug.Log ("Gamedonia initialized successfully"); }