怎么在unity中unity 播放音频mp3格式的外部音频

你的浏览器禁用了JavaScript, 请开启后刷新浏览器获得更好的体验!
unity 录音通过
Microphone.Start(null, false, recordLength, frequency);
来录音. 但是好像并没有设置录音的格式....
返回的AudioClip 也没有设置格式的参数....在编辑上倒是看到后format 的选项....但是代码里面没有....
究竟怎么设置录音的格式呢??? 比如wav格式.....
有两种解决方式,一种是不用Unity提供的接口,网上很多C++封装实现的,可以将其做成dll文件,unity去调用其接口录音,二是使用unity提供的接口返回ogg格式就可以。你添加wav头数据需要在其保存流文件之前去加入,不赞成这么做。容易破坏其格式。
Microphone.Start 这个好像就是声音采集,至于你要保存成什么格式,应该是需要你自己转的,比如保存成wav,你就得给.wav文件添加头部数据等等,这个你可以去网上搜一下(wav格式),应该有很多。
楼主,噪音问题解决了么 ,能分享下解决的方案么。。
要回复问题请先或
浏览: 2669
关注: 4 人包含5节视频教程
关注5.1万次
本系列包含Unity3D介绍、Unity3D导出人物、Unity3D导出场景、Unity3D导出动作、游戏测试最终完成一个简单的游戏。是一套非常完整的Unity3D游戏制作教程。
Unity组件:Audio Source 音频源
关注:1252 留言:0 楼主: 发帖时间:15年11月16日
积分 70登陆 1发帖 6作品 1
The Audio Source plays back an Audio Clip in the scene. If the Audio Clip is a 3D clip, the source is played back
at a given position and will attenuate over distance. The audio can be
spread out between speakers (stereo to 7.1) (Spread) and morphed between 3D and 2D (PanLevel). This can be controlled over distance with falloff curves. Also, if the listener is within 1 or multiple Reverb Zones,
reverberations is applied to the source. (PRO only) Individual filters
can be applied to each audio source for an even richer audio experience.
See Audio Effects for more details.
音频源(Audio Source)在场景中播放音频剪辑(Audio Clip)。如果音频剪辑(Audio Clip)是一个3D剪辑,音频源是在一个给定的位置,并会随距离衰减这样的方式进行播放。音频可以在扬声器之间传播(立体声至7.1)(扩散Spread)和可以在3D和2D(平衡调整级别PanLevel)之间进行转换。这是可以控制的随距离衰减曲线。此外,如果侦听器是在1个或多个混响区中,回响将会应用到音频源。&(只专业版可用)单独的过滤器可以应用到每个音频源,可以得到更丰富的音频体验。更多细节请参阅音频效果(Audio Effects)。
The Audio Source gizmo in the Scene View and its settings in the inspector.
音频源在场景视图中gizmo 和 它在检视面板中的设置
Properties 属性
Audio Clip 音频剪辑
Reference to the sound clip file that will be played.
将被播放的声音剪辑文件
If enabled the sound will be playing but muted.
如果启用,声音将被播放,但没有声音(静音)
Bypass Effects 直通效果
This Is to quickly "by-pass" filter effects applied to the audio source. An easy way to turn all effects on/off.
应用到音频源的快速"直通"过滤效果。一个简单的方法来打开/关闭所有特效。
Play On Awake
唤醒时播放
If enabled, the sound will start playing the moment the scene launches. If disabled, you need to start it using the Play() command from scripting.
如果启用,则声音会在场景启动的时候开始播放。如果禁用,则需要从脚本中使用的play()命令来启动它。
Enable this to make the Audio Clip loop when it reaches the end.
启用这个属性使音频剪辑(Audio Clip)在播放结束后循环 。
Determines the priority of this audio source among all the ones that coexist in the scene. (Priority: 0 = most important. 256 = least important. Default = 128.). Use 0 for music tracks to avoid it getting occasionally swapped out.
确定场景所有并存的音频源之间的优先权。(0=最重要的优先权。256 =最不重要。默认为128。)。使用0的音乐曲目,以避免偶尔换出。
Volume 音量
How loud the sound is at a distance of 1 world unit (1 meter) from the Audio Listener.
声音从距离音频监听器(Audio Listener)1个世界单位(1米)处有多响?
Pitch 音调
Amount of change in pitch due to slowdown/speed up of the Audio Clip. Value 1 is normal playback speed.
改变音调(Pitch)值,可以减速/加速音频剪辑的播放。1是正常播放速度。
3D Sound Settings
3D声音设置
Settings that are applied to the audio source if the is a 3D Sound.
如果是一个三维的声音,应用到音频源的设置
平衡调整级别
Sets how much the 3d engine has an effect on the audio source.
设置多少,3D引擎在音频源上有效果。
Spread 扩散
Sets the spread angle to 3d stereo or multichannel sound in speaker space.
设置3D立体声或者多声道音响在扬声器空间的传播角度。
Doppler Level
多普勒级别
Determines how much doppler effect will be applied to this audio source (if is set to 0, then no effect is applied).
决定了多少多普勒效应将被应用到这个音频信号源(如果设置为0,就是无效果)。
Min Distance
Within the MinDistance, the sound will stay at loudest possible. Outside MinDistance it will begin to attenuate. Increase the MinDistance of a sound to make it 'louder' in a 3d world, and decrease it to make it 'quieter' in a 3d world.
在最小距离(MinDistance)之内,声音会保持最响亮。&在最小距离(MinDistance)之外,声音就会开始衰减。增加声音的最小距离(MinDistance),可以使声音在3D世界"更响亮",减少最小距离(MinDistance)可使声音在一个三维世界"安静"。
Max Distance
The distance where the sound stops attenuating at. Beyond this point it will stay at the volume it would be at MaxDistance units from the listener and will not attenuate any more.
声音停止衰减距离。超过这一点,它将在距离侦听器最大距离(MaxDistance)单位,保持音量,并不会作任何衰减。
Rolloff Mode
How fast the sound fades. The higher the value, the closer the Listener has to be before hearing the sound.(This is determined by a Graph).
声音淡出的速度有多快。该值越高,越接近侦听器最先听到声音(这是由图形决定)。
&&&&Logarithmic Rolloff
&&&&对数衰减
The sound is loud when you are close to the audio source, but when you get away from the object it decreases significantly fast.
当你接近的音频源,声音响亮,但是当你远离对象,声音下降显着快。
&&&&Linear Rolloff
&&&&线性衰减
The more far away from the audio source you go, the less you can hear it.
越是远离音频源的,你可以听到的声音越小。
&&&&Custom Rolloff
&&&&自定义衰减
The sound from the audio source behaves accordingly to how you set the graph of roll offs.
根据你设置的衰减图形,来自音频源的声音行为。
2D Sound Settings
2D声音设置
Settings that are applied to the audio source if the is a 3D Sound.
如果是一个二维的声音,应用到音频源的设置
2D平衡调整
Sets how much the engine has an effect on the audio source.
设置多少,引擎在音频源上有效果。
Types of Rolloff 衰减类型
There are three Rolloff modes: Logarithmic, Linear and Custom
Rolloff. The Custom Rolloff can be modified by modifying the volume
distance curve as described below. If you try to modify the volume
distance function when it is set to Logarithmic or Linear, the type will
automatically change to Custom Rolloff.
衰减模式有三种:对数,线性和自定义衰减。自定义衰减可以修改通过修改音量的距离曲线,如下所述。当它被设置为对数或线性类型时,如果你修改音量距离函数,类型将自动更改为自定义衰减。
Rolloff Modes that an audio source can have. 音频源的衰减模式
Distance Functions 距离函数
There are several properties of the audio that can be modified as a
function of the distance between the audio source and the audio
有音频的几个的属性,作为 音频源和音频侦听器之间的距离的函数,可以被修改。
Volume: Amplitude(0.0 - 1.0) over distance. 音量:幅度(0.0-1.0)随距离
Pan: Left(-1.0) to Right(1.0) over distance. 平衡调整: 左(-1.0)到右(1.0)随距离
Spread: Angle (degrees 0.0 - 360.0) over distance. 扩散:角度(0.0到360.0度)随距离
Low-Pass (only if LowPassFilter is attached to the AudioSource): Cutoff Frequency (.0) over distance.
低通(只有当低通滤波器(LowPassFilter)贴到音频源(AudioSource)上): 低通截止频率(10.0~22000.0hz)随距离。
functions for Volume, Pan, Spread and Low-Pass audio filter. The
current distance to the Audio Listener is marked in the graph.
音量,平衡调整,扩散和低通音频滤波器的距离函数。当前到音频监侦听器的距离在图中标记。
To modify the distance functions, you can edit the curves directly. For more information, see the guide to Editing Curves.
要修改的距离函数,您可以直接编辑曲线。想了解更多信息,请参阅编辑曲线(Editing Curves)的指南。
Creating Audio Sources 创建音频源
Audio Sources don't do anything without an assigned Audio Clip.
The Clip is the actual sound file that will be played back.
Source is like a controller for starting and stopping playback of that
clip, and modifying other audio properties.
没有分配音频剪辑的音频源不会播放任何东西。剪辑是实际的声音文件,该文件将被播放。音频源就像是一个控制器,用于启动和停止播放该剪辑,并修改其他的音频属性。
To create a new Audio Source 创建一个新的音频源:
Import your audio files into your Unity Project.
These are now Audio Clips.
导入你的音频文件到Unity项目。这些都是现在的音频剪辑。
Go to GameObject-&Create Empty from the menubar.
从菜单栏选择 GameObject-&Create Empty
With the new GameObject selected, select Component-&Audio-&Audio Source.
随着新的游戏对象(GameObject) 被选择,选择&Component-&Audio-&Audio Source
Assign the Audio Clip property of the Audio Source Component in the Inspector.
在检视面板中分配音频源 (Audio Source)组件的音频剪辑属性。
Note: If you want to create an audio source just for one Audio Clip that you have in the Assets folder, you can drag and drop that Audio Clip to the scene view and an Audio Source game object will be created automatically for it.
注意:如果你想创建一个音频源,只需有一个音频剪辑(Audio Clip)在你的资源文件夹,你可以拖拽音频剪辑(Audio Clip)到场景视图,那么带有音频源(Audio Source)的游戏对象将自动创建。
Platform specific details 平台的具体细节
On mobile platforms compressed audio is encoded as MP3 for speedier
decompression. Beware that this compression can remove samples at the
end of the clip and potentially break a "perfect-looping" clip. Make
sure the clip is right on a specific MP3 sample boundary to avoid sample
clipping (Tools to perform this is widely available).
For performance reasons audio clips can be played back using the Apple
hardware codec. To enable this check the "Use Hardware" checkbox in the
import settings. See the Audio Clip documentation for more details.
在移动平台上的压缩音频以MP3格式编码为了能快捷解压。要注意,这种压缩是可以删除剪辑结尾的样品,并可能打破一个"完美循环"的剪辑。确保剪辑是正确的在一个特定的MP3样品边界,避免样品剪裁(这是执行它广泛被使用的工具)。出于性能方面的原因,音频剪辑可以使用苹果的硬件编解码器进行播放。若要启用它,选上在导入设置(import settings)的"使用硬件(Use Hardware)"复选框。有关详细信息,请参阅音频剪辑(Audio Clip)文件。
On mobile platforms compressed audio is encoded as MP3 for speedier
decompression. Beware that this compression can remove samples at the
end of the clip and potentially break a "perfect-looping" clip. Make
sure the clip is right on a specific MP3 sample boundary to avoid sample
clipping (Tools to perform this is widely available).
在移动平台上的压缩音频以MP3格式编码为了能快捷解压。要注意,这种压缩是可以删除剪辑结尾的样品,并可能打破一个"完美循环"的剪辑。确保剪辑是正确的在一个特定的MP3样品边界,避免样品剪裁(这是执行它广泛被使用的工具)。
朱峰社区编辑推荐
realflow在制作水效果方面还是比较强的,…
朱峰社区 版权所有 闽ICP备号
ZhuFeng Community All Rights Reserved
1.复制文本发给您的QQ好友或群、微信等;好友点击链接以后,转发就成功了。
2.如朋友点击您的链接,您需要需刷新一下才行;同一个好友仅能点击一次。拒绝访问 |
| 百度云加速
请打开cookies.
此网站 () 的管理员禁止了您的访问。原因是您的访问包含了非浏览器特征(38d26f9db30c6634-ua98).
重新安装浏览器,或使用别的浏览器字号:大 中 小
tips:LitJson 是一个 Unity3D 用来读取 Json 文件的插件,网上有下载,这里就不提供了 ///////////////////////////////////////////////////////////////////////////////////////using UnityEusing System.Cusing System.IO;public class Com_FileController { // 文件IO操作,这里不需要释放 // private static Com_FileController sm_share = public string m_path = "";
public static Com_FileController Share() {
if (sm_share == null)
sm_share = new Com_FileController();
sm_share.InitData();
return sm_ } void InitData () {
if (Application.platform == RuntimePlatform.Android)
m_path = Application.persistentDataPath + "/";
else if (Application.platform == RuntimePlatform.windowsEditor)
m_path = Application.dataP
int num = m_path.LastIndexOf("/");
m_path = m_path.Substring(0, num) + "/";
else if (Application.platform == RuntimePlatform.windowsPlayer)
m_path = Application.dataP
int num = m_path.LastIndexOf("/");
m_path = m_path.Substring(0, num) + "/";
m_path = Application.persistentDataPath + "/";
Debug.Log("Com_FileController, InitData(), m_path: " + m_path); } public bool Exists (string fileName) {
return File.Exists(m_path + fileName); } public string ReadAllText (string fileName) {
if (Exists(fileName))
return File.ReadAllText(m_path + fileName);
return "";
} } public byte[] ReadFileStream (string fileName) {
fs = new FileStream(m_path + fileName, FileMode.Open, FileAccess.Read);
catch (System.Exception e)
Debug.Log("exception: " + m_path + fileName);
Debug.Log(e.ToString());
return new byte[0];
byte[] datas = new byte[fs.Length];
fs.Read(datas, 0, datas.Length);
fs.Close();
fs.Dispose();
} public void WriteAllText (string fileName, string contextStr) {
File.WriteAllText(m_path + fileName, contextStr); } public void WriteFileStream (string fileName, byte[] datas) {
FileStream fs = new FileStream(m_path + fileName, FileMode.OpenOrCreate, FileAccess.Write);
fs.Write(datas, 0, datas.Length);
fs.Close();
fs.Dispose(); } public void Delete (string fileName) {
if (Exists(fileName))
File.Delete(m_path + fileName);
} }}/////////////////////////////////////////////////////////////////////////////////////using UnityEusing System.Cusing System.Collections.Gpublic class Com_AudioManager { // 音频管理,这里不需要释放 // private static Com_AudioManager sm_share = AudioSource m_musicAudio = // 音乐播放器 // AudioSource m_soundAudio = // 音效播放器 // Dictionary&int, AudioClip& m_audioClipDic = // 声音 ID, 声音 // Dictionary&int, AudioSource& m_channelDic = // 声道号, 声音播放器 //& public static Com_AudioManager Share() {
if (sm_share == null)
sm_share = new Com_AudioManager();
sm_share.InitData();
return sm_ } public static void Destroy () {
if (sm_share != null)
sm_share.StopMusic();
sm_share.StopSound();
sm_share.CleanAudioDic();
sm_share.CleanChannelDic();
GameObject.Destroy(sm_share.m_musicAudio);
GameObject.Destroy(sm_share.m_soundAudio);
sm_share.m_musicAudio =
sm_share.m_soundAudio =
sm_share =
void InitData () {
GameObject obj = Common_Com.Share().GetNotificationObj();
if (obj != null)
if (m_musicAudio == null)
m_musicAudio = obj.AddComponent&AudioSource&(); // temp delete
if (m_soundAudio == null)
m_soundAudio = obj.AddComponent&AudioSource&(); // temp delete
m_audioClipDic = new Dictionary&int, AudioClip&();
m_channelDic = new Dictionary&int, AudioSource&();
Debug.Log("Com_AudioManager InitData() error!, notification obj is null!");
SetMusicLoop(true); } public void AddAudioClip (int id, AudioClip audioClip) // 将声音加到字典中 // {
if (m_audioClipDic != null)
m_audioClipDic.Add(id, audioClip);
} } public void CleanAudioDic () // 清空保存声音的字典, 只有影响到游戏效率的时候才要调用 // {
if (m_audioClipDic != null)
m_audioClipDic.Clear();
} } public void CleanChannelDic () // 清空声道的字典, 只有影响到游戏效率的时候才要调用 // {
if (m_channelDic != null)
foreach (KeyValuePair&int, AudioSource& kvp in m_channelDic)
GameObject.Destroy(kvp.Value);
m_channelDic.Clear();
} } public void SetMusicVolume (float value) // 0.0 到 1.0 // {
if (m_musicAudio != null)
m_musicAudio.volume =
} } public float GetMusicVolume () {
if (m_musicAudio != null)
return m_musicAudio.
return 0; } public void SetSoundVolume (float value) // 0.0 到 1.0 // {
if (m_soundAudio != null)
m_soundAudio.volume =
public float GetSoundVolume () {
if (m_soundAudio != null)
return m_soundAudio.
return 0; } public void SetMusicMute (bool sign) // 设置音乐是否静音 // {
if (m_musicAudio != null)
m_musicAudio.mute =
} } public bool IsMusicMute () {
if (m_musicAudio != null)
return m_musicAudio.
} public void SetSoundMute (bool sign) // 设置音效是否静音 // {
if (m_soundAudio != null)
m_soundAudio.mute =
public bool IsSoundMute () {
if (m_soundAudio != null)
return m_soundAudio.
} public void PlaySound (AudioClip audioClip) // 只播放一次音效,每个音效相互独立 // {
if (m_soundAudio != null)
if (!IsSoundMute())
m_soundAudio.PlayOneShot(audioClip);
} } public void PlaySound (string resPath) {
AudioClip audioClip = Resources.Load(resPath) as AudioC
if (audioClip != null)
PlaySound(audioClip);
Debug.LogError("audioClip is null");
} } public void StopSound () // 停止所有音效 // {
if (m_soundAudio != null)
m_soundAudio.Stop();
} } public void PlayMusic (AudioClip audioClip) // 播放背景音乐,会停掉上次播放的背景音乐 // {
if (m_musicAudio != null)
m_musicAudio.clip = audioC
m_musicAudio.Play();
} } public void PlayMusic (string resPath) {
AudioClip audioClip = Resources.Load(resPath) as AudioC
if (audioClip != null)
PlayMusic(audioClip);
Debug.LogError("audioClip is null");
} } public void StopMusic () // 停止所有背景音乐 // {
if (m_musicAudio != null)
m_musicAudio.Stop();
} } public void PauseMusic () // 暂停背景音乐 // {
if (m_musicAudio != null)
m_musicAudio.Pause();
} } public void PlayMusic () // 继续播放背景音乐 // {
if (m_musicAudio != null)
m_musicAudio.Play();
} } public bool IsPlayingMusic () {
if (m_musicAudio != null)
return m_musicAudio.isP
} public void SetMusicLoop (bool sign) {
if (m_musicAudio != null)
m_musicAudio.loop =
} } public bool IsMusicLoop () {
if (m_musicAudio != null)
return m_musicAudio.
} public AudioSource GetMusicPlayer () {
return m_musicA } public AudioSource GetSoundPlayer () {
return m_soundA }}/////////////////////////////////////////////////////////////////////////////////////using UnityEusing System.Cusing S// 这个类的作用为设置一个 GameObject 不会因切换场景而消失 //public class NotificationNode : MonoBehaviour { public static NotificationNode sm_share = void Awake () {
//Debug.Log("NotificationNode, Awake(), " + this.gameObject.name);
if (sm_share == null)
sm_share =
Debug.Log("NotificationNode, Awake()");
DontDestroyOnLoad(this.gameObject);
} } void OnDestroy () {
//Debug.Log("NotificationNode, OnDestroy(), " + this.gameObject.name);
if (sm_share == this)
MyDestroy();
sm_share =
Debug.Log("NotificationNode, OnDestroy()");
} } void MyInit () {
Application.runInBackground =
string str = String.Format("NotificationNode MyInit() {0} {1}", "date time: ", DateTime.Now); // 用来证明游戏当前的运行时间 //
Debug.Log(str); } void MyDestroy () {
Com_AudioManager.Destroy();
Common_Com.Destroy(); } // Use this for initialization void Start () {
// Update is called once per frame void Update () {
}}/////////////////////////////////////////////////////////////////////////////////////using UnityEusing Susing System.Cusing System.Collections.Gusing LitJusing System.Tusing System.Security.Cusing System.IO;public class Common_Com { private static Common_Com sm_share =
Hashtable m_fileTable = private const string PRIVATE_KEY = "HaHaHaHa312"; // 私钥 // private const string PUBLIC_KEY = "HeHeHaHa123"; // 公钥 // private JsonData m_stringMap = public static Common_Com Share () {
if (sm_share == null)
sm_share = new Common_Com();
sm_share.InitData();
return sm_ } public static void Destroy () {
if (sm_share != null)
sm_share.DestroyData();
sm_share =
} } void InitData () {
m_fileTable = new Hashtable();
{ // string info
UnityEngine.TextAsset s = Resources.Load("Tables/string") as TextA
string tmp = s.
m_stringMap = JsonMapper.ToObject(tmp);
if (m_stringMap == null)
Debug.Log("Error: m_stringMap == null");
} } void DestroyData () {
m_fileTable.Clear();
m_fileTable = } public GameObject LoadPrefab(string pathName) // 加载预制体 // {
return (GameObject)Resources.Load(pathName); } public GameObject CopyGameObjectInResources(string name, Vector3 position, Quaternion rotation) // 复制一个预制体到场景中 // {
GameObject prefab =
prefab = LoadPrefab(name);
if (prefab != null)
return (GameObject)UnityEngine.GameObject.Instantiate(prefab, position, rotation);
} public GameObject CopyGameObjectInResources(string name) // 复制一个预制体到场景中, 保留这个预制体的坐标、角度和缩放大小 // {
GameObject prefab =
prefab = LoadPrefab(name);
if (prefab != null)
Vector3 localScale = new Vector3(prefab.transform.localScale.x, prefab.transform.localScale.y, prefab.transform.localScale.z);
GameObject gameObj = (GameObject)UnityEngine.GameObject.Instantiate(prefab, prefab.transform.position, prefab.transform.rotation); // create game object
if (gameObj != null)
gameObj.transform.localScale = localS
return gameO
} public GameObject LoadPanelPrefab(string name ,GameObject parent) {
GameObject panelGo;
panelGo = CopyGameObjectInResources(name);
if (panelGo != null)
panelGo.name = panelGo.name.Remove(panelGo.name.Length -7);
if (parent != null)
Vector3 pos = new Vector3(panelGo.transform.position.x, panelGo.transform.position.y, panelGo.transform.position.z);
Vector3 scale = new Vector3(panelGo.transform.localScale.x, panelGo.transform.localScale.y, panelGo.transform.localScale.z);
panelGo.transform.parent = parent.
panelGo.transform.localScale =
panelGo.transform.localPosition =
return panelGo; } public string GetString(string key) {
string value = "";
if (m_stringMap != null)
value = (string)m_stringMap[key];
catch (Exception ex)
Debug.Log("error, GetString() ex = " + ex);
} public void LookChilds (GameObject gObject) // 看孩子节点,不看当前节点 // {
foreach (Transform child in gObject.transform)
Debug.Log("object name is " + child.gameObject.name);
LookChilds(child.gameObject);
} } public List&GameObject& GetChilds (GameObject gObject) {
List&GameObject& objs = new List&GameObject&();
GetChilds(gObject, objs);
} public int GetChildsNum(GameObject gObject)//得到第一级的孩子个数// {
int nCount = 0;
foreach (Transform child in gObject.transform)
return nC } public int GetAllChildsNum(GameObject gObject) //得到总孩子个数,包括子孩子// {
return GetChilds(gObject).C } void GetChilds (GameObject gObject, List&GameObject& objs) {
foreach (Transform child in gObject.transform)
objs.Add(child.gameObject);
GetChilds(child.gameObject, objs);
public GameObject FindChild (GameObject gObject, string name) // 根据一个名字获得 GameObject // {
if (gObject == null)
//Debug.Log("Error, FindChild() gObject == null, name = " + name);
return UnityEngine.GameObject.Find(name);
GameObject tempObject =
foreach (Transform child in gObject.transform)
if (child.gameObject.name == name)
tempObject = child.gameO
tempObject = FindChild (child.gameObject, name);
if (tempObject != null)
return tempO } public Texture2D GetCapture () // 屏幕截图 // {
return GetCapture (0, 0, Screen.width, Screen.height); } public Texture2D GetCapture (int left, int top, int width, int height) // 屏幕截图 // {
// 注: yield return new WaitForEndOfFrame(); // 需要等到这个时候才能调用下面的截图函数 //
Texture2D tex = new Texture2D(width, height, TextureFormat.ARGB32, false);
tex.ReadPixels(new Rect(left, top, width, height), 0, 0, true);
} public GameObject ShareNotificationObj () // warning: share notification obj, don't use in Awake() or OnDestroy(). {
if (NotificationNode.sm_share != null)
return NotificationNode.sm_share.gameO
GameObject obj = new GameObject();
obj.name = "NotificationObj";
obj.AddComponent&NotificationNode&();
} } public GameObject GetNotificationObj () // 获得唯一的全局 GameObject // {
if (NotificationNode.sm_share != null)
return NotificationNode.sm_share.gameO
} } public bool BeginFile (String fileName) // 开始文件操作, 读取文件, 返回 true 说明有这个文件 // {
//Debug.Log("BeginFile()");
return BeginFile(fileName, false); } public bool BeginFile (String fileName, bool isEncrypt) // isEncrypt 为 true 表示这个文件原来是加密的,需要解密 // {
String fileData = Com_FileController.Share().ReadAllText(fileName);
Hashtable hashtable =
// 在这里可以先对 fileData 进行解密 //
if (isEncrypt)
fileData = DecryptDES(fileData);
hashtable = JsonMapper.ToObject&Hashtable&(fileData);
catch (Exception ex)
hashtable =
Debug.Log ("Exception = " + ex);
if (hashtable != null)
m_fileTable[fileName] =
m_fileTable[fileName] = new Hashtable();
} } public void SetFileData (string fileName, string key, string data) // 设置文件的数据 // {
if (m_fileTable.Contains(fileName))
Hashtable hashtable = (Hashtable)m_fileTable[fileName];
hashtable[key] =
} } public string GetFileData (string fileName, string key, string defaultStr) // 获得文件的数据 // {
if (m_fileTable.Contains(fileName))
Hashtable hashtable = m_fileTable[fileName] as H
if (hashtable.Contains(key))
return hashtable[key].ToString();
return defaultS } public string GetFileData (string fileName, string key) // 获得文件的数据 // {
return GetFileData(fileName, key, ""); } public void RemoveFileData (string fileName, string key) // 移除文件的数据 // {
if (m_fileTable.Contains(fileName))
Hashtable hashtable = (Hashtable)m_fileTable[fileName];
if (hashtable.Contains(key))
hashtable.Remove(key);
} } public void RemoveAllFileData (string fileName) {
if (m_fileTable.Contains(fileName))
m_fileTable[fileName] = new Hashtable();
} } public void EndFile (string fileName) // 结束文件操作, 保存文件 // {
//Debug.Log("EndFile()");
EndFile(fileName, false); } public void EndFile (string fileName, bool isEncrypt) // isEncrypt 为 true 表示保存为加密的数据 // {
if (m_fileTable.Contains(fileName))
Hashtable hashtable = m_fileTable[fileName] as H
string fileData = "";
JsonData jsonData = new JsonData();
foreach (DictionaryEntry de in hashtable)
jsonData[de.Key.ToString()] = de.Value.ToString();
fileData = JsonMapper.ToJson(jsonData);
// 在这里可以先对 fileData 进行加密 //
if (isEncrypt)
fileData = EncryptDES(fileData);
Com_FileController.Share().WriteAllText(fileName, fileData);
m_fileTable.Remove(fileName);
} } public void Quit () // 结束游戏程序, 还要在这里销毁一些东西 // {
Application.Quit(); } /// &summary& // /// DES加密字符串 // /// &/summary& // /// &param name="encryptString"&待加密的字符串&/param& // /// &param name="encryptKey"&加密密钥,要求为8位&/param& // /// &returns&加密成功返回加密后的字符串,失败返回源串&/returns& // public string EncryptDES (string encryptString, string encryptKey) {//
Debug.Log("EncryptDES, encryptString = " + encryptString + ", encryptKey = " + encryptKey);
byte[] rgbKey = Encoding.UTF8.GetBytes(encryptKey.Substring(0, 8));
byte[] rgbIV = Encoding.UTF8.GetBytes(PRIVATE_KEY.Substring(0, 8));
byte[] inputByteArray = Encoding.UTF8.GetBytes(encryptString);
DESCryptoServiceProvider dCSP = new DESCryptoServiceProvider();
MemoryStream mStream = new MemoryStream();
CryptoStream cStream = new CryptoStream(mStream, dCSP.CreateEncryptor(rgbKey, rgbIV), CryptoStreamMode.Write);
cStream.Write(inputByteArray, 0, inputByteArray.Length);
cStream.FlushFinalBlock();
cStream.Close();
return Convert.ToBase64String(mStream.ToArray());
Debug.LogError("EncryptDES failed.");
return encryptS
} } public string EncryptDES (string encryptString) // 加密 // {
Debug.Log("EncryptDES()");
return EncryptDES(encryptString, PUBLIC_KEY); }
/// &summary& // /// DES解密字符串 // /// &/summary& // /// &param name="decryptString"&待解密的字符串&/param& // /// &param name="decryptKey"&解密密钥,要求为8位,和加密密钥相同&/param& // /// &returns&解密成功返回解密后的字符串,失败返源串&/returns& // public string DecryptDES (string decryptString, string decryptKey) {//
Debug.Log("DecryptDES, decryptString = " + decryptString + ", decryptKey = " + decryptKey);
byte[] rgbKey = Encoding.UTF8.GetBytes(decryptKey.Substring(0, 8));
byte[] rgbIV = Encoding.UTF8.GetBytes(PRIVATE_KEY.Substring(0, 8));
byte[] inputByteArray = Convert.FromBase64String(decryptString);
DESCryptoServiceProvider DCSP = new DESCryptoServiceProvider();
MemoryStream mStream = new MemoryStream();
CryptoStream cStream = new CryptoStream(mStream, DCSP.CreateDecryptor(rgbKey, rgbIV), CryptoStreamMode.Write);
cStream.Write(inputByteArray, 0, inputByteArray.Length);
cStream.FlushFinalBlock();
cStream.Close();
return Encoding.UTF8.GetString(mStream.ToArray());
Debug.LogError("DecryptDES failed.");
return decryptS
} } public string DecryptDES (string decryptString) // 解密 // {
Debug.Log("DecryptDES()");
return DecryptDES(decryptString, PUBLIC_KEY); } public void VibrateEx() // 震动函数 // {
#if UNITY_ANDROID & //安卓//
Handheld.Vibrate();
#elif UNITY_IPHONE &//iPhone//
Handheld.Vibrate();
#elif UNITY_STANDALONE_WIN || UNITY_EDITOR &//windows平台和web平台//
function open_phone(e) {
var context = document.title.replace(/%/g, '%');
var url = document.location.
open("/ishare.do?m=t&u=" + encodeURIComponent(url) + "&t=" + encodeURIComponent(context) + "&sid=70cd6ed4a0");
!觉得精彩就顶一下,顶的多了,文章将出现在更重要的位置上。
请根据下图中的字符输入验证码:
(您的评论将有可能审核后才能发表)
已成功添加“”到
请不要超过6个字}

我要回帖

更多关于 unity 音频格式 的文章

更多推荐

版权声明:文章内容来源于网络,版权归原作者所有,如有侵权请点击这里与我们联系,我们将及时删除。

点击添加站长微信