public void OnApplicationQuit() { YUR_Log.Log("Storing last user logged in"); string path = Utilities.YUR_Conversions.PathCombine(Application.persistentDataPath, YUR_Constants.LAST_ACTIVE_USER_FILEPATH + "active.txt"); File.WriteAllText(path, User_Manager.CurrentUser.loginCredentials.LocalId); }
/// <summary> /// Change response from Refresh Token login into valid login credentials /// </summary> /// <param name="jsonResponse"></param> /// <param name="yURaccount"></param> /// <returns></returns> public bool Convert_Refresh_Login(string jsonResponse) { try { YUR_Log.Log("Extracting data from class: " + jsonResponse); Temp_Class temp_class = new Temp_Class(); temp_class = JsonUtility.FromJson <Temp_Class>(jsonResponse); YUR_Log.Log("Temporary class: " + JsonUtility.ToJson(temp_class)); loginCredentials.LocalId = temp_class.user_id; loginCredentials.RefreshToken = temp_class.refresh_token; loginCredentials.IDtoken = temp_class.id_token; YUR_Log.Log("Conversion, items passed: " + JsonUtility.ToJson(this)); if (loginCredentials.IDtoken == "" || loginCredentials.IDtoken == string.Empty || loginCredentials.IDtoken == null) { return(false); } return(true); } catch (Exception e) { YUR_Log.Error("Convert Refresh Login Failed with Error: " + e); return(false); } }
IEnumerator LoadUsers() { YUR_Log.Log("Loading Users"); yield return(User_Manager = new GameObject("[Users]").AddComponent <YUR_UserManager>()); yield return(User_Manager.GET_LIST_USERS_IDS(ref UserList)); User_Manager.gameObject.transform.SetParent(YUR.Yur.YURGameObject.transform); bool user_found = false; if (UserList.Count == 0) { YUR_Log.Log("No users previously logged in!"); YUR_Log.Log("YUR remains inactive until a user logs in"); } else { YUR_Log.Log("Retrieving last user data: " + Last_Played_User); foreach (string st in UserList) { YUR_Log.Log(st); if (st == Last_Played_User) { YUR_Log.Log("User Found >> " + st); user_found = true; break; } } } Completed_Startup?.Invoke(user_found); yield break; }
/// <summary> /// Invoked when a user has been logged in successfully /// </summary> /// <param name="response"></param> /// <returns></returns> private string YUR_UserManager_Successful_Login(string response) { YUR_Log.Log("User Successfully Logged In"); calorieCounter = Tracking.Calories.calories.CalorieDisplayObject.AddComponent <CalorieCounter>(); calorieCounter.Completed += CalorieCounter_Completed; return(response); }
public void Save <T>(T UserClass, bool force = false) { try { if (!force) { if (UserClass is GeneralCalorieData) { if (!ALTERED_userCalories || !UserDataCheck(Data_General_Calories)) { return; } } if (UserClass is Biometrics) { if (!ALTERED_userBiometrics || !UserDataCheck(Data_Biometrics)) { return; } } if (UserClass is GameData) { if (!ALTERED_userCalories || !UserDataCheck(Data_Current_Game)) { return; } } } TimeSpan t = DateTime.UtcNow - new DateTime(1970, 1, 1); long currentDate = (long)t.TotalSeconds; if (UserClass is GeneralCalorieData) { Data_General_Calories.Last_modified = currentDate; UserManagement.YUR_UserManager.YUR_Users.SavingData(Data_General_Calories); } else if (UserClass is Biometrics) { Data_Biometrics.Last_modified = currentDate; UserManagement.YUR_UserManager.YUR_Users.SavingData(Data_Biometrics); } else if (UserClass is GameData) { Data_Current_Game.Last_Modified = currentDate; UserManagement.YUR_UserManager.YUR_Users.SavingData(Data_Current_Game); } else if (UserClass is YUR_CurrentUser) { return; } } catch (Exception e) { YUR_Log.Log("Exception[User|Save<T>] " + e); } }
public void FixedUpdate() { InputTracking.GetNodeStates(nodeStates); if (isSetup && !IsRunning) { YUR_Log.Log("Starting Calorie counter coroutine!"); StartCoroutine(CountCoroutine()); } }
public static T[] getJsonArray <T>(string json) { string newJson = "{ \"array\": " + json + "}"; YUR_Log.Log("Wrapped Json: \n" + newJson); Wrapper <T> wrapper = JsonUtility.FromJson <Wrapper <T> >(newJson); return(wrapper.array); }
/// <summary> /// Reads the data stored for the provided USERID /// </summary> /// <param name="USERID">Unique user Identifier</param> public static Local_User_Info_Reference Preview_User(string USERID) { YUR_Log.Log("Previewing " + USERID); var userDataPath = Utilities.YUR_Conversions.PathCombine(Application.persistentDataPath, YUR_Constants.USERS_FILEPATH); YUR_Log.Log("User Data Path: " + userDataPath); var userFile = Utilities.YUR_Conversions.PathCombine(userDataPath, USERID + ".json"); YUR_Log.Log("User Path: " + userFile); return(JsonUtility.FromJson <Local_User_Info_Reference>(File.ReadAllText(userFile))); }
/// <summary> /// Called upon creation of YUR object /// </summary> /// <param name="game_ID"></param> /// <param name="Fixed_Time_Step"></param> /// <param name="debug"></param> /// <param name="error_debug"></param> public void StartUp(string game_ID = "yurapp", float Fixed_Time_Step = 90, bool debug = false, bool error_debug = true, bool server_debug = false, bool log_to_file = false, bool auto_sign_in = false, bool editor_debugging = true) { main = this; DontDestroyOnLoad(main); DontDestroyOnLoad(this); this.game_ID = game_ID; TimeStep = Fixed_Time_Step; this.auto_sign_in = auto_sign_in; YUR_Log.Debugging = debug; YUR_Log.Error_Logging = error_debug; YUR_Log.Server_Logging = server_debug; YUR_Log.Log_To_File = log_to_file; YUR_Log.Editor_Debugging = editor_debugging; YUR_Log.Log("Starting YUR"); workout = gameObject.AddComponent <Workouts.Workout>(); calories = new GameObject("YUR Calorie Display Object").AddComponent <Tracking.Calories>(); DontDestroyOnLoad(workout); // TODO Check DontDestroyOnLoads are not over done. Placed everywhere as a quick fix DontDestroyOnLoad(calories); YUR_UserManager.Successful_Login += new YUR_UserManager.Login_Status_Changed(Active_User_Logged_In_Successfully); YUR_UserManager.Bad_Login += new YUR_UserManager.Login_Status_Changed(Active_User_Unable_To_Login); YUR_Log.Log("Subscribed to events"); try { YUR_Log.Log("Getting Last Logged In User ID"); string path = Utilities.YUR_Conversions.PathCombine(Application.persistentDataPath, YUR_Constants.LAST_ACTIVE_USER_FILEPATH); Directory.CreateDirectory(path); path += "active.txt"; YUR_Log.Log("Looking here: " + path); if (File.Exists(path)) { Last_Played_User = File.ReadAllText(path); YUR_Log.Log("Last uid: " + Last_Played_User); } else { YUR_Log.Log("Last user was not saved!"); } StartCoroutine(LoadUsers()); } catch (System.Exception e) { YUR_Log.Error(e.ToString()); } }
private void YUR_Main_Completed_Startup(bool user_found) { YUR_Log.Log("Startup completed. User Found for Login: "******"" || Last_Played_User == string.Empty) { return; } User_Manager.Login_USERID(Last_Played_User); } //if(user_found) //YUR_Main.main.User_Manager.Login_USERID(Last_Played_User); }
/// <summary> /// Stores logged in Users refresh token and identifiers to local storage. To be called after all data is acquired. /// </summary> public static bool Store_RefreshToken(string Name, string PhotoURL, string Refresh_Token) { var userFolder = Utilities.YUR_Conversions.PathCombine(Application.persistentDataPath, YUR_Constants.USERS_FILEPATH); var userFolderPath = Utilities.YUR_Conversions.PathCombine(userFolder, YUR_Main.main.User_Manager.CurrentUser.loginCredentials.LocalId + ".json"); YUR_Log.Log("Store_RefreshToken() userFold path: " + userFolderPath); Local_User_Info_Reference userInfo = new Local_User_Info_Reference(Name, PhotoURL, Refresh_Token); YUR_Log.Log("Setup data, ready to store"); var data = JsonUtility.ToJson(userInfo); File.WriteAllText(userFolderPath, data); YUR_Main.main.UserList.Add(YUR_Main.main.User_Manager.CurrentUser.loginCredentials.LocalId); return(true); }
/// <summary> /// Waits for the Calorie Counter to complete its setup /// </summary> private void CalorieCounter_Completed() { YUR_Log.Log("Calorie Counter Setup, setting presets"); YUR_Log.Log("_altered_counter == true"); calorieCounter.CalorieCountDisplay.fontSize = _counter_fontsize; calorieCounter.CalorieCountDisplay.color = _counter_color; YUR_Log.Log("_altered_label == true"); calorieCounter.CalorieLabel.fontSize = _label_fontsize; calorieCounter.CalorieLabel.color = _label_color; if (CalorieDisplayFonts != null) { YUR_Log.Log("Font asset not null! Applying..."); calorieCounter.CalorieCountDisplay.font = CalorieDisplayFonts; calorieCounter.CalorieLabel.font = CalorieDisplayFonts; } }
/// <summary> /// Object created check /// </summary> void Awake() { Completed_Startup += YUR_Main_Completed_Startup; YUR_Log.Log("Building YUR Object. Waiting for attach."); }
/// <summary> /// Called when a user has been logged out /// </summary> /// <param name="response">Describes reason for loggout</param> /// <returns></returns> private string YUR_UserManager_Log_Out(string response) { YUR_Log.Log("User Successfully Logged Out"); return(response); }
public void Start() { if (!enabled) { YUR_Log.Error("YUR is not enabled!"); return; } if (YUR.Yur == null) { _yur = this; } else { YUR_Log.Log("YUR is already setup"); DestroyImmediate(this); return; } /// Instantiate YUR Main Object /// YUR_GO = new GameObject("[YUR]"); /// Load General Settings /// Settings = Resources.Load("YURGeneralSettings") as YURSettingsScriptableObject; AutoUpdate = Settings.AutomaticUpdates; if (!Settings.SceneBasedWorkouts || Settings.StartWorkoutScenes == null || Settings.StartWorkoutScenes.Length <= 0) { YUR_Log.Warning("Scene based workouts is set to false. If this is a mistake, please ensure that you have at least 1 scene setup to start a workout"); Settings.SceneBasedWorkouts = false; } else { var WorkoutsManager = new GameObject("[Workouts]"); WorkoutsManager.transform.SetParent(YUR_GO.transform); _sceneWorkoutManager = WorkoutsManager.AddComponent <Workouts.YUR_SceneWorkoutManager>(); } CalorieDisplay = new GameObject("Calorie Display"); //TODO Calorie Display object is most likely instantiated elsewhere DontDestroyOnLoad(CalorieDisplay); /// Setup all AOT variables inside here if (Application.platform == RuntimePlatform.Android) { AutoUpdate = false; } var mainCameras = GameObject.FindGameObjectsWithTag(Settings.CameraTag); if (mainCameras.Length > 0) { foreach (var camera in mainCameras) { _mainCamera = camera; break; } } else { YUR_Log.Warning("Unable to locate the Camera using tag..."); } YUR_Log.Log("Starting to get YUR Object and startup system"); StartCoroutine(InstantiateYURObjects()); _eventSystem = UnityEngine.EventSystems.EventSystem.current; YUR_Main.Completed_Startup += YUR_Main_Completed_Startup; Fit = YUR_Script_Helper.Setup_YUR_Object(YUR_GO, Settings.GameID, Settings.debugging, Settings.ErrorDebugging, Settings.ServerDebugging, Settings.WriteDebuggingToFile, Settings.AutomaticallySignInUser); YURGesture = YUR_GO.AddComponent <YUR_GestureRecognition>(); platform = Settings.platform; if (platform != VRUiKits.Utils.VRPlatform.VIVE_STEAM2) { LeftControllerTrigger = Settings.LeftControllerButton; RightControllerTrigger = Settings.RightControllerButton; } this.gameObject.transform.SetParent(YUR_GO.transform); DontDestroyOnLoad(this); //UnityEngine.SceneManagement.SceneManager.sceneLoaded += SceneManager_sceneLoaded; }