void Start() { // Listen to events EventManager.StartListening <BasicEvent> (Constants.ON_CURRENT_DATA_RECEIVED, OnCurrentDataReceived); EventManager.StartListening <BasicEvent> (Constants.ON_ANSWER_CLICK_DONE, OnAnswerClickDone); EventManager.StartListening <BasicEvent> (Constants.LAST_ROUND_ANSWER, OnLastRoundAnswer); playerScore = 0; questionNumber = 0; currentRoundNumber = -1; isRoundActive = false; corrects = correctsOnChunk = 0; errors = 0; markerText.text = corrects + "/" + Constants.QUESTIONS_PER_ROUND; user = UserLocal.ReadUserData(); // Show user name userNameText.text = user.Name; win = true; currentLevel = user.Level; // Show Round #0, only for first round if (currentRoundNumber == -1) { StartGame(); } }
public static void SaveUserData(string userName, int lastScore, Constants.Levels level = Constants.Levels.BASIC) { // Avoid some serialization problems on iOS if (Application.platform == RuntimePlatform.IPhonePlayer) { System.Environment.SetEnvironmentVariable("MONO_REFLECTION_SERIALIZER", "yes"); } // Allow serialization BinaryFormatter bf = new BinaryFormatter(); FileStream file; UserLocalData user = new UserLocalData(); user.SetData(userName, lastScore, level); // Check user exists if (File.Exists(Application.persistentDataPath + "/" + fileUserLocal)) { // If exists, delete it ... File.Delete(Application.persistentDataPath + "/" + fileUserLocal); } // Create new file file = File.Create(Application.persistentDataPath + "/" + fileUserLocal); file.Close(); // Write data file = File.Open(Application.persistentDataPath + "/" + fileUserLocal, FileMode.Open); bf.Serialize(file, user); file.Close(); }
private void LevelDown() { switch (currentLevel) { default: currentLevel = (Constants.Levels)(currentLevel - 1); break; case Constants.Levels.BASIC: break; } // Save new level user.Level = currentLevel; UserLocal.SaveUserData(user); }
public void SetData(string userName, int userLastScore, Constants.Levels userLevel) { this.name = userName; this.lastScore = userLastScore; this.level = userLevel; }
public UserLocalData() { this.name = ""; this.lastScore = 0; this.level = Constants.Levels.BASIC; }
/// <summary> /// Chamada quando uma cena e carregada /// Nota: Esta funcao e chamada pelo Awake e OnLevelWasLoaded, /// e nao faz parte do Unity /// </summary> void OnLevelLoad() { // Gera uma nova UI, isso deve acontecer no menu principal if (showPanels == null) { GameObject ui = GameObject.Instantiate(UIPrefab); showPanels = ui.GetComponent<ShowPanels>(); showPanels.ShowMenu(); } // Atualiza qual fase o jogo esta currentLevel = GetLevelEnum (); if (currentLevel != Constants.Levels.None) { // retorna NULL se nao achou nada com a TAG GameObject[] pickUps = GameObject.FindGameObjectsWithTag (Constants.Tags.PickUps) as GameObject[]; pickUpsTotal = pickUps.Length; //conta o total de pickups na fase, de acordo com o vetor pickUps if (pickUps == null || pickUps.Length == 0) { Debug.LogWarning ("Nenhum pickup encontrado"); return; } pickUpsTotal = pickUps.Length; gameTime = 0; score = 0; pickUpsGet = 0; // Ativa o HUD showPanels.ShowGameScreen (); // Inicializa um relogio interno InvokeRepeating ("GameTimer", 0f, 1f); } else { // confirma que o HUD esta desativado showPanels.HideGameScreen(); } count = 0; Instance = this; }