当前位置:网站首页>【Unity开发小技巧】Unity混音器Mixer控制全局音量
【Unity开发小技巧】Unity混音器Mixer控制全局音量
2022-07-17 00:14:00 【幻世界】
目录
1.创建MasterMixer,MusicMixer,soundEffectMixer
一:前言
从业多年一直没用过这个混音器工具,毕竟很很多功能都是尽可能的自己写代码控制,这样后期维护和修改都会很容易,最近有学生在咨询声音管理系统,特别是这个混音器怎么使用。趁这次机会赶紧去了解学习了一下,在此记录。这里只记录用混音器统一控制属性,其他的音频资源管理模块这里不涉及,以后有时间单独记录。
二:控制逻辑
我们常用的游戏音频类型主要还是分为三个种类:1.Music背景音乐(一直存在的)2.瞬时音效(即时生成)3.剧情配音(也可以归类于音效)。正常使用代码管理控制这些音效的时候,特别是对声音音量的管理设置,都是先分类管理再全部遍历然后设置音量,这种虽然说麻烦但是优点在于方便我们维护修改,另外一种就是把音量的控制逻辑或者其他的属性控制剥离出来交给混音器处理其实也很方便。这里我的思路是创建三个混音器一个全局Mixer,一个MusicMixer和一个SoundEffectMixer,其中全局的只对MusicMixer和SoundEffectMixer进行管理,然后具体的声音分别归SoundEffectMixer和MusicMixer管理。简单的话也可以直接做一个Mixer直接对音乐进行管理

三:制作混音器Mixer
1.创建MasterMixer,MusicMixer,soundEffectMixer
鼠标右键创建混音器,修改名字为MasterMixer..,另外两个可以点击Mixers后面的加号创建也可以在外面右键创建。


2.设置父子级关系
1..点击加号创建music和sound

2.把music和sound拖到master的子节点下面。并关联对应的Group下面的节点

3.设置对应AudioSource
分别选中场景里的音乐,然后把对MasterMixer下对应的类型拖拽进音乐的Output槽内


4.暴漏属性
1.选中Mastermixer,2.再选中目标Mixer 3.找到右边Volume属性 4.在Volume上右键暴漏属性 5.修改属性名字f2

三个Mixer都要暴漏出来

四:编辑代码控制
public class Test : MonoBehaviour
{
public AudioMixer audioMixer;//MasterMixer
public AudioSource soundClick;//sound
public void SetAllVolume(Slider s)
{
audioMixer.SetFloat("MasterVolume", s.value);
}
public void SetMusicVolume(Slider s)
{
audioMixer.SetFloat("MusicVolume", s.value);
}
public void SetEffectVolume(Slider s)
{
audioMixer.SetFloat("EffectVolume", s.value);
}
private void Update()
{
if (Input.GetKeyDown(KeyCode.P))
{
soundClick.Play();
}
}
}五:Slider滑动条设置
1.根据混音器内音量的最大最小值设置slider的最大最小值[-40,0]
2.添加事件

完结撒花
边栏推荐
- 搭建Hue环境
- VIM profile
- 成信大ENVI_IDL第三周课堂内容1:读取OMI数据(HDF5文件)以及输出+解析
- ENVI_IDL:批量拼接Modis Swath的逐日数据并输出为Geotiff格式
- STL--vector容器
- 02 design of smart home system based on ZigBee
- DGC best practice: how to ensure that confidential data is not leaked when entering the lake?
- 软件测试技术期中测试小结|软件测试基础&执行测试&测试设计和开发
- How to understand volatile and how to use it
- Prohibit smart Safari from playing automatically when opening a web page
猜你喜欢

SAE j1708/j1587 protocol details

成信大ENVI_IDL第二周实验内容:提取所有MODIS气溶胶产品中AOD+详细解析

ENVI_IDL:讀取所有OMI產品的NO2柱含量並計算月均值、季均值、年均值+解析

笔记一之IDL基础内容:常用数据类型_创建数组_类型转换_print输出_基本运算_关系运算

04 design of indoor wireless positioning system based on ZigBee

Cookie和Session的区别

【Unity编辑器扩展】显示资源目录下所有文件所占内存大小

Basic principle and parameter interpretation of operational amplifier

池式组件之线程池篇

On the properties and methods of list < t >
随机推荐
搭建Sqoop环境
Dueling DQN的理论基础及其代码实现【Pytorch + Pendulum-v0】
工程编译那点事:Makefile和cmake(一)
Gdb+vscode for debugging 1 -- compile and debug using cmakelist files + attach process debugging
The code of dsaa related articles in the blog
【HDRP高清渲染管道】创建HDRP工程,把内置管线工程升级为HDRP工程
LeetCode:动态规划【基础题目求解】
STL--deque容器
Gdb+vscode for debugging 5 - GDB view relevant commands
Hue oozie editor scheduling shell
gdb+vscode进行调试3——vscode以及gdb远程调试
Build Ozzie environment
Labelme 的简单用法和界面介绍
动态规划 - 01背包问题
ENVI_ Idl: read the NO2 column content of all OMI products and calculate the monthly average, quarterly average, annual average + analysis
Characteristics and application points of electrolytic capacitor
ENVI_ Idl: read the text file and output it in GeoTIFF format + simple mean interpolation
Compilation and link of C language program
ENVI_IDL:批量重投影Modis Swath产品并指定范围输出为Geotiff格式+解析
leetcode力扣经典题目——82.柱形图中的最大矩形
