[3D跑酷] MissionManager

前端之家收集整理的这篇文章主要介绍了[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的属性方法

image

image

    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

原文链接:/unity/995669.html

猜你在找的Unity相关文章