void Update() { if (currentOpenFileName != null && currentPlaybackState == PlaybackState.NoOpenFile) { // Change the state to indicate that the file is opening SetPlaybackState(PlaybackState.OpeningFileInfo); } else if (currentPlaybackState == PlaybackState.OpeningFileInfo && fileInfoReady) { // If the file info is ready but the state has not transitioned, perform // the state change loadingManager.Progress(); SetPlaybackState(PlaybackState.OpeningFileData); } else if (currentPlaybackState == PlaybackState.OpeningFileData) { // If the playback manager is still loading the initial chunks, check // if the loading bar can be updated if (playbackManager.IsLoading) { int lastRemainingItems = loadingManager.RemainingDataItems; int actualRemainingItems = playbackManager.GetChunksToLoadCount(); // If the number of items in the processing queue has changed, update the // loading bar progress if (lastRemainingItems != actualRemainingItems) { // Update its progress by the difference between the remaining item values for (int i = 0; i < (lastRemainingItems - actualRemainingItems); i++) { loadingManager.Progress(); } } } else { // Call the method to show and initialise the mesh kinectMesh.ShowAndInitialiseMesh(); // Destroy and dereference the loading bar if it exists if (loadingManager != null) { loadingManager.DestroyLoading(); loadingManager = null; } // Initialise the slider and its timers, then change to the paused state sliderManager.InitialiseSlider(playbackManager.FileInfoOpen.TotalRecordingLength); SetPlaybackState(PlaybackState.PausedFile); } } else if (currentPlaybackState == PlaybackState.PlayingFile) { // If the playback manager has stopped playing because it needs to buffer, reflect this // in the canvas by changing the state if (!playbackManager.IsPlaying) { SetPlaybackState(PlaybackState.BufferingFile); } else if (kinectMesh.LastFrame) { // Else if the kinect mesh has reached its last frame, pause the file to stop playback TogglePlayPause(); } } else if (currentPlaybackState == PlaybackState.BufferingFile) { // If the playback manager is still buffering, check if the loading bar // can be updated if (playbackManager.IsLoading) { int lastRemainingItems = loadingManager.RemainingDataItems; int actualRemainingItems = playbackManager.GetChunksToLoadCount(); // If the number of items in the processing queue has changed, update the // loading bar progress if (lastRemainingItems != actualRemainingItems) { // Update its progress by the difference between the remaining item values for (int i = 0; i < (lastRemainingItems - actualRemainingItems); i++) { loadingManager.Progress(); } } } else { // Otherwise, destroy and dereference the loading bar if it still exists if (loadingManager != null) { loadingManager.DestroyLoading(); loadingManager = null; } // Then, go back to playing the video SetPlaybackState(PlaybackState.PlayingFile); } } }
void Update() { // If the system is still waiting for data from the kinect manager, set the recording // state to no data if not already done so and return if (!KinectManager.IsDataAvailable()) { SetRecordingState(RecordingState.NoData); return; } // Otherwise, data is available, so if the current state indicates that the system is // waiting for data, the state can now be changed to no file if (currentRecordingState == RecordingState.NoData) { SetRecordingState(RecordingState.NoFile); } else if (currentRecordingState == RecordingState.StopRecording) { // If the recording manager is still processing, check if the loading bar can be updated if (recordingManager.IsProcessingFile) { // Get the loading bar remaining items and the actual number of remaining items in // the recording manager queue int lastRemainingItems = loadingManager.RemainingDataItems; int actualRemainingItems = recordingManager.GetDataQueueCount(); // If the number of items in the processing queue has changed, update the // loading bar progress if (lastRemainingItems != actualRemainingItems) { // Update its progress by the difference between the remaining item values for (int i = 0; i < (lastRemainingItems - actualRemainingItems); i++) { loadingManager.Progress(); } // Once the last data item in the queue has been passed to the background thread, // the loading bar will say 100%, but the scene will not unload just yet because // the last data item is being processed and then the file info will be processed. // When this happens, change the loading bar message to indicate that it is now // saving the file info and opening the recording in playback if (actualRemainingItems == 0) { loadingManager.ChangeLoadingMessage(openingPlaybackMessage); } } } else { // Otherwise, the file has finished saving, so if the loading manager reference // points to an instantiated prefab, destroy the game object and nullify the cached // reference if (loadingManager != null) { loadingManager.DestroyLoading(); loadingManager = null; } // Then, save the file name in player prefs temporarily so that playback can access it // and load the playback scene PlayerPrefs.SetString("fileName", currentOpenFileName); SceneManager.LoadScene("Playback"); } } }