コード例 #1
0
    /// <summary>
    /// 转换Wwis 的xml to json
    /// zzg 增加 2019-1-21 16:06
    /// </summary>
    public static bool ConvertXml2Json(string srcfile, string dstfile)
    {
        string path = srcfile;

        Debug.Log(path);

        string soundStr = string.Empty;

        if (File.Exists(path))
        {
            soundStr = File.ReadAllText(path);
        }
        else
        {
            Logger.LogError("待转换文件不存在,请放入文件,如果不需要转换请忽略");
            return(false);
            //soundStr = Resources.Load<TextAsset>("SoundbanksInfo").text;
        }
        BnkJson bJson = new BnkJson();

        bJson.m = new List <BnkMap>();

        XmlElement  xml_root   = XmlParse.LoadXml(soundStr);
        XmlNode     soundBanks = XmlParse.FindSingleNode(xml_root, "SoundBanks");
        XmlNodeList node_list  = soundBanks.ChildNodes;
        IEnumerator _enmu      = node_list.GetEnumerator();

        while (_enmu.MoveNext())
        {
            XmlNode temp_node  = _enmu.Current as XmlNode;
            string  bnkName    = temp_node.SelectSingleNode("ShortName").InnerText;
            XmlNode eventNodes = temp_node.SelectSingleNode("IncludedEvents");
            if (eventNodes != null)
            {
                XmlNodeList eventList  = eventNodes.SelectNodes("Event");
                IEnumerator _enmuEvent = eventList.GetEnumerator();
                while (_enmuEvent.MoveNext())
                {
                    BnkMap bMap = new BnkMap();

                    XmlNode temp_event_node = _enmuEvent.Current as XmlNode;
                    string  key             = temp_event_node.Attributes["Name"].InnerText;

                    bMap.n = key;

                    BnkData bData = new BnkData();
                    bData.id  = uint.Parse(temp_event_node.Attributes["Id"].InnerText);
                    bData.bnk = bnkName;

                    bMap.d = bData;

                    bJson.m.Add(bMap);
                }
            }
        }
        string wwiseInfo = JsonUtility.ToJson(bJson);

        // string jsonpath = Application.dataPath + "/Resources/SoundbanksInfo.txt";
        string jsonpath = dstfile;

        if (File.Exists(jsonpath))
        {
            File.Delete(jsonpath);
        }

        File.WriteAllText(jsonpath, wwiseInfo, System.Text.Encoding.UTF8);
        //File.Delete(path);

        Logger.Log(wwiseInfo);
        return(true);
    }
コード例 #2
0
    //转换生成自动更新的音效资源
    public static void BuildAudioData(BuildTarget buildTarget, string channelName)
    {
        //首先从资源路径复制所有音效资源到更新路径
        string pltname = GetPlatformName(buildTarget);

        //取得音效的原始路径
        string sourcePath = GetAudioSourceDataPath(pltname);
        //资源输出路径
        string AssetsPath = GetAssetBundleOutputPath(buildTarget, channelName);
        //需要复制到的资源路径
        string destPath = Path.Combine(AssetsPath, AssetBundleConfig.AssetBundlesAudioFolderName_GEN);

        //加入平台
        destPath = Path.Combine(destPath, pltname);
        //要删除的Audio路径
        string delpath = Path.Combine(AssetsPath, AssetBundleConfig.AssetBundlesAudioFolderName);

        // 有毒,竟然在有的windows系统这个函数删除不了目录,不知道是不是Unity的Bug
        // GameUtility.SafeDeleteDir(destination);
        destPath   = GameUtility.FormatToUnityPath(destPath);
        sourcePath = GameUtility.FormatToUnityPath(sourcePath);
        delpath    = GameUtility.FormatToUnityPath(delpath);
        //如果文件夹下面有meta文件的时候无法删除文件夹,因为meta文件是隐藏文件,需要权限
        CopyFolder(sourcePath, destPath, ".meta");
        //转换xml为json
        string path = Path.Combine(destPath, AssetBundleConfig.WWISESoundbanksInfo_XML);

        Debug.Log(path);
        string soundStr = string.Empty;

        if (File.Exists(path))
        {
            soundStr = File.ReadAllText(path);
        }
        else
        {
            CreateAssetbundleMd5(destPath, AssetsPath);
            Logger.LogError("文件不存在,请放入文件,如果不需要转换请忽略");
            return;
            //soundStr = Resources.Load<TextAsset>("SoundbanksInfo").text;
        }
        BnkJson bJson = new BnkJson();

        bJson.m = new List <BnkMap>();

        XmlElement  xml_root   = XmlParse.LoadXml(soundStr);
        XmlNode     soundBanks = XmlParse.FindSingleNode(xml_root, "SoundBanks");
        XmlNodeList node_list  = soundBanks.ChildNodes;
        IEnumerator _enmu      = node_list.GetEnumerator();

        while (_enmu.MoveNext())
        {
            XmlNode temp_node  = _enmu.Current as XmlNode;
            string  bnkName    = temp_node.SelectSingleNode("ShortName").InnerText;
            XmlNode eventNodes = temp_node.SelectSingleNode("IncludedEvents");
            if (eventNodes != null)
            {
                XmlNodeList eventList  = eventNodes.SelectNodes("Event");
                IEnumerator _enmuEvent = eventList.GetEnumerator();
                while (_enmuEvent.MoveNext())
                {
                    BnkMap bMap = new BnkMap();

                    XmlNode temp_event_node = _enmuEvent.Current as XmlNode;
                    string  key             = temp_event_node.Attributes["Name"].InnerText;

                    bMap.n = key;

                    BnkData bData = new BnkData();
                    bData.id  = uint.Parse(temp_event_node.Attributes["Id"].InnerText);
                    bData.bnk = bnkName;

                    bMap.d = bData;

                    bJson.m.Add(bMap);
                }
            }
        }
        string wwiseInfo = JsonUtility.ToJson(bJson);
        string jsonpath  = Path.Combine(destPath, AssetBundleConfig.WWISESoundbanksInfo);;

        //删除原始的xml文件
        if (File.Exists(jsonpath))
        {
            File.Delete(jsonpath);
        }

        File.WriteAllText(jsonpath, wwiseInfo, System.Text.Encoding.UTF8);
        File.Delete(path);
        Debug.Log("Json " + AssetBundleConfig.WWISESoundbanksInfo + " 生成成功");

        //拷贝和转换完成之后需要生成所有文件的md5值
        CreateAssetbundleMd5(destPath, AssetsPath);


        AssetDatabase.Refresh();
    }