跳至主要内容

[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

评论

此博客中的热门博文

[3D跑酷] AudioManager

Unity音频管理 游戏中的声音管理最常用的组件莫过于AudioSource和AudioClip,我的做法是建立是一个AudioManager类(单例类)管理各个音频,谈一下我的经验: 函数列表 Start函数:设置音频整体参数; 编辑器面板 拖拽文件赋值 AudioSource文档 逻辑实现代码 public void playSoundEffect(SoundEffects soundEffect) { AudioClip clip = null ; float pitch = 1; switch (soundEffect) { case SoundEffects.ObstacleCollisionSoundEffect: clip = obstacleCollision; break ; case SoundEffects.CoinSoundEffect: clip = coinCollection; pitch = 1.5f; break ; case SoundEffects.PowerUpSoundEffect: clip = powerUpCollection; break ; case SoundEffects.GameOverSoundEffect: clip = gameOver; break ; case SoundEffects.GUITapSoundEffect: clip = guiTap; break ; } soundEffectsAudio.pitch = pitch; //音调 so...

jnyy

[3D跑酷] GUIManager UI管理

UI元素更新及界面跳转 继上篇日志《Unity开发之 GUIClickEventReceiver》,再谈一下我们如何管理游戏中的UI元素更新及界面跳转 UI绑定 图一:Inspector面板 Public GameObjectName与GameObject一一对应 UI结构及命名规范 图二:Hierarchy面板 UI父子结构及组件命名规范 UI枚举种类 图三:enum GUIState UI绑定代码 图四:public UI控件定义 与Hierarchy命名规范 UI主要方法及逻辑 图五:主要方法及逻辑 主要方法 1、隐藏Transform及子Transform #if !UNITY_3_5 private void activeRecursively(Transform obj, bool active) { foreach (Transform child in obj) { activeRecursively(child, active); } obj.gameObject.SetActive(active); } #endif private GameObject panelFromState(GUIState state) { switch (state) { case GUIState.MainMenu: return mainMenuPanel; case GUIState.InGame: return inGamePanel; case GUIState.EndGame: return endGamePanel; case GUIState.Store: return storePanel; case GUIState.Stats: return statsPanel; case GUISt...