public void Initialize() { if (LimSystem.ChartContainer == null) { return; } ChartContainer = LimSystem.ChartContainer; BpmManager.Initialize(ChartContainer.ChartData.LanotaChangeBpm); CameraManager.Initialize(ChartContainer.ChartData.LanotaCameraRot, ChartContainer.ChartData.LanotaCameraXZ, ChartContainer.ChartData.LanotaCameraY, ChartContainer.ChartData.LanotaDefault); ScrollManager.Initialize(ChartContainer.ChartData.LanotaScroll); TapNoteManager.Initialize(ChartContainer.ChartData.LanotaTapNote); HoldNoteManager.Initialize(ChartContainer.ChartData.LanotaHoldNote); MediaPlayerManager.Initialize(ChartContainer.ChartMusic, ChartContainer.ChartProperty); BackgroundManager.Initialize(ChartContainer.ChartBackground, ChartContainer.ChartLoadResult); isInitialized = true; }
IEnumerator LoadCurrentProject() { bool isLoadFinished = false; DialogUtils.ProgressBar.ShowProgress(() => { return(isLoadFinished); }); #region Prepare Loading if (string.IsNullOrEmpty(CurrentProject.Name)) { DialogUtils.MessageBox.ShowMessage(LimLanguageManager.TextDict["Project_NoName"]); isLoadFinished = true; yield break; } if (string.IsNullOrEmpty(CurrentProject.Designer)) { DialogUtils.MessageBox.ShowMessage(LimLanguageManager.TextDict["Project_NoDesigner"]); isLoadFinished = true; yield break; } Lanotalium.ChartContainer LastChartContainer = LimSystem.ChartContainer; LimSystem.ChartContainer = new Lanotalium.ChartContainer { ChartProperty = new Lanotalium.Chart.ChartProperty(CurrentProject.ChartPath), ChartLoadResult = new Lanotalium.Chart.ChartLoadResult() }; SystemManager.SavePreferences(); DialogUtils.ProgressBar.Percent = 0.5f; #endregion #region Load Chart try { File.Copy(CurrentProject.ChartPath, CurrentProject.ChartPath.Replace(".txt", "_backup.txt"), true); string ChartJson = File.ReadAllText(CurrentProject.ChartPath); LimSystem.ChartContainer.ChartData = new Lanotalium.Chart.ChartData(ChartJson); } catch (Exception) { DialogUtils.MessageBox.ShowMessage(LimLanguageManager.TextDict["Project_ReadChartFailed"]); isLoadFinished = true; yield break; } LimSystem.ChartContainer.ChartLoadResult.isChartLoaded = true; DialogUtils.ProgressBar.Percent = 0.6f; #endregion #region Load Background Images string BGAColor = null, BGAGray = null, BGALinear = null; switch (CurrentProject.BGACount()) { case 1: BGAColor = CurrentProject.BGA0Path; break; case 2: BGAGray = CurrentProject.BGA0Path; BGAColor = CurrentProject.BGA1Path; break; case 3: BGALinear = CurrentProject.BGA0Path; BGAGray = CurrentProject.BGA1Path; BGAColor = CurrentProject.BGA2Path; break; } DialogUtils.ProgressBar.Percent = 0.65f; if (CurrentProject.BGACount() >= 1) { WWW ImageRead = null; try { if (!File.Exists(BGAColor)) { throw new FileNotFoundException(); } ImageRead = new WWW(Uri.EscapeUriString("file:///" + BGAColor)); } catch (Exception) { DialogUtils.MessageBox.ShowMessage(LimLanguageManager.TextDict["Project_ReadImageFailed"]); isLoadFinished = true; yield break; } yield return(ImageRead); try { if (ImageRead == null || !string.IsNullOrEmpty(ImageRead.error)) { throw new Exception("Color Image Invalid"); } Texture2D BackgroundImage = ImageRead.texture; LimSystem.ChartContainer.ChartBackground.Color = Sprite.Create(BackgroundImage, new Rect(0, 0, BackgroundImage.width, BackgroundImage.height), new Vector2(0.5f, 0.5f), 100); LimSystem.ChartContainer.ChartLoadResult.isBackgroundLoaded = true; } catch (Exception) { DialogUtils.MessageBox.ShowMessage(LimLanguageManager.TextDict["Project_ReadImageFailed"]); isLoadFinished = true; yield break; } } DialogUtils.ProgressBar.Percent = 0.7f; if (CurrentProject.BGACount() >= 2) { WWW ImageRead = null; try { if (!File.Exists(BGAGray)) { throw new FileNotFoundException(); } ImageRead = new WWW(Uri.EscapeUriString("file:///" + BGAGray)); } catch (Exception) { DialogUtils.MessageBox.ShowMessage(LimLanguageManager.TextDict["Project_ReadImageFailed"]); isLoadFinished = true; yield break; } yield return(ImageRead); try { if (ImageRead == null || !string.IsNullOrEmpty(ImageRead.error)) { throw new Exception("Gray Image Invalid"); } Texture2D BackgroundGray = ImageRead.texture; LimSystem.ChartContainer.ChartBackground.Gray = Sprite.Create(BackgroundGray, new Rect(0, 0, BackgroundGray.width, BackgroundGray.height), new Vector2(0.5f, 0.5f), 100); LimSystem.ChartContainer.ChartLoadResult.isBackgroundGrayLoaded = true; } catch (Exception) { DialogUtils.MessageBox.ShowMessage(LimLanguageManager.TextDict["Project_ReadImageFailed"]); isLoadFinished = true; yield break; } } DialogUtils.ProgressBar.Percent = 0.8f; if (CurrentProject.BGACount() == 3) { WWW ImageRead = null; try { if (!File.Exists(BGALinear)) { throw new FileNotFoundException(); } ImageRead = new WWW(Uri.EscapeUriString("file:///" + BGALinear)); } catch (Exception) { DialogUtils.MessageBox.ShowMessage(LimLanguageManager.TextDict["Project_ReadImageFailed"]); isLoadFinished = true; yield break; } yield return(ImageRead); try { if (ImageRead == null || !string.IsNullOrEmpty(ImageRead.error)) { throw new Exception("Linear Image Invalid"); } Texture2D BackgroundLinear = ImageRead.texture; LimSystem.ChartContainer.ChartBackground.Linear = Sprite.Create(BackgroundLinear, new Rect(0, 0, BackgroundLinear.width, BackgroundLinear.height), new Vector2(0.5f, 0.5f), 100); LimSystem.ChartContainer.ChartLoadResult.isBackgroundLinearLoaded = true; } catch (Exception) { DialogUtils.MessageBox.ShowMessage(LimLanguageManager.TextDict["Project_ReadImageFailed"]); isLoadFinished = true; yield break; } } DialogUtils.ProgressBar.Percent = 0.9f; #endregion #region Load Music UnityWebRequest AudioRead = null; switch (Path.GetExtension(CurrentProject.MusicPath)) { case ".wav": AudioRead = UnityWebRequestMultimedia.GetAudioClip(Uri.EscapeUriString("file:///" + CurrentProject.MusicPath), AudioType.WAV); break; case ".ogg": AudioRead = UnityWebRequestMultimedia.GetAudioClip(Uri.EscapeUriString("file:///" + CurrentProject.MusicPath), AudioType.OGGVORBIS); break; case ".mp3": AudioRead = UnityWebRequestMultimedia.GetAudioClip(Uri.EscapeUriString("file:///" + CurrentProject.MusicPath), AudioType.MPEG); break; } try { if (!File.Exists(CurrentProject.MusicPath)) { throw new FileNotFoundException(); } if (AudioRead == null) { throw new InvalidDataException(); } } catch (Exception) { DialogUtils.MessageBox.ShowMessage(LimLanguageManager.TextDict["Project_ReadMusicFailed"]); isLoadFinished = true; yield break; } yield return(AudioRead.SendWebRequest()); if (string.IsNullOrWhiteSpace(AudioRead.error)) { try { LimSystem.ChartContainer.ChartMusic = new Lanotalium.Chart.ChartMusic(DownloadHandlerAudioClip.GetContent(AudioRead)); LimSystem.ChartContainer.ChartLoadResult.isMusicLoaded = true; } catch (Exception) { DialogUtils.MessageBox.ShowMessage(LimLanguageManager.TextDict["Project_ReadMusicFailed"]); isLoadFinished = true; yield break; } } else { DialogUtils.MessageBox.ShowMessage(LimLanguageManager.TextDict["Project_ReadMusicFailed"]); isLoadFinished = true; yield break; } #endregion #region Load Video If Exist if (File.Exists(CurrentProject.ProjectFolder + "/background.mp4")) { LimSystem.ChartContainer.ChartBackground.VideoPath = CurrentProject.ProjectFolder + "/background.mp4"; LimSystem.ChartContainer.ChartLoadResult.isBackgroundVideoDetected = true; } #endregion #region Handle Project File ChartSaveLocation = LimSystem.ChartContainer.ChartProperty.ChartPath; DialogUtils.ProgressBar.Percent = 0.95f; LimSystem.Preferences.LastOpenedChartFolder = LimSystem.ChartContainer.ChartProperty.ChartFolder; LimSystem.Preferences.Designer = CurrentProject.Designer; #endregion #region Clean Up CleanUpEvent.AddListener(() => { if (LastChartContainer != null) { LastChartContainer.CleanUp(); LastChartContainer = null; DestroyImmediate(BGA0.sprite); DestroyImmediate(BGA1.sprite); DestroyImmediate(BGA2.sprite); GC.Collect(); } }); #endregion AsyncOperation LoadAsync = SceneManager.LoadSceneAsync("LimTuner"); while (!LoadAsync.isDone) { DialogUtils.ProgressBar.Percent = 0.95f + LoadAsync.progress * 0.05f; yield return(null); } SaveProjectFile(); DialogUtils.ProgressBar.Percent = 1f; isLoadFinished = true; }