[3D跑酷] MissionManager

前言

许久没有更新日志了,之前写了GUIManager,GUIClickEventReceiver还有AudioManager,这次写MissionManager

引用关系

首先看下MissionManager在项目中的引用关系image

解释一下引用关系:

MissionManager是一个单例类,类中定义了和任务相关的属性的方法,其它类中通过单例引用MissionManager中的方法

GameManager

public void gameOver (GameOverType gameOverType, bool waitForFrame)
   {
        missionManager.gameOver (); 
   }
再来查看MissionManager中的GameOver()
    public void gameOver()
    {
        checkForCompletedMissions();
    }

这里的逻辑是,在GameOver的时候检查MissionManager中的任务是否完成

DataManager

public int getScore ()
   {
        return Mathf.RoundToInt (score * missionManager.getScoreMultiplier ());    
    }

DataManager中 获取玩家得分  MissionManager中的倍率*Score=玩家最后的得分

 

GUIManager

    public void showGUI (GUIState state)
    {
        // activate the new gui state, deactivate the old.
        changeGUIState (true, state);
        changeGUIState (false, guiState);
     
        switch (state) {
        case GUIState.EndGame:
            endGameScore.text = dataManager.getScore ().ToString ()+"M";
            endGameCoins.text = dataManager.getLevelCoins ().ToString ();
            endGameHighScore.text=dataManager.getHighScore().ToString()+"M";
            endGameMultiplier.text = string.Format ("{0}x", missionManager.getScoreMultiplier ());
       break;
       case GUIState.Missions:
            if (guiState == GUIState.MainMenu) {
                missionsBackButtonReceiver.clickType = ClickType.MainMenu;
            } else { // coming from GUIState.EndGame
                missionsBackButtonReceiver.clickType = ClickType.EndGame;
            }
            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));

            break;
    }
可以看到在GUIManager中,当UI切换到任务界面时,显示在界面上的数据大多与MissionManager中的属性或方法相关

任务系统 (MissionManager)

MissionManager的属性和方法

imageimage
    public void Start()
    {
        dataManager = DataManager.instance;

        activeMissions = new MissionType[3]; // 3 active missions at a time
        scoreMultiplier = 1;
        for (int i = 0; i < activeMissions.Length; ++i) {
            activeMissions[i] = (MissionType)PlayerPrefs.GetInt(string.Format("Mission{0}", i), -1);
            // there are no active missions if the game hasn't been started yet
            if ((int)activeMissions[i] == -1) {
                activeMissions[i] = (MissionType)(i * 4); // 4 missions per set
            }
            scoreMultiplier += ((int)activeMissions[i] % 4) * scoreMultiplierIncrement;
        }
    }

//检测任务是否完成  
 private void checkForCompletedMissions()
    {
        for (int i = 0; i < activeMissions.Length; ++i) {
            switch (activeMissions[i]) {
                case MissionType.NoviceRunner:
                    if (dataManager.getScore() > 500) {
                        missionComplete(MissionType.NoviceRunner);
                    }
                    break;    
             ......
             }
           }
      }

//任务完成   
 private void missionComplete(MissionType missionType)
    {
        int missionSet = (int)missionType / 4;
        activeMissions[missionSet] = missionType + 1;
        scoreMultiplier += scoreMultiplierIncrement;
        PlayerPrefs.SetInt(string.Format("Mission{0}", missionSet), (int)activeMissions[missionSet]);
    }

设计思想

image

image

posted @ 2014-01-13 17:45  赵青青  阅读(407)  评论(0编辑  收藏  举报