//后一关 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> /// 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> /// 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; } }