private void Start() { Conductor.OnBeat += _OnBeat; if (chartReaderObj != null) { chartReader = chartReaderObj.GetComponent <ChartReader>(); } else { Debug.LogError("Chart Reader Object Not Specified"); Application.Quit(); } if (chartFileLocation != "" && chartFileLocation.IndexOf(".txt") > 0) { if (chart == null) { Debug.LogError("Chart list null"); } if (chartReader == null) { Debug.LogError("Chart Reader component is null"); } chart = chartReader.ReadChart(chartFileLocation); } }
public void StartLevel(Level lev, Difficulty diff) { _level = lev; _difficulty = diff; Init(); ChartReader chartReader = GetComponent <ChartReader>(); chart = chartReader.ReadChart(_level.chartFile, _speed, diff); List <Note> thisChartNotes = chart.Notes[diff]; _totalNumberNotes = thisChartNotes.Count; foreach (AudioClip clip in _level.musicFiles) { AudioSource s = gameObject.AddComponent <AudioSource>(); s.clip = clip; s.Play(); songAudioSources.Add(s); } _isRunning = true; }
public IEnumerator _Load(string currentFileName, bool recordLastLoaded = true) { LoadingTasksManager tasksManager = services.loadingTasksManager; bool error = false; Song backup = currentSong; #if TIMING_DEBUG float totalLoadTime = Time.realtimeSinceStartup; #endif bool mid = false; Song newSong = null; MidReader.CallbackState midiCallbackState = MidReader.CallbackState.None; List <LoadingTask> tasks = new List <LoadingTask>() { new LoadingTask("Loading file", () => { // Wait for saving to complete just in case while (currentSong.isSaving) { } if (errorManager.HasErrorToDisplay()) { error = true; return; } mid = System.IO.Path.GetExtension(currentFileName) == ".mid"; try { if (mid) { newSong = MidReader.ReadMidi(currentFileName, ref midiCallbackState); } else { newSong = ChartReader.ReadChart(currentFileName); } } catch (Exception e) { currentSong = backup; if (mid) { errorManager.QueueErrorMessage(Logger.LogException(e, "Failed to open mid file")); } else { errorManager.QueueErrorMessage(Logger.LogException(e, "Failed to open chart file")); } error = true; } }), new LoadingTask("Loading audio", () => { if (error) { return; } // Free the previous audio clips FreeAudio(); newSong.LoadAllAudioClips(); }), }; tasksManager.KickTasks(tasks); while (tasksManager.isRunningTask) { while (midiCallbackState == MidReader.CallbackState.WaitingForExternalInformation) { // Halt main thread until message box is complete } yield return(null); } // Tasks have finished if (error) { yield break; // Immediate exit } isDirty = false; if (mid) { currentFileName = string.Empty; isDirty = true; Debug.Log("Loaded mid file"); } if (recordLastLoaded && currentFileName != string.Empty && !mid) { lastLoadedFile = System.IO.Path.GetFullPath(currentFileName); } else { lastLoadedFile = string.Empty; } currentSong = newSong; LoadSong(currentSong); #if TIMING_DEBUG Debug.Log("Total load time: " + (Time.realtimeSinceStartup - totalLoadTime)); #endif }
public IEnumerator _Load(string currentFileName, bool recordLastLoaded = true) { bool error = false; Song backup = currentSong; #if TIMING_DEBUG float totalLoadTime = 0; #endif // Start loading animation Globals.applicationMode = Globals.ApplicationMode.Loading; loadingScreen.FadeIn(); yield return(null); // Wait for saving to complete just in case while (currentSong.isSaving) { yield return(null); } if (SaveErrorCheck()) { yield break; } #if TIMING_DEBUG totalLoadTime = Time.realtimeSinceStartup; #endif bool mid = false; #if TIMING_DEBUG float time = Time.realtimeSinceStartup; #endif // Load the actual file loadingScreen.loadingInformation.text = "Loading file"; yield return(null); Song newSong = null; MidReader.CallbackState midiCallbackState = MidReader.CallbackState.None; System.Threading.Thread songLoadThread = new System.Threading.Thread(() => { mid = (System.IO.Path.GetExtension(currentFileName) == ".mid"); try { if (mid) { newSong = MidReader.ReadMidi(currentFileName, ref midiCallbackState); } else { newSong = ChartReader.ReadChart(currentFileName); } } catch (Exception e) { currentSong = backup; if (mid) { ErrorMessage.errorMessage = Logger.LogException(e, "Failed to open mid file"); } else { ErrorMessage.errorMessage = Logger.LogException(e, "Failed to open chart file"); } error = true; } }); songLoadThread.Priority = System.Threading.ThreadPriority.Highest; songLoadThread.Start(); while (songLoadThread.ThreadState == System.Threading.ThreadState.Running) { while (midiCallbackState == MidReader.CallbackState.WaitingForExternalInformation) { // Halt thread until message box is complete } yield return(null); } if (error) { loadingScreen.FadeOut(); errorMenu.gameObject.SetActive(true); yield break; } #if TIMING_DEBUG Debug.Log("Chart file load time: " + (Time.realtimeSinceStartup - time)); time = Time.realtimeSinceStartup; #endif // Load the audio clips loadingScreen.loadingInformation.text = "Loading audio"; yield return(null); // Free the previous audio clips FreeAudio(); newSong.LoadAllAudioClips(); while (newSong.isAudioLoading) { yield return(null); } #if TIMING_DEBUG Debug.Log("All audio files load time: " + (Time.realtimeSinceStartup - time)); #endif yield return(null); isDirty = false; #if TIMING_DEBUG Debug.Log("File load time: " + (Time.realtimeSinceStartup - totalLoadTime)); #endif // Wait for audio to fully load while (newSong.isAudioLoading) { yield return(null); } if (mid) { currentFileName = string.Empty; isDirty = true; Debug.Log("Loaded mid file"); } if (recordLastLoaded && currentFileName != string.Empty && !mid) { lastLoadedFile = System.IO.Path.GetFullPath(currentFileName); } else { lastLoadedFile = string.Empty; } currentSong = newSong; LoadSong(currentSong); #if TIMING_DEBUG Debug.Log("Total load time: " + (Time.realtimeSinceStartup - totalLoadTime)); #endif // Stop loading animation Globals.applicationMode = Globals.ApplicationMode.Editor; loadingScreen.FadeOut(); loadingScreen.loadingInformation.text = "Complete!"; }
public IEnumerator _Load(string currentFileName, bool recordLastLoaded = true) { LoadingTasksManager tasksManager = services.loadingTasksManager; bool error = false; Song backup = currentSong; #if TIMING_DEBUG float totalLoadTime = Time.realtimeSinceStartup; #endif bool mid = false; Song newSong = null; MidReader.CallbackState midiCallbackState = MidReader.CallbackState.None; List <LoadingTask> tasks = new List <LoadingTask>() { new LoadingTask("Loading file", () => { // Wait for saving to complete just in case while (isSaving) { } if (errorManager.HasErrorToDisplay()) { error = true; return; } mid = System.IO.Path.GetExtension(currentFileName) == ".mid"; try { if (mid) { newSong = MidReader.ReadMidi(currentFileName, ref midiCallbackState); } else { newSong = ChartReader.ReadChart(currentFileName); } } catch (Exception e) { currentSong = backup; if (mid) { errorManager.QueueErrorMessage(Logger.LogException(e, "Failed to open mid file")); } else { errorManager.QueueErrorMessage(Logger.LogException(e, "Failed to open chart file")); } error = true; } try { string directory = System.IO.Path.GetDirectoryName(currentFileName); string iniPath = System.IO.Path.Combine(directory, "song.ini"); if (newSong != null && System.IO.File.Exists(iniPath)) { try { newSong.iniProperties.Open(iniPath); newSong.iniProperties = SongIniFunctions.FixupSongIniWhitespace(newSong.iniProperties); } catch (Exception e) { errorManager.QueueErrorMessage(Logger.LogException(e, "Failed to parse song.ini")); } finally { newSong.iniProperties.Close(); } } } catch (Exception e) { // TODO } }), new LoadingTask("Loading audio", () => { if (error) { return; } // Free the previous audio clips currentSongAudio.FreeAudioStreams(); currentSongAudio.LoadAllAudioClips(newSong); }), }; tasksManager.KickTasks(tasks); while (tasksManager.isRunningTask) { while (midiCallbackState == MidReader.CallbackState.WaitingForExternalInformation) { // Halt main thread until message box is complete } yield return(null); } // Tasks have finished if (error) { yield break; // Immediate exit } isDirty = false; if (mid) { currentFileName = string.Empty; isDirty = true; Debug.Log("Loaded mid file"); } if (recordLastLoaded && currentFileName != string.Empty && !mid) { lastLoadedFile = System.IO.Path.GetFullPath(currentFileName); } else { lastLoadedFile = string.Empty; } currentSong = newSong; sessionFlags &= ~ChartEditorSessionFlags.CurrentChartSavedInProprietyFormat; LoadSong(currentSong); #if TIMING_DEBUG Debug.Log("Total load time: " + (Time.realtimeSinceStartup - totalLoadTime)); #endif }