跳至主要内容

[3D跑酷] AudioManager

Unity音频管理

游戏中的声音管理最常用的组件莫过于AudioSource和AudioClip,我的做法是建立是一个AudioManager类(单例类)管理各个音频,谈一下我的经验:

函数列表

Start函数:设置音频整体参数;
image

编辑器面板

拖拽文件赋值
image

AudioSource文档

image

逻辑实现代码

 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;//音调
        soundEffectsAudio.clip = clip;//
        soundEffectsAudio.Play();
    }

评论

此博客中的热门博文

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...