Пример #1
0
    // Show the UI for the gameover
    public void EndGameRPC(Team winningTeam)
    {
        // Stop timer
        Timer.roundTimer.End();

        // Show endgame UI
        taskCompletionUI.UpdateBar();
        timerCountdown.Stop();
        deathUI.gameObject.SetActive(false);
        gameOverUI.OnGameOver(winningTeam);

        // Unlock mouse
        Cursor.lockState = CursorLockMode.None;
        Cursor.visible   = true;

        // Stop the player from being able to move (so mouse movement only
        // affects the mouse in the UI)
        NetworkManager.instance.GetMe().Freeze();

        // After a game has ended people can join the room again
        PhotonNetwork.CurrentRoom.IsVisible = true;
    }
Пример #2
0
    /// <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);
    }