使用脚本将Unity的ogg音效全部改为2d音效

[MenuItem("将所有3D音效改成2D音效")]
static void change3DMusicTo2D()
{
    string[] fs = GetSoundMetaFile();
    bool hasChangeFile = false;
    foreach(var f in fs)
    {
        if(MakeSoundMetaFile3DFalse(f))
        {
            hasChangeFile = true;
        }
    }
    if(hasChangeFile)
        AssetDatabase.Refresh();
}

static string[] GetSoundMetaFile()
{
    string dir = Application.dataPath + "/Resources/Res/Audio/";
    return System.IO.Directory.GetFiles(dir,"*.ogg.meta",System.IO.SearchOption.AllDirectories);
}

static bool MakeSoundMetaFile3DFalse(string file)
{
    var text = System.IO.File.ReadAllText(file);
    int pos = text.IndexOf("3D: 1");
    if(pos > 0)
    {
        text = text.Replace("3D: 1","3D: 0");
        System.IO.File.WriteAllText(file,text);
        Debug.Log(string.Format("Sound File Make 3D False:{0}",file);
        return true;
    }
    return false;
}

 

 

相关文章

这篇文章将为大家详细讲解有关Unity3D中如何通过Animator动画...
这篇文章主要介绍了Unity3D如何播放游戏视频,具有一定借鉴价...
这篇文章给大家分享的是有关Unity3D各平台路径是什么的内容。...
小编给大家分享一下Unity3D如何实现移动平台上的角色阴影,希...
如何解析基于Unity3D的平坦四叉树地形与Virtual Texture的分...
这篇文章主要介绍Unity3D如何实现动态分辨率降低渲染开销,文...