コード例 #1
0
    // 把Sound_Ogg里的文件都解压出来
    public static IEnumerator AndroidPrepareForSound(ProgressNotifyDelegate notifyProgress)
    {
        // 读List
        WWW list = new WWW(Utility.streamingAssetsPath + "Sounds_Ogg/List.bytes");

        yield return(list);

        string destpath_list = Utility.LocalStoragePath + "/Sounds_Ogg/List.bytes";

        destpath_list = destpath_list.Replace("jar:file:/", "");

        // 创建Sounds_Ogg文件夹
        string OggDic = destpath_list.Remove(destpath_list.LastIndexOf("/"));

        Directory.CreateDirectory(OggDic);

        // 写入List
        FileStream fs_list = File.Create(destpath_list);

        fs_list.Write(list.bytes, 0, list.bytes.Length);
        fs_list.Close();

        // 读List
        string[] paths = list.text.Split(new char[2] {
            '\r', '\n'
        });

        // 写入ogg
        for (int i = 0; i < paths.Length; i++)
        {
            string path = paths[i];
            if (string.IsNullOrEmpty(path))
            {
                continue;
            }

            WWW file = new WWW(Utility.streamingAssetsPath + "Sounds_Ogg/" + path + ".bytes");
            yield return(file);

            string destpath = Utility.LocalStoragePath + "/Sounds_Ogg/" + path + ".bytes";
            destpath = destpath.Replace("jar:file:/", "");

            string destdic = destpath.Remove(destpath.LastIndexOf("/"));
            Directory.CreateDirectory(destdic);

            FileStream fs = File.Create(destpath);
            fs.Write(file.bytes, 0, file.bytes.Length);
            fs.Close();

            file.Dispose();

            if (notifyProgress != null)
            {
                notifyProgress((float)(i + 1) / (float)paths.Length);
            }
        }

        list.Dispose();
    }
コード例 #2
0
    public static IEnumerator ConvertOgg2Wav(string Path, string targetPath, ProgressNotifyDelegate notifyProgress)
    {
        string        listFilePath = Path + "/List.bytes";
        StreamReader  sr           = new StreamReader(listFilePath);
        List <string> fileList     = new List <string>();

        while (!sr.EndOfStream)
        {
            fileList.Add(sr.ReadLine());
        }
        sr.Close();
        int fileCount = fileList.Count;

        for (int i = 0; i < fileCount; ++i)
        {
            string   filePath     = fileList[i];
            FileInfo waveFileInfo = new FileInfo(targetPath + filePath + ".wav");
#if UNITY_EDITOR
            if (waveFileInfo.Exists)
            {
                continue;
            }
#endif
#if !UNITY_WEBPLAYER
            if (!waveFileInfo.Directory.Exists)
            {
                waveFileInfo.Directory.Create();
            }
#endif

            string srcFullPath = Path + filePath + ".bytes";
            if (File.Exists(srcFullPath))
            {
                PluginConvertOgg2Wav(srcFullPath, waveFileInfo.FullName);
            }
            else
            {
                ssLogger.LogWarning("Can't find ogg file :" + srcFullPath);
                if (!InitFirstRunFail)
                {
                    InitFirstRunFail = true;
                    //ssUtil.ShowAlertDialog(
                    //	Localization.instance.Get("AlertDialogTitle"),
                    //	Localization.instance.Get("InitFailedAlertMessage"),
                    //	Localization.instance.Get("AlertDialogCancelButtonTitle"));

                    ssLogger.LogError("Timi Init Failed!");
                }
            }

            if (notifyProgress != null)
            {
                notifyProgress((float)(i + 1) / (float)fileCount);
                yield return(null);
            }
        }
    }
コード例 #3
0
    public static IEnumerator PrepareForRun(ProgressNotifyDelegate notifyProgress)
    {
        string srcPath = Utility.LocalStoragePath;

#if UNITY_IPHONE
        srcPath = Application.dataPath + "/Raw";
#elif UNITY_EDITOR || UNITY_STANDALONE_WIN
        srcPath = Application.streamingAssetsPath;
#endif

        string oggSrcPath = srcPath + "/Sounds_Ogg/";
        string targetPath = srcPath + "/Sounds/";

#if UNITY_IPHONE
        targetPath = Utility.LocalStoragePath + "/Sounds/";
#endif
        if (!InitFirstRunFail)
        {
            var enmrt = ssUtil.ConvertOgg2Wav(oggSrcPath, targetPath, notifyProgress);
            while (enmrt.MoveNext())
            {
                yield return(enmrt.Current);
            }
        }

        if (!InitFirstRunFail)
        {
            int Ver = StreamingVer.ReadResourceVer(EResourceVerType.Sound);
            StreamingVer.WriteStreamingVer(EResourceVerType.Sound, Ver);
        }

#if !UNITY_EDITOR
        if (Directory.Exists(oggSrcPath) && !oggSrcPath.Contains("/Raw/Sounds_Ogg/"))
        {
            SafeDeleteDirectory(oggSrcPath, true);
        }
#endif

        yield return(null);
    }
コード例 #4
0
    // 把Font合并了
    public static IEnumerator AndroidPrepareForFont(ProgressNotifyDelegate notifyProgress)
    {
        // 复制numer.ttf
        WWW number = new WWW(Utility.streamingAssetsPath + "Font/number.ttf");

        yield return(number);

        string destpath_number = Utility.AndroidNativeStoragePath + "/Font/number.ttf";

        destpath_number = destpath_number.Replace("jar:file:/", "");

        string FontDic = destpath_number.Remove(destpath_number.LastIndexOf("/"));

        // 写入,重试3次
        bool success = false;

        for (int i = 0; i < 3; i++)
        {
            try
            {
                Directory.CreateDirectory(FontDic);
                success = true;
            }
            catch
            {
            }
            if (success)
            {
                break;
            }
            yield return(new WaitForSeconds(0.5f));
        }
        if (!success)
        {
            InitFirstRunFail = true;
            yield break;
        }


        // 写入,重试3次
        success = false;
        for (int i = 0; i < 3; i++)
        {
            if (Utility.SafeWriteFile(destpath_number, number.bytes))
            {
                success = true;
                break;
            }
            yield return(new WaitForSeconds(0.5f));
        }
        if (!success)
        {
            InitFirstRunFail = true;
            yield break;
        }


        // 复制vdFont.ttf子文件
        WWW list = new WWW(Utility.streamingAssetsPath + "Font/List.bytes");

        yield return(list);

        string destpath = Utility.AndroidNativeStoragePath + "/Font/vdFont.ttf";

        destpath = destpath.Replace("jar:file:/", "");

        //string destdic = destpath.Remove(destpath.LastIndexOf("/"));
        //Directory.CreateDirectory(destdic);

        FileStream fs = File.Create(destpath);

        string[] paths = list.text.Split(new char[2] {
            '\r', '\n'
        });

        for (int i = 0; i < paths.Length; i++)
        {
            string path = paths[i];
            if (string.IsNullOrEmpty(path))
            {
                continue;
            }

            WWW file = new WWW(Utility.streamingAssetsPath + "Font/" + path + ".bytes");
            yield return(file);

            fs.Write(file.bytes, 0, file.bytes.Length);

            if (notifyProgress != null)
            {
                notifyProgress((float)(i + 1) / (float)paths.Length);
            }

            file.Dispose();
        }

        fs.Close();

        list.Dispose();

        number.Dispose();
    }