public void DisplayErrorObject(string error) { Debug.LogError(error); var parsedError = StringSerializationAPI.Deserialize(typeof(FirebaseError), error) as FirebaseError; DisplayError(parsedError.message); }
public void CreateChatRoom() { reference = FirebaseDatabase.DefaultInstance.GetReference("chatRooms"); reference.GetValueAsync().ContinueWithOnMainThread(task => { if (task.IsFaulted || task.IsCanceled) { Debug.Log("task failed"); } else if (task.IsCompleted) { Debug.Log(roomIndex); DataSnapshot snapshot = task.Result; Debug.Log(task.Result); if (snapshot.Value != null) { IDictionary temp = (IDictionary)snapshot.Value; roomIndex = temp.Count; } Debug.Log(roomIndex); ChatRoom chatRoom = new ChatRoom($"http://gravatar.com/avatar/{imageURL}?d=identicon", nicknameIF.text, "", nicknameIF.text + "의 방", UID, nicknameIF.text + "의 방", roomIndex); var chatRoomJson = StringSerializationAPI.Serialize(typeof(ChatRoom), chatRoom); reference.Child(UID).SetRawJsonValueAsync(chatRoomJson); Debug.Log("채팅방 생성 완료"); SetPlayerNameAndImage(nicknameIF.text, $"http://gravatar.com/avatar/{imageURL}?d=identicon"); HumanAnimatorController.isJoin = true; JoinCanvas.SetActive(false); CharacterSelect.SetActive(true); } }); }
public SliderTree() { sliderNodeList = new Dictionary <string, SliderNode>(); //in case the templates of these change. versionHash = StringSerializationAPI.Serialize(typeof(SliderTree), this); versionHash += StringSerializationAPI.Serialize(typeof(SliderNode), new SliderNode()); }
/// <summary> /// Exchanges the Auth Code with the user's Id Token /// </summary> /// <param name="code"> Auth Code </param> /// <param name="callback"> What to do after this is successfully executed </param> public static void ExchangeAuthCodeWithIdToken(string code, Action <string> callback) { RestClient.Post($"https://oauth2.googleapis.com/token?code={code}&client_id={ClientId}&client_secret={ClientSecret}&redirect_uri=urn:ietf:wg:oauth:2.0:oob&grant_type=authorization_code", null).Then( response => { var data = StringSerializationAPI.Deserialize(typeof(GoogleIdTokenResponse), response.Text) as GoogleIdTokenResponse; callback(data.id_token); }).Catch(Debug.Log); }
public static string ToJson_full <T>(T data) { var json = StringSerializationAPI.Serialize(typeof(T), data); // Assetsフォルダに保存する json = JsonFormatter.ToPrettyPrint(json, JsonFormatter.IndentType.Space); return(json); }
public void Load() { var json = EditorPrefs.GetString(typeof(AssetWindowOptions).Name); if (json != null) { StringSerializationAPI.DeserializeInto(typeof(AssetWindowOptions), json, this); } }
public void OnBeforeSerialize() { string s = StringSerializationAPI.Serialize(typeof(Type), type); if (s.StartsWith("\"") && s.EndsWith("\"")) { s = s.Substring(1, s.Length - 2); } serializedType = s; }
public void OnAfterDeserialize() { string s = serializedType; if (!s.StartsWith("\"") && !s.EndsWith("\"")) { s = "\"" + s + "\""; } type = (Type)StringSerializationAPI.Deserialize(typeof(Type), s); }
public static T LoadAction <T>(string path) { StreamReader streamReader = new StreamReader(GetPath(path)); string json = streamReader.ReadToEnd(); streamReader.Close(); T data = (T)StringSerializationAPI.Deserialize(typeof(T), json); return(data); }
public void Save() { var existingJson = EditorPrefs.GetString(typeof(AssetWindowOptions).Name); string json = StringSerializationAPI.Serialize(this); if (existingJson != json) { Debug.Log(json); EditorPrefs.SetString(typeof(AssetWindowOptions).Name, json); } }
public SliderTree GetSliderTree(string filename) { try { return(StringSerializationAPI.Deserialize(typeof(SliderTree), File.ReadAllText(filename)) as SliderTree); } catch (Exception e) { Debug.LogError(e.ToString()); return(null); } }
/// <summary> /// Exchanges the Auth Code with the user's Access Token /// </summary> /// <param name="code"> Auth Code </param> /// <param name="callback"> What to do after this is successfully executed </param> public static void ExchangeAuthCodeWithIdToken(string code, Action <string> callback) { RestClient.Post( $"https://graph.facebook.com/v5.0/oauth/access_token?code={code}&client_id={ClientId}&client_secret={ClientSecret}&redirect_uri=http://localhost:1234/", null).Then( response => { var data = StringSerializationAPI.Deserialize(typeof(FacebookAccessTokenResponse), response.Text) as FacebookAccessTokenResponse; callback(data.access_token); }).Catch(Debug.Log); }
public static void SaveAction <T>(T data, string path) { var json = StringSerializationAPI.Serialize(typeof(T), data); // Assetsフォルダに保存する json = JsonFormatter.ToPrettyPrint(json, JsonFormatter.IndentType.Space); var savePath = GetPath(path); var writer = new StreamWriter(savePath, false); // 上書き writer.WriteLine(json); writer.Flush(); writer.Close(); }
public void GetUser(Action <User> callback, Action <AggregateException> fallback) => reference.Child($"users/{APIHandler.Instance.authAPI.GetUserId()}").GetValueAsync().ContinueWith( task => { if (task.IsCanceled || task.IsFaulted) { fallback(task.Exception); } else { callback(StringSerializationAPI.Deserialize(typeof(User), task.Result.GetRawJsonValue()) as User); } });
public bool LoadGame(out GameState gameSaveData) { gameSaveData = default(GameState); if (PlayerPrefs.HasKey("GameSave")) { string json = PlayerPrefs.GetString("GameSave"); if (StringSerializationAPI.TryDeserialize <GameState>(json, out gameSaveData)) { return(true); } } gameSaveData = default(GameState); return(false); }
public static List <T> LoadAction_list <T>(string path) { StreamReader streamReader = new StreamReader(GetPath(path)); var json = streamReader.ReadToEnd(); //var data = JsonUtility.FromJson<ListSaveData<T>>(json); var data = (ListSaveData <T>)StringSerializationAPI.Deserialize(typeof(ListSaveData <T>), json); var result = new List <T>(); foreach (var d in data.saveList) { result.Add(d); } return(result); }
/// Returns a generic object that is serialized to a Resources folder path. public static T Load <T> (string resourcesLocalPath) { // get serialized data from file TextAsset serialized = (TextAsset)Resources.Load(resourcesLocalPath, typeof(TextAsset)); if (serialized == null) { Debug.LogWarning("No save file found to load: " + GetFullResourcesPath(resourcesLocalPath)); return(default(T)); } // return deserialized data return((T)StringSerializationAPI.Deserialize(typeof(T), serialized.text)); }
public void JoinQueue(string playerId, Action <string> onGameFound, Action <AggregateException> fallback) => DatabaseAPI.PostObject($"matchmaking/{playerId}", "placeholder", () => queueListener = DatabaseAPI.ListenForValueChanged($"matchmaking/{playerId}", args => { var gameId = StringSerializationAPI.Deserialize(typeof(string), args.Snapshot.GetRawJsonValue()) as string; if (gameId == "placeholder") { return; } LeaveQueue(playerId, () => onGameFound( gameId), fallback); }, fallback), fallback);
public void PostUser(User user, Action callback, Action <AggregateException> fallback) { var messageJSON = StringSerializationAPI.Serialize(typeof(User), user); reference.Child($"users/{APIHandler.Instance.authAPI.GetUserID}").SetRawJsonValueAsync(messageJSON).ContinueWith(task => { if (task.IsCanceled || task.IsFaulted) { fallback(task.Exception); } else { callback(); } }); }
public void PostMessage(Message message, Action callback, Action <AggregateException> fallback) { var messageJSON = StringSerializationAPI.Serialize(typeof(Message), message); reference.Child("messages").Push().SetRawJsonValueAsync(messageJSON).ContinueWith(task => { if (task.IsCanceled || task.IsFaulted) { fallback(task.Exception); } else { callback(); } }); }
public void EditMessage(string messageId, string newText, Action callback, Action <AggregateException> fallback) { var messageJSON = StringSerializationAPI.Serialize(typeof(string), newText); reference.Child($"messages/{messageId}/text").SetRawJsonValueAsync(messageJSON).ContinueWith(task => { if (task.IsCanceled || task.IsFaulted) { fallback(task.Exception); } else { callback(); } }); }
public void SyncUnfold(UnfoldData data, Action <UnfoldData> callback, Action <AggregateException> fallback) { var json = StringSerializationAPI.Serialize(typeof(UnfoldData), data); reference.Child("worlds/world_1234/pieces").Push().SetRawJsonValueAsync(json).ContinueWith(task => { if (task.IsCanceled || task.IsFaulted) { fallback(task.Exception); } else { callback(data); } }); }
public void ListenForMessages(Action <Message> callback, Action <AggregateException> fallback, string key) { void CurrentListener(object o, ChildChangedEventArgs args) { if (args.DatabaseError != null) { fallback(new AggregateException(new Exception(args.DatabaseError.Message))); } else { callback(StringSerializationAPI.Deserialize(typeof(Message), args.Snapshot.GetRawJsonValue()) as Message); } } reference.Child("messages").Child(key).ChildAdded += CurrentListener; }
//public void PostMessage(Message message, Action callback, Action<AggregateException> fallback) //{ // var messageJSON = StringSerializationAPI.Serialize(typeof(Message), message); // reference.Child("messages").Push().SetRawJsonValueAsync(messageJSON).ContinueWith(task => // { // if (task.IsCanceled || task.IsFaulted) // fallback(task.Exception); // else // callback(); // }); //} //public void EditMessage(string messageId, string newText, Action callback, Action<AggregateException> fallback) //{ // var messageJSON = StringSerializationAPI.Serialize(typeof(string), newText); // reference.Child($"messages/{messageId}/text").SetRawJsonValueAsync(messageJSON).ContinueWith(task => // { // if (task.IsCanceled || task.IsFaulted) // fallback(task.Exception); // else // callback(); // }); //} //public void DeleteMessage(string messageId, Action callback, Action<AggregateException> fallback) //{ // reference.Child($"messages/{messageId}").SetRawJsonValueAsync(null).ContinueWith(task => // { // if (task.IsCanceled || task.IsFaulted) // fallback(task.Exception); // else // callback(); // }); //} public void ListenForUnfold(Action <UnfoldData> callback, Action <AggregateException> fallback) { void CurrentListener(object o, ChildChangedEventArgs args) { if (args.DatabaseError != null) { fallback(new AggregateException(new Exception(args.DatabaseError.Message))); } else { callback(StringSerializationAPI.Deserialize(typeof(UnfoldData), args.Snapshot.GetRawJsonValue()) as UnfoldData); } } newMessageListener = CurrentListener; reference.Child("worlds/world_1234/pieces").ChildAdded += newMessageListener; }
public void SaveGame() { SerializeFishData(allFish, this.gameState); if (StringSerializationAPI.TrySerialize <GameState>(gameState, out var json)) { PlayerPrefs.SetString("GameSave", json); PlayerPrefs.Save(); } // call the indexed db file sync to force saving if (Application.platform == RuntimePlatform.WebGLPlayer) { SyncFiles(); } #if UNITY_EDITOR // Debug.Log("Saved to " + SavePath); #endif }
public void ListenForMoves(Action <Move> onNewMove) { moveListener = DatabaseAPI.ListenForValueChanged( $"games/{currentGameInfo.gameId}/move", args => { if (!args.Snapshot.Exists) { return; } var move = StringSerializationAPI.Deserialize(typeof(Move), args.Snapshot.GetRawJsonValue()) as Move; if (move.userId == MainManager.Instance.currentUserId) { return; } onNewMove(move); }, exc => Debug.Log("!!!Fallback subscribe for move!!!")); }
public static void ExchangeAuthCodeWithIDToken(string code, Action <string> callback) { Debug.Log("step 1"); string requestUrl = $"https://oauth2.googleapis.com/token" + $"?client_id={ClientId}" + $"&client_secret={ClientSecret}" + $"&code={code}" + $"&grant_type=authorization_code" + $"&redirect_uri=urn:ietf:wg:oauth:2.0:oob"; RestClient.Post(requestUrl, null) .Then( onResolved: response => { Debug.Log("step 2"); var data = StringSerializationAPI.Deserialize(typeof(GoogleIDToken), response.Text) as GoogleIDToken; callback(data.id_token); }); }
// Loads and returns the recipe with given name as parameter public static Recipe LoadRecipe(string recipeName) { BinaryFormatter bf = new BinaryFormatter(); FileStream file; if (File.Exists(Application.dataPath + "/Recipes/" + recipeName + ".vrcr")) { file = File.OpenRead(Application.dataPath + "/Recipes/" + recipeName + ".vrcr"); } else { return(null); } Recipe loadedRecipe = (Recipe)StringSerializationAPI.Deserialize(typeof(Recipe), (string)bf.Deserialize(file)); file.Close(); return(loadedRecipe); }
public void ListenForEditedMessages(Action <string, string> callback, Action <AggregateException> fallback) { void CurrentListener(object o, ChildChangedEventArgs args) { if (args.DatabaseError != null) { fallback(new AggregateException(new Exception(args.DatabaseError.Message))); } else { callback(args.Snapshot.Key, StringSerializationAPI.Deserialize(typeof(string), args.Snapshot.Child("text").GetRawJsonValue()) as string); } } editedMessageListener = CurrentListener; reference.Child("messages").ChildChanged += editedMessageListener; }
// private readonly Dictionary<string, KeyValuePair<DatabaseReference, EventHandler<ChildChangedEventArgs>>> // moveListeners = // new Dictionary<string, KeyValuePair<DatabaseReference, EventHandler<ChildChangedEventArgs>>>(); public void GetCurrentGameInfo(string gameId, string localPlayerId, Action <GameInfo> callback, Action <AggregateException> fallback) { currentGameInfoListener = DatabaseAPI.ListenForValueChanged($"games/{gameId}/gameInfo", args => { if (!args.Snapshot.Exists) { return; } var gameInfo = StringSerializationAPI.Deserialize(typeof(GameInfo), args.Snapshot.GetRawJsonValue()) as GameInfo; currentGameInfo = gameInfo; currentGameInfo.localPlayerId = localPlayerId; DatabaseAPI.StopListeningForValueChanged(currentGameInfoListener); callback(currentGameInfo); }, fallback); }