// Use this for initialization void Awake() { coinsLabel = GameObject.Find("CoinsScore"); Application.targetFrameRate = 60; int layermask = ~(1 << 6); // Debug.Log("layermask: " + layermask); if (Time.timeScale < 1) { Time.timeScale = 1; } currentWorldData = DataManager.FindWorldDataById(World.selectedWorld.ID, DataManager.filterdWorldsData); //Get the current world currentLevelData = currentWorldData.FindLevelDataById(TableLevel.selectedLevel.ID); ///Get the current level CurrentLevel = "Level" + currentWorldData.ID + "." + currentLevelData.ID; // Debug.Log ("Level: " + CurrentLevel); // if(CurrentLevel == "Level1.1"){ // GameObject.FindObjectOfType<HintOne> ().Hint (); // int bulletsBalance = StoreInventory.GetItemBalance("armor"); // Debug.Log("armor balance: " + bulletsBalance); // } // if(CurrentLevel == "Level1.2"){ // GameObject.FindObjectOfType<HintTwo> ().Hint (); // } #if UNITY_IOS System.Environment.SetEnvironmentVariable("MONO_REFLECTION_SERIALIZER", "yes"); #endif }
//后一关 public void NextLevel() { if (LevelsTable.currentLevelID >= 1 && LevelsTable.currentLevelID < LevelsTable.tableLevels.Count) { ///Get the next level and check if it's locked , then do not load the next level DataManager.MissionData currentMissionData = DataManager.FindMissionDataById(Mission.wantedMission.ID, DataManager.filterdMissionsData); //Get the current mission DataManager.LevelData currentLevelData = currentMissionData.FindLevelDataById(TableLevel.wantedLevel.ID); ///Get the current level if (currentLevelData.ID + 1 < currentMissionData.levelsData.Count) { DataManager.LevelData nextLevelData = currentMissionData.FindLevelDataById(TableLevel.wantedLevel.ID + 1); ///Get the next level if (nextLevelData.isLocked) { ///Play lock sound effectd if (levelLockedSFX != null) { AudioSource.PlayClipAtPoint(levelLockedSFX, Vector3.zero, effectsAudioSource.volume); } ///Skip the next return; } } LevelsTable.currentLevelID++; ///Increase level ID TableLevel.wantedLevel = LevelsTable.tableLevels [LevelsTable.currentLevelID - 1]; ///Set the wanted level CreateNewLevel(); ///Create new level } else { ///Play lock sound effectd if (levelLockedSFX != null) { AudioSource.PlayClipAtPoint(levelLockedSFX, Vector3.zero, effectsAudioSource.volume); } } }
/// <summary> /// Go to the next level. /// </summary> public void NextLevel() { if (TableLevel.selectedLevel.ID >= 1 && TableLevel.selectedLevel.ID <= LevelsTable.tableLevels.Count) { ///Get the next level and check if it's locked , then do not load the next level DataManager.WorldData currentWorldData = DataManager.FindWorldDataById(World.selectedWorld.ID, DataManager.filterdWorldsData); //Get the current world DataManager.LevelData currentLevelData = currentWorldData.FindLevelDataById(TableLevel.selectedLevel.ID); ///Get the current level if (currentLevelData.ID + 1 < currentWorldData.levelsData.Count) { DataManager.LevelData nextLevelData = currentWorldData.FindLevelDataById(TableLevel.selectedLevel.ID + 1); ///Get the next level if (nextLevelData.isLocked) { ///Play lock sound effectd // Debug.Log ("locked"); if (levelLockedSFX != null) { // AudioSource.PlayClipAtPoint (levelLockedSFX, Vector3.zero, GeneralCanvas.instance.audioSources [1].volume); } ///Skip the next return; } string LoadNextLevel = "Level" + currentWorldData.ID + "." + nextLevelData.ID; GameObject.FindObjectOfType <UIEvents> ().LoadNextLevelAfterChecking(LoadNextLevel); // StartCoroutine(LoadNextScene(LoadNextLevel)); // Application.LoadLevel (LoadNextLevel); TableLevel.selectedLevel.ID = TableLevel.selectedLevel.ID + 1; // Debug.Log ("nextLevelData.name " + LoadNextLevel); } //Load levels scene if (currentLevelData.ID == LevelsTable.tableLevels.Count) { // Application.LoadLevel (Scenes.levelsScene); } // else { //Load game scene // Debug.Log ("nextLevelData.name " + currentWorldData.ID + currentLevelData.ID); // TableLevel.selectedLevel = LevelsTable.tableLevels [TableLevel.selectedLevel.ID];///Set the selected level // Debug.Log ("TableLevel.selectedLevel.name" + TableLevel.selectedLevel); // Application.LoadLevel (Scenes.gameScene); // } } else { ///Play lock sound effectd if (levelLockedSFX != null) { // AudioSource.PlayClipAtPoint (levelLockedSFX, Vector3.zero, GeneralCanvas.instance.audioSources [1].volume); } } }
/// <summary> /// Checks Wheter the level is completed. /// </summary> private void CheckLevelComplete() { if (gridLines == null) { return; } bool isLevelComplete = true; for (int i = 0; i < gridLines.Length; i++) { //只要有一个gridLines.completedLine = fase就是未完成 if (!gridLines [i].completedLine) { isLevelComplete = false; break; } } if (isLevelComplete) //过关 { timer.Stop(); //停止定时器 isRunning = false; try { ///Save the stars level DataManager.MissionData currentMissionData = DataManager.FindMissionDataById(Mission.wantedMission.ID, DataManager.filterdMissionsData); DataManager.LevelData currentLevelData = currentMissionData.FindLevelDataById(TableLevel.wantedLevel.ID); currentLevelData.starsLevel = StarsRating.GetLevelStarsRating(Timer.timeInSeconds, GameManager.movements, gridCells.Length); if (currentLevelData.ID + 1 <= currentMissionData.levelsData.Count) { ///Unlock the next level DataManager.LevelData nextLevelData = currentMissionData.FindLevelDataById(TableLevel.wantedLevel.ID + 1); nextLevelData.isLocked = false; } DataManager.SaveMissionsDataToFile(DataManager.filterdMissionsData); } catch (Exception ex) { Debug.Log(ex.Message); } ///Show the black area BlackArea.Show(); //深色背景 ///Show the awesome dialog GameObject.FindObjectOfType <AwesomeDialog> ().Show(); //显示过关的dialog Debug.Log("You completed level " + TableLevel.wantedLevel.ID); } }
/// <summary> /// Settings up the level contents in the table. /// </summary> /// <param name="tableLevel">Table level.</param> /// <param name="ID">ID of the level.</param> private void SettingUpLevel(TableLevel tableLevel, int ID) { if (tableLevel == null) { return; } ///Get Mission Data of the current Mission tempMissionData = DataManager.FindMissionDataById(Mission.wantedMission.ID, DataManager.instance.filterdMissionsData); if (tempMissionData == null) { Debug.Log("Null MissionData"); return; } ///Get Level Data of the wanted (selected) Level tempLevelData = tempMissionData.FindLevelDataById(tableLevel.ID); if (tempLevelData == null) { Debug.Log("Null LevelData"); return; } //If the level is locked then , skip the next if (tempLevelData.isLocked) { return; } ///Make the button interactable tableLevel.GetComponent <Button> ().interactable = true; ///Show the stars of the level tableLevel.transform.Find("Stars").gameObject.SetActive(true); ///Hide the lock tableLevel.transform.Find("Lock").gameObject.SetActive(false); ///Show the title of the level tableLevel.transform.Find("LevelTitle").gameObject.SetActive(true); ///Setting up the level title tableLevel.transform.Find("LevelTitle").GetComponent <Text> ().text = ID.ToString(); ///Get stars Number from current Level Data tableLevel.starsNumber = tempLevelData.starsNumber; tempTransform = tableLevel.transform.Find("Stars"); ///Apply the current Stars Rating if (tempLevelData.starsNumber == TableLevel.StarsNumber.ONE) //One Star { tempTransform.Find("FirstStar").GetComponent <Image> ().sprite = starOn; tempTransform.Find("SecondStar").GetComponent <Image> ().sprite = starOff; tempTransform.Find("ThirdStar").GetComponent <Image> ().sprite = starOff; } else if (tempLevelData.starsNumber == TableLevel.StarsNumber.TWO) //Two Stars { tempTransform.Find("FirstStar").GetComponent <Image> ().sprite = starOn; tempTransform.Find("SecondStar").GetComponent <Image> ().sprite = starOn; tempTransform.Find("ThirdStar").GetComponent <Image> ().sprite = starOff; } else if (tempLevelData.starsNumber == TableLevel.StarsNumber.THREE) //Three Stars { tempTransform.Find("FirstStar").GetComponent <Image> ().sprite = starOn; tempTransform.Find("SecondStar").GetComponent <Image> ().sprite = starOn; tempTransform.Find("ThirdStar").GetComponent <Image> ().sprite = starOn; } else //Zero Stars { tempTransform.Find("FirstStar").GetComponent <Image> ().sprite = starOff; tempTransform.Find("SecondStar").GetComponent <Image> ().sprite = starOff; tempTransform.Find("ThirdStar").GetComponent <Image> ().sprite = starOff; } }
/// <summary> ///On level complete. /// </summary> public void OnLevelComplete() { if (instantiated) { return; } instantiated = true; KeepDataOnPlayMode.instance.reloadedTimes += 1; if (KeepDataOnPlayMode.instance.reloadedTimes > 5) { KeepDataOnPlayMode.instance.reloadedTimes = 0; } if (KeepDataOnPlayMode.instance.randomAds == KeepDataOnPlayMode.instance.reloadedTimes) { KeepDataOnPlayMode.instance.reloadedTimes = 0; KeepDataOnPlayMode.instance.randomAds = KeepDataOnPlayMode.instance.generateIntAds(); TotalData.LoadTotalFromFile(); if (!TotalData.totalData.noads) { ShowAd(); } } // Debug.Log("on Level Complete"); int timerType = 0; if (timer != null) { // Debug.Log("timer"); timer.Stop(); timerType = 1; CoinsToInt(); } else { // Debug.Log("timer countdown"); CoinsToInt(); timerCountdown.Stop(); timerType = 2; } isRunning = false; // Time.timeScale = 0; try { ///Save the stars level DataManager.WorldData currentWorldData = DataManager.FindWorldDataById(World.selectedWorld.ID, DataManager.filterdWorldsData); DataManager.LevelData currentLevelData = currentWorldData.FindLevelDataById(TableLevel.selectedLevel.ID); TotalData.LoadTotalFromFile(); // Debug.Log ("currentWorldData: " + currentWorldData); // Debug.Log ("currentLevelData: " + currentLevelData.ID); // Debug.Log("timerType: " + timerType); if (timerType == 1) { // Debug.Log("first"); // currentLevelData.leveltime = (int)timer.timeInSeconds; // Debug.Log ("currentLevelData.leveltime " + currentLevelData.leveltime); int currentTime = currentLevelData.leveltime; currentLevelData.leveltime = timer.timeInSeconds; if (currentTime == 0) { // if(currentLevelData.ID == 1){ // TotalData.totalData.laser = 3; // TotalData.totalData.green = 3; // TotalData.totalData.blue = 3; // TotalData.SaveTotalToFile(); // Debug.Log("done"); // } // Debug.Log("zero"); /// currentWorldData.Worldtime += timer.timeInSeconds; } // currentWorldData.Worldtime += currentTime; TotalData.totalData.totalTime += timer.timeInSeconds; // currentWorldData.Worldtime += currentLevelData.leveltime; // currentTotalData.totalTime += currentWorldData.Worldtime; if (currentTime > timer.timeInSeconds) { // Debug.Log("less"); currentLevelData.leveltime = timer.timeInSeconds; currentWorldData.Worldtime += timer.timeInSeconds; TotalData.totalData.totalTime -= (currentTime - timer.timeInSeconds); // currentWorldData.Worldtime -= (currentTime - timer.timeInSeconds); } TotalData.SaveTotalToFile(); // Debug.Log("currentTime: " + currentTime); // Debug.Log ("currentWorldData.Worldtime: " + currentWorldData.Worldtime); currentLevelData.levelScore = coins; // currentWorldData.worldScore += coins; // DataManager.SaveWorldsDataToFile (DataManager.); //TotalData.totalData.totalCoins = coins; // Debug.Log ("totaldata2: " + TotalData.totalData.totalCoins); // Debug.Log("currentTotalData.totalCoins: " + currentTotalData.totalCoins); //TotalData.SaveTotalToFile(); // Debug.Log("gamemanager: " + currentTotalData.totalCoins); // if (currentLevelData.starsLevel < TableLevel.StarsNumber.TWO){ // Debug.Log ("good thing"); // } //Calculate the stars rating if (timer.timeInSeconds >= 0 && timer.timeInSeconds <= threeStarsTimePeriod) { currentLevelData.starsLevel = TableLevel.StarsNumber.THREE; } else if (timer.timeInSeconds > threeStarsTimePeriod && timer.timeInSeconds <= twoStarsTimePeriod) { currentLevelData.starsLevel = TableLevel.StarsNumber.TWO; } else { currentLevelData.starsLevel = TableLevel.StarsNumber.ONE; } } else if (timerType == 2) { // Debug.Log("second"); // Debug.Log ("timerCountdown.timeInSeconds " + timerCountdown.timeInSeconds); // int currentScore = currentLevelData.leveltime; // currentWorldData.Worldtime += currentLevelData.leveltime; // if(currentLevelData.leveltime > timer.timeInSeconds || currentLevelData.leveltime == 0){ // currentLevelData.leveltime = timer.timeInSeconds; // currentWorldData.Worldtime -= timer.timeInSeconds; // } // currentLevelData.levelScore = coins; // if (currentLevelData.starsLevel < TableLevel.StarsNumber.TWO){ // Debug.Log ("good thing"); // } //Calculate the stars rating // Debug.Log ("test"); currentLevelData.levelScore = coins; currentWorldData.worldScore += coins; // TotalData.totalData.totalCoins += coins; // TotalData.SaveTotalToFile(); if (timerCountdown.timeInSeconds >= 0 && timerCountdown.timeInSeconds <= threeStarsTimePeriod) { currentLevelData.starsLevel = TableLevel.StarsNumber.THREE; } else if (timerCountdown.timeInSeconds > threeStarsTimePeriod && timerCountdown.timeInSeconds <= twoStarsTimePeriod) { currentLevelData.starsLevel = TableLevel.StarsNumber.TWO; } else { currentLevelData.starsLevel = TableLevel.StarsNumber.ONE; } } // Debug.Log ("test2"); // Debug.Log ("levelsdata.count " + currentWorldData.levelsData.Count); if (currentLevelData.ID + 1 <= currentWorldData.levelsData.Count) { // ///Unlock the next level // Debug.Log ("Unlock next level"); DataManager.LevelData nextLevelData = currentWorldData.FindLevelDataById(TableLevel.selectedLevel.ID + 1); // Debug.Log ("nextleveldata: " + nextLevelData); nextLevelData.isLocked = false; DataManager.SaveWorldsDataToFile(DataManager.filterdWorldsData); } if (currentLevelData.ID == currentWorldData.levelsData.Count) { // Debug.Log ("Last level: " + currentLevelData .ID); DataManager.WorldData nextWorldData = DataManager.FindWorldDataById(World.selectedWorld.ID + 1, DataManager.filterdWorldsData); nextWorldData.WorldIsLocked = false; // Debug.Log ("world " + nextWorldData.ID + nextWorldData.WorldIsLocked); } // Debug.Log ("test3"); DataManager.SaveWorldsDataToFile(DataManager.filterdWorldsData); TotalData.totalData.totalCoins += coins; // Debug.Log ("currentWorldData.Worldtime: " + currentWorldData.Worldtime); TotalData.SaveTotalToFile(); // for (int ID = 0; ID < 5; ID ++){ // int ID = 2; // Debug.Log("World_GameManger " + World.selectedWorld.ID + World.selectedWorld.WorldIsLocked); // } BlackArea2.Show(); WinDialogObj.gameObject.SetActive(true); winDialog.starsNumber = currentLevelData.starsLevel; winDialog.Show(); } catch (Exception ex) { Debug.Log(ex.Message); } // Debug.Log ("You win..."); Time.timeScale = 0; //AudioSource.PlayClipAtPoint(finishSFX,Vector3.zero); }
void Awake() { currentWorldData = DataManager.FindWorldDataById(World.selectedWorld.ID, DataManager.filterdWorldsData); //Get the current world currentLevelData = currentWorldData.FindLevelDataById(TableLevel.selectedLevel.ID); ///Get the current level levelNumber.text = "Level: " + currentWorldData.ID + "-" + currentLevelData.ID; }
/// <summary> /// Settings up the level contents in the table. /// </summary> /// <param name="tableLevel">Table level.</param> /// <param name="ID">ID of the level.</param> private void SettingUpLevel(TableLevel tableLevel, int ID) { if (tableLevel == null) { return; } ///Get World Data of the current World tempWorldData = DataManager.FindWorldDataById(World.selectedWorld.ID, DataManager.filterdWorldsData); // Debug.Log("tempworlddata0 " + World.selectedWorld.ID + ".." + DataManager.filterdWorldsData); // Debug.Log("tempworlddata " + World.selectedWorld.ID + tempWorldData + "..." + DataManager.filterdWorldsData); if (tempWorldData == null) { Debug.Log("Null WorldData"); return; } ///Get Level Data of the wanted (selected) Level tempLevelData = tempWorldData.FindLevelDataById(tableLevel.ID); if (tempLevelData == null) { Debug.Log("Null LevelData"); return; } // Debug.Log("tempLevelData " + tableLevel.ID + "..."+tempLevelData.isLocked + "...."+tempLevelData); /// Debug.Log("time for levels " + tempLevelData.leveltime); //If the level is locked then , skip the next if (tempLevelData.isLocked) { return; } //show summary time TotalData.LoadTotalFromFile(); // Debug.Log ("totaldata: " + TotalData.totalData.totalCoins); // Debug.Log("levelsTable: " + currentTotalData.totalTime) // sumTime = currentTotalData.totalTime; // Debug.Log ("Worldtime: " + TotalData.totalData.totalTime); // Debug.Log ("leveltime: " + tempLevelData.leveltime); // Debug.Log ("levelScore: " + tempLevelData.levelScore); // sumTime = TotalData.totalData.totalTime; // sumTime = tempWorldData.Worldtime; // sumTime += tempLevelData.leveltime; // time.text = ": " + currentTotalData.totalCoins.ToString(); time.text = ": " + TotalData.totalData.totalTime.ToString(); //show summary coins // sumCoins = sumCoins += tempLevelData.levelScore; coins.text = ": " + TotalData.totalData.totalCoins.ToString(); // Debug.Log ("data: " + TotalData.totalData.totalCoins); // Debug.Log ("laser: " + TotalData.totalData.laser); // Debug.Log ("time: " + tempLevelData.leveltime ); //Enable level animator tableLevel.GetComponent <Animator> ().enabled = true; ///Make the button interactable tableLevel.GetComponent <Button> ().interactable = true; ///Show the stars of the level tableLevel.transform.Find("Stars").gameObject.SetActive(true); ///Hide the lock tableLevel.transform.Find("Lock").gameObject.SetActive(false); tableLevel.transform.Find("Background").gameObject.SetActive(true); ///Show the title of the level tableLevel.transform.Find("LevelTitle").gameObject.SetActive(true); ///Setting up the level title tableLevel.transform.Find("LevelTitle").GetComponent <Text> ().text = ID.ToString(); ///Get stars Number from current Level Data tableLevel.starsNumber = tempLevelData.starsLevel; tempTransform = tableLevel.transform.Find("Stars"); ///Apply the current Stars Rating if (tempLevelData.starsLevel == TableLevel.StarsNumber.ONE) //One Star { tempTransform.Find("FirstStar").GetComponent <Image> ().sprite = starOn; tempTransform.Find("SecondStar").GetComponent <Image> ().sprite = starOff; tempTransform.Find("ThirdStar").GetComponent <Image> ().sprite = starOff; } else if (tempLevelData.starsLevel == TableLevel.StarsNumber.TWO) //Two Stars { tempTransform.Find("FirstStar").GetComponent <Image> ().sprite = starOn; tempTransform.Find("SecondStar").GetComponent <Image> ().sprite = starOn; tempTransform.Find("ThirdStar").GetComponent <Image> ().sprite = starOff; } else if (tempLevelData.starsLevel == TableLevel.StarsNumber.THREE) //Three Stars { tempTransform.Find("FirstStar").GetComponent <Image> ().sprite = starOn; tempTransform.Find("SecondStar").GetComponent <Image> ().sprite = starOn; tempTransform.Find("ThirdStar").GetComponent <Image> ().sprite = starOn; } else //Zero Stars { tempTransform.Find("FirstStar").GetComponent <Image> ().sprite = starOff; tempTransform.Find("SecondStar").GetComponent <Image> ().sprite = starOff; tempTransform.Find("ThirdStar").GetComponent <Image> ().sprite = starOff; } }
/// <summary> /// Settings up the level contents in the table. /// </summary> /// <param name="tableLevel">Table level.</param> /// <param name="ID">ID of the level.</param> private void SettingUpLevel (TableLevel tableLevel, int ID) { if (tableLevel == null) { return; } ///Get Mission Data of the current Mission tempMissionData = DataManager.FindMissionDataById (Mission.wantedMission.ID, DataManager.instance.filterdMissionsData); if (tempMissionData == null) { Debug.Log ("Null MissionData"); return; } ///Get Level Data of the wanted (selected) Level tempLevelData = tempMissionData.FindLevelDataById (tableLevel.ID); if (tempLevelData == null) { Debug.Log ("Null LevelData"); return; } //If the level is locked then , skip the next if (tempLevelData.isLocked) { return; } ///Make the button interactable tableLevel.GetComponent<Button> ().interactable = true; ///Show the stars of the level tableLevel.transform.Find ("Stars").gameObject.SetActive (true); ///Hide the lock tableLevel.transform.Find ("Lock").gameObject.SetActive (false); ///Show the title of the level tableLevel.transform.Find ("LevelTitle").gameObject.SetActive (true); ///Setting up the level title tableLevel.transform.Find ("LevelTitle").GetComponent<Text> ().text = ID.ToString (); ///Get stars Number from current Level Data tableLevel.starsNumber = tempLevelData.starsNumber; tempTransform = tableLevel.transform.Find ("Stars"); ///Apply the current Stars Rating if (tempLevelData.starsNumber == TableLevel.StarsNumber.ONE) {//One Star tempTransform.Find ("FirstStar").GetComponent<Image> ().sprite = starOn; tempTransform.Find ("SecondStar").GetComponent<Image> ().sprite = starOff; tempTransform.Find ("ThirdStar").GetComponent<Image> ().sprite = starOff; } else if (tempLevelData.starsNumber == TableLevel.StarsNumber.TWO) {//Two Stars tempTransform.Find ("FirstStar").GetComponent<Image> ().sprite = starOn; tempTransform.Find ("SecondStar").GetComponent<Image> ().sprite = starOn; tempTransform.Find ("ThirdStar").GetComponent<Image> ().sprite = starOff; } else if (tempLevelData.starsNumber == TableLevel.StarsNumber.THREE) {//Three Stars tempTransform.Find ("FirstStar").GetComponent<Image> ().sprite = starOn; tempTransform.Find ("SecondStar").GetComponent<Image> ().sprite = starOn; tempTransform.Find ("ThirdStar").GetComponent<Image> ().sprite = starOn; } else {//Zero Stars tempTransform.Find ("FirstStar").GetComponent<Image> ().sprite = starOff; tempTransform.Find ("SecondStar").GetComponent<Image> ().sprite = starOff; tempTransform.Find ("ThirdStar").GetComponent<Image> ().sprite = starOff; } }