Example #1
0
        /// <summary>
        /// 开始加载资源
        /// </summary>
        /// <param name="fileExtensionName">带后缀的文件名</param>
        internal static void StartLoadAssets(string fileExtensionName)
        {
            //后缀名
            string extension = Path.GetExtension(fileExtensionName);
            //文件名(不带后缀)
            string fileNameWithoutExtension = Path.GetFileNameWithoutExtension(fileExtensionName);
            string songPath  = string.Concat(Application.streamingAssetsPath, AssetsControl.AUDIO, fileExtensionName);
            string lyricPath = string.Concat(Application.streamingAssetsPath, AssetsControl.LYRIC, fileNameWithoutExtension, AssetsControl.LYRICEXTENSION);
            string moviePath = string.Concat(Application.streamingAssetsPath, AssetsControl.MOVIE, fileNameWithoutExtension, AssetsControl.MOVIEEXTENSION);

            if (File.Exists(songPath))
            {
                AudioType audioType = AssetsControl.JudgeAudioType(extension);
                if (audioType == AudioType.MPEG)
                {
                    //转化为wav
                    string outSongPath = string.Concat(Application.streamingAssetsPath, AssetsControl.AUDIO, fileNameWithoutExtension, AssetsControl.AUDIOMP3TOWAVEXTENSION);
                    using (var reader = new Mp3FileReader(songPath))
                    {
                        WaveFileWriter.CreateWaveFile(outSongPath, reader);
                    }
                    audioType = AudioType.WAV;
                    //此处更新文件名fileExtensionName
                    string[] songName = ModelManager.Instance.GetLogicDatas.SongsName;
                    for (int i = 0; i < songName.Length; i++)
                    {
                        if (songName[i].Equals(fileExtensionName))
                        {
                            songName[i] = string.Concat(fileNameWithoutExtension, AssetsControl.AUDIOMP3TOWAVEXTENSION);
                            break;
                        }
                    }
                    File.Delete(songPath);
                    //重定向路径
                    songPath = outSongPath;
                }
                AssetsControl.songRequest = LoadAssetsTools.StartLoadAudioClip(songPath, audioType);
            }
            else
            {
                Debug.LogError("歌曲文件不存在");
            }

            if (File.Exists(lyricPath))
            {
                AssetsControl.textAssetRequest = LoadAssetsTools.StartLoadTextAsset(lyricPath);
            }

            if (File.Exists(moviePath))
            {
                ModelManager.Instance.GetScenesDatas.VideoPlayer.enabled = true;
                LoadAssetsTools.StartLoadMovie(moviePath, ModelManager.Instance.GetScenesDatas.VideoPlayer);
            }
        }
Example #2
0
        /// <summary>
        /// 刷新资源
        /// </summary>
        internal static void RefreshAssets()
        {
            LogicDatas  logicDatas  = ModelManager.Instance.GetLogicDatas;
            ScenesDatas scenesDatas = ModelManager.Instance.GetScenesDatas;

            if (logicDatas.GameState != GameState.Loading)
            {
                return;
            }
            if (AssetsControl.IsLoadFinishAssets())
            {
                //此处应统一调用并更新UI
                AssetsControl.LoadFinish(out AudioClip audioClip, out string textContent);
                scenesDatas.AudioSource.clip = audioClip;
                logicDatas.LyricInfo         = ParseLyric.ParseLyricFunc(textContent);
                SongControl.PlayLoadFinishSong();
            }
        }
Example #3
0
 /// <summary>
 /// 加载下一首歌曲
 /// </summary>
 /// <param name="songName">歌曲名称</param>
 private static void LoadNextSong(string songName)
 {
     ModelManager.Instance.GetLogicDatas.GameState = GameState.Loading;
     AssetsControl.StartLoadAssets(songName);
 }