void Start() { // If initialization is incomplete if (GameObject.Find ("PermanentObjects") == null) { SceneManager.LoadScene ("sc0_pom"); return; } pom = GameObject.Find ("PermanentObjects").GetComponent <PermanentObjectsManager> (); drawingArea = GameObject.Find ("DrawingCanvas").GetComponentsInChildren <Transform>()[2]; foreach (Transform child in drawingArea) { if (child.name == "Background") background = child; if (child.name == "MainPanel") mainPanel = child; if (child.name == "ComputeSettingsPanel") computeSettingsPanel = child; if (child.name == "LoadSettingsPanel") loadSettingsPanel = child; if (child.name == "LoadingBarPanel") loadingBarPanel = child; } mainTabManager = mainPanel.GetComponent <TabManager>(); computeSettingsManager = computeSettingsPanel.GetComponent <ComputeSettingsManager>(); loadSettingsManager = loadSettingsPanel.GetComponent <LoadSettingsManager>(); loadingBarManager = loadingBarPanel.GetComponent <LoadingBarManager>(); mainTabManager.Initialize (); computeSettingsManager.Initialize (); loadSettingsManager.Initialize (); loadingBarManager.Initialize (); tab1 = mainTabManager.GetTab (1); tab2 = mainTabManager.GetTab (2); foreach (Transform child in tab1) { if (child.name == "Formula_dropdown") formula_dropdown = child.GetComponent <Dropdown> (); if (child.name == "FooterButtonsSection") dropdownComputeFooter = child; if (child.name == "FooterVisualizationSection") { visualizationComputeFooter = child; foreach (Transform child2 in visualizationComputeFooter) { if (child2.name == "DisplayArea") formula_text = child2.GetComponentsInChildren <Text> () [0]; } } } foreach (Transform child in tab2) { if (child.name == "FileName") fileName_text = child.GetComponentsInChildren <Text> () [0]; } mainPanel.gameObject.SetActive (true); computeSettingsPanel.gameObject.SetActive (false); loadSettingsPanel.gameObject.SetActive (false); loadingBarPanel.gameObject.SetActive (false); dropdownComputeFooter.gameObject.SetActive (true); visualizationComputeFooter.gameObject.SetActive (false); state_onSettings = false; state_onLoadingBar = false; state_onVisualization = false; foreach (string name in Enum.GetNames(typeof(Formula.Function))) { if (name != "None") { formula_dropdown.options.Add (new Dropdown.OptionData () { text = name }); } } if (pom.names.Length != 0) { computeSettingsManager.SetTo (pom); formula_dropdown.value = ((int)pom.function == 0) ? 1 : 0; formula_dropdown.value = (int)pom.function; loadSettingsManager.SetTo (pom); } else { formula_dropdown.value = 1; formula_dropdown.value = 0; } OnUpdateFormulaText (); }
private void SetPlaybackState(PlaybackState newState) { // If the playback state has not changed, return if (currentPlaybackState == newState) { return; } // Otherwise, make changes to the UI based on the new state switch (newState) { // For the no open file state, disable all playback controls apart from the home button and the // open file button case PlaybackState.NoOpenFile: SetUiStates(true, true, false, false, false, false, false); break; // If the open file button is selected, open the panel with this set of controls visible and disable // the toolbar buttons apart from the home button. Also, disable the playback controls whilst the // panel is open case PlaybackState.OpenFileSelected: SetUiStates(true, false, false, true, true, false, false); if (playbackManager.IsPlaying) { playbackManager.StopPlaying(); } // Remove this line once download is implemented DownloadButton.interactable = false; break; // Downloading file state not implemented case PlaybackState.DownloadingFile: break; // If the user has selected a file to open, disable all UI controls whilst it loads the file info case PlaybackState.OpeningFileInfo: SetUiStates(false, false, false, false, false, false, false); // Indicate to the playback manager that it should begin opening the specified file // and add a event handler to the file info finished loading event playbackManager.OpenFile(currentOpenFileName); // Instantiate a loading bar prefab and get a reference to its manager class GameObject loadingBar = Instantiate(LoadingBar, gameObject.transform) as GameObject; loadingManager = loadingBar.GetComponent <LoadingBarManager>(); // Then, initialise it with 1 data item and the loading file info message before showing // it in the canvas loadingManager.InitialiseLoading(loadingFileInfoMessage, 1); loadingManager.ShowLoading(); // Finally, set the file info ready flag to false fileInfoReady = false; break; // If the file info has been loaded in and chunk data is now being loaded in, disable all UI // controls whilst this happens case PlaybackState.OpeningFileData: SetUiStates(false, false, false, false, false, false, false); // An instance of the loading bar should be available with a reference to its manager // cached, so reinitialise the loading bar with the new chunk queue data loadingManager.InitialiseLoading(loadingChunksMessage, playbackManager.GetChunksToLoadCount()); loadingManager.ShowLoading(); break; // If the user has opened a file and they are playing it or they have paused it, everything will be enabled // apart from the options panel case PlaybackState.PausedFile: SetUiStates(true, true, true, false, false, false, true); if (playbackManager.IsPlaying) { playbackManager.StopPlaying(); } sliderManager.StopPlaying(); break; case PlaybackState.PlayingFile: SetUiStates(true, true, true, false, false, false, true); if (!playbackManager.IsPlaying) { playbackManager.StartPlaying(); } sliderManager.StartPlaying(); break; // If the file is buffering, everything should be disabled to prevent errors from occurring case PlaybackState.BufferingFile: SetUiStates(false, false, false, false, false, false, false); sliderManager.StopPlaying(); // Instantiate a loading bar prefab and get a reference to its manager class GameObject bufferingBar = Instantiate(LoadingBar, gameObject.transform) as GameObject; loadingManager = bufferingBar.GetComponent <LoadingBarManager>(); // Then, initialise it with the chunks to load count from the playback manager and the // buffering messgae before showing it in the canvas loadingManager.InitialiseLoading(bufferingMessage, playbackManager.GetChunksToLoadCount()); loadingManager.ShowLoading(); break; // If the upload file button is selected, open the panel with this set of controls visible and disable // the toolbar buttons apart from the home button. Also, disable the playback controls whilst the // panel is open case PlaybackState.UploadFileSelected: SetUiStates(true, false, false, true, false, true, false); if (playbackManager.IsPlaying) { playbackManager.StopPlaying(); } // Remove this line once upload is implemented UploadRecordingButton.interactable = false; break; // Uploading file state not implemented case PlaybackState.UploadingFile: break; } // Store the new state currentPlaybackState = newState; }
private void SetRecordingState(RecordingState newState) { // If the recording state has not changed, return if (currentRecordingState == newState) { return; } // Otherwise, make changes to the UI based on the new state switch (newState) { // For the no data state, disable all recording controls apart from the home button case RecordingState.NoData: SetUiStates(true, false, false, false, false); break; // If data is coming in but no file has been created, only enable the home button and // new recording button case RecordingState.NoFile: SetUiStates(true, true, false, false, false); break; // If the user has indicated that they wish to create a new file, disable all controls apart // from the home button and options panel case RecordingState.InputNewFile: SetUiStates(true, false, true, false, false); break; // If the user has created a file and is ready to record, disable the panel but reenable // everything else case RecordingState.FileReady: SetUiStates(true, true, false, true, false); break; // If the user has begun recording, disable everything apart from the recording controls and // change their appearence to indicate recording case RecordingState.RecordingData: SetUiStates(false, false, false, true, true); // Also indicate to the recording manager that it should start recording data recordingManager.StartRecording(currentOpenFileName); break; // Once the user has stopped recording, keep everything disabled but also change the recording // button state and then disable it as well case RecordingState.StopRecording: SetUiStates(false, false, false, false, false); // Also indicate to the recording manager that it should stop recording data recordingManager.StopRecording(); // Finally, if the recording manager is still processing the file, instantiate the loading // bar prefab and cache a reference to its loading manager component. Then, initialise it // with the loading message and show the component. Finally, store the total data items left // using the recording manager data queue count if (recordingManager.IsProcessingFile) { GameObject loadingBar = Instantiate(LoadingBar, gameObject.transform) as GameObject; loadingManager = loadingBar.GetComponent <LoadingBarManager>(); loadingManager.InitialiseLoading(loadingFileMessage, recordingManager.GetDataQueueCount()); loadingManager.ShowLoading(); } break; } // Store the new state currentRecordingState = newState; }
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"); } } }