コード例 #1
0
ファイル: GameManager.cs プロジェクト: Maareks/Endless-Cat
        public void UpgradePowerUp(PowerUpTypes powerUpType)
        {
            // Can't upgrade if the player can't afford the power up
            int cost = dataManager.GetPowerUpCost(powerUpType);

            if (dataManager.GetTotalCoins(true) < cost)
            {
                return;
            }
            dataManager.UpgradePowerUp(powerUpType);
            dataManager.AdjustTotalCoins(-cost, true);
        }
コード例 #2
0
ファイル: GUIManager.cs プロジェクト: Maareks/Endless-Cat
        public void ShowGUI(GUIState state)
        {
            screenTouch.SetActive(false);

            switch (state)
            {
            case GUIState.InGame:

                screenTouch.SetActive(true);

                if (tutorialShown)
                {
                    tutorialPanel.SetActive(true);
                }
#if !(UNITY_4_3 || UNITY_4_4 || UNITY_4_5)
                if (useuGUI)
                {
                    inGameActivePowerUpImage.gameObject.SetActive(powerUpActive);
                    EventSystem.current.SetSelectedGameObject(null);
                }
                else
                {
#endif
#if COMPILE_NGUI
                inGameActivePowerUp.gameObject.SetActive(powerUpActive);
#endif
#if !(UNITY_4_3 || UNITY_4_4 || UNITY_4_5)
            }
#endif
                break;

            case GUIState.EndGame:
#if !(UNITY_4_3 || UNITY_4_4 || UNITY_4_5)
                if (useuGUI)
                {
                    endGameScoreText.text      = dataManager.GetScore(true).ToString();
                    endGameCoinsText.text      = dataManager.GetLevelCoins(true).ToString();
                    endGameMultiplierText.text = string.Format("{0}x", missionManager.GetScoreMultiplier());
                }
                else
                {
#endif
#if COMPILE_NGUI
                endGameScore.text      = dataManager.GetScore(true).ToString();
                endGameCoins.text      = dataManager.GetLevelCoins(true).ToString();
                endGameMultiplier.text = string.Format("{0}x", missionManager.GetScoreMultiplier());
#endif
#if !(UNITY_4_3 || UNITY_4_4 || UNITY_4_5)
            }
#endif

                // only need to show the animation if we are coming from in game or revive
                if (guiState == GUIState.InGame || guiState == GUIState.Revive)
                {
                    endGamePanel.SetActive(true);

                    endGamePlayAnimation.enabled = true;
                    endGamePlayAnimation.Stop();
#if !(UNITY_4_3 || UNITY_4_4 || UNITY_4_5)
                    if (useuGUI)
                    {
                        endGamePlayAnimation[endGamePlayAnimationName].speed = -1;
                        endGamePlayAnimation[endGamePlayAnimationName].time  = endGamePlayAnimation[endGamePlayAnimationName].length;
                    }
                    else
                    {
#endif
#if COMPILE_NGUI
                    endGamePlayAnimation[endGamePlayAnimationName].speed = 1;
#endif
#if !(UNITY_4_3 || UNITY_4_4 || UNITY_4_5)
                }
#endif
                    endGamePlayAnimation.Play(endGamePlayAnimationName);
                    for (int i = 0; i < inGamePlayAnimation.Length; ++i)
                    {
                        inGamePlayAnimation[i].Stop();
                        inGamePlayAnimation[i][inGamePlayAnimationName].speed = 1;
                        inGamePlayAnimation[i].enabled = true;
                        inGamePlayAnimation[i].Play(inGamePlayAnimationName);
                    }
#if COMPILE_NGUI
                    // NGUI 2 uses UIButtonPlayAnimation. NGUI 3 uses UIPlayAnimation. When the NGUI 3 version of the play animation activates it automatically disables
                    // the animation component. We don't want that so we are just going to disable the NGUI component.
                    System.Type playAnimationType = System.Type.GetType("UIPlayAnimation, Assembly-CSharp");
                    if (playAnimationType != null)
                    {
                        var playAnimations = endGamePanel.GetComponentsInChildren(playAnimationType);
                        for (int i = 0; i < playAnimations.Length; ++i)
                        {
                            ((MonoBehaviour)playAnimations[i]).enabled = false;
                        }
                        // enable the buttons again after the animation is done playing
                        StartCoroutine(EnableComponents(endGamePlayAnimation[endGamePlayAnimationName].length, playAnimations));
                    }
#endif
                }
                break;

            case GUIState.Store:
                // go back to the correct menu that we came from
                if (guiState == GUIState.MainMenu)
                {
                    storeBackToEndGameButton.SetActive(false);
                    storeBackToMainMenuButton.SetActive(true);
                }
                else if (guiState == GUIState.EndGame)
                {
                    storeBackToMainMenuButton.SetActive(false);
                    storeBackToEndGameButton.SetActive(true);
                }
                storeSelectingPowerUp = false;
                storeItemIndex        = dataManager.GetSelectedCharacter();
                RefreshStoreGUI();
                RefreshStoreItem();
                break;

            case GUIState.Pause:
                if (tutorialShown)
                {
                    tutorialPanel.SetActive(false);
                }
                if (inGameMissionsPanel.activeSelf)
                {
                    // speed up the animation so the panel will disappear quicker
                    inGameMissionsPlayAnimation[inGameMissionsPlayAnimationName].speed = 2;
                }
#if !(UNITY_4_3 || UNITY_4_4 || UNITY_4_5)
                if (useuGUI)
                {
                    pauseScoreText.text          = dataManager.GetScore().ToString();
                    pauseCoinsText.text          = (dataManager.GetLevelCoins(true) + coinGUICollection.GetAnimatingCoins()).ToString();
                    pauseSecondaryCoinsText.text = dataManager.GetLevelCoins(false).ToString();
                }
                else
                {
#endif
#if COMPILE_NGUI
                pauseScore.text          = dataManager.GetScore().ToString();
                pauseCoins.text          = (dataManager.GetLevelCoins(true) + coinGUICollection.GetAnimatingCoins()).ToString();
                pauseSecondaryCoins.text = dataManager.GetLevelCoins(false).ToString();
#endif
#if !(UNITY_4_3 || UNITY_4_4 || UNITY_4_5)
            }
#endif
                break;

            case GUIState.Stats:
#if !(UNITY_4_3 || UNITY_4_4 || UNITY_4_5)
                if (useuGUI)
                {
                    statsHighScoreText.text      = dataManager.GetHighScore().ToString();
                    statsCoinsText.text          = dataManager.GetTotalCoins(true).ToString();
                    statsSecondaryCoinsText.text = dataManager.GetTotalCoins(false).ToString();
                    statsPlayCountText.text      = dataManager.GetPlayCount().ToString();
                }
                else
                {
#endif
#if COMPILE_NGUI
                statsHighScore.text      = dataManager.GetHighScore().ToString();
                statsCoins.text          = dataManager.GetTotalCoins(true).ToString();
                statsSecondaryCoins.text = dataManager.GetTotalCoins(false).ToString();
                statsPlayCount.text      = dataManager.GetPlayCount().ToString();
#endif
#if !(UNITY_4_3 || UNITY_4_4 || UNITY_4_5)
            }
#endif
                break;

            case GUIState.Missions:
                if (guiState == GUIState.MainMenu)
                {
                    missionsBackToEndGameButton.SetActive(false);
                    missionsBackToMainMenuButton.SetActive(true);
                }
                else         // coming from GUIState.EndGame
                {
                    missionsBackToMainMenuButton.SetActive(false);
                    missionsBackToEndGameButton.SetActive(true);
                }
#if !(UNITY_4_3 || UNITY_4_4 || UNITY_4_5)
                if (useuGUI)
                {
                    missionsScoreMultiplierText.text = string.Format("{0}x", missionManager.GetScoreMultiplier());
                    missionsActiveMission1Text.text  = dataManager.GetMissionDescription(missionManager.GetMission(0));
                    missionsActiveMission2Text.text  = dataManager.GetMissionDescription(missionManager.GetMission(1));
                    missionsActiveMission3Text.text  = dataManager.GetMissionDescription(missionManager.GetMission(2));
                }
                else
                {
#endif
#if COMPILE_NGUI
                missionsScoreMultiplier.text = string.Format("{0}x", missionManager.GetScoreMultiplier());
                missionsActiveMission1.text  = dataManager.GetMissionDescription(missionManager.GetMission(0));
                missionsActiveMission2.text  = dataManager.GetMissionDescription(missionManager.GetMission(1));
                missionsActiveMission3.text  = dataManager.GetMissionDescription(missionManager.GetMission(2));
#endif
#if !(UNITY_4_3 || UNITY_4_4 || UNITY_4_5)
            }
#endif
                break;

            case GUIState.Revive:
                revivePanel.SetActive(true);
#if !(UNITY_4_3 || UNITY_4_4 || UNITY_4_5)
                if (useuGUI)
                {
                    reviveDescriptionText.text = "Do you want to use " + dataManager.GetReviveCost() + " diamonds to revive?\n\nYou have " + (dataManager.GetTotalCoins(false) + dataManager.GetLevelCoins(false)).ToString() + " diamonds.";
                }
                else
                {
#endif
#if COMPILE_NGUI
                reviveDescription.text = "Do you want to use " + dataManager.GetReviveCost() + " diamonds to revive?\n\nYou have " + (dataManager.GetTotalCoins(false) + dataManager.GetLevelCoins(false)).ToString() + " diamonds.";

                // Deactivate the yes animation if the player doesn't have enough coins. NGUI3 automatically starts with it deactivated
                if (!dataManager.CanPurchaseRevive())
                {
                    System.Type animationType = System.Type.GetType("UIButtonPlayAnimation, Assembly-CSharp");
                    if (animationType != null)
                    {
                        var playAnimation = reviveYesButton.GetComponent(animationType);
                        ((MonoBehaviour)playAnimation).enabled = false;
                    }
                }
#endif
#if !(UNITY_4_3 || UNITY_4_4 || UNITY_4_5)
            }
#endif
                revivePlayAnimation.enabled = true;
                revivePlayAnimation.Stop();
                revivePlayAnimation[revivePlayAnimationName].speed = 1;
                revivePlayAnimation.Play(revivePlayAnimationName);
                break;
            }

            guiState = state;
        }