private void FillTierMenu() { foreach (var tier in _allTiers) { GameObject goTierMenuButton = Instantiate(tierMenuButton) as GameObject; TierMenuButton tierButton = goTierMenuButton.GetComponent <TierMenuButton>(); tierButton.buttonText.text = tier.tierName; tierButton.buttonNumber.text = (_allTiers.IndexOf(tier) + 1).ToString(); tierButton.GetComponent <Button>().interactable = tier.isInteractable; // Set the image regarding interactability goTierMenuButton.GetComponent <Image>().sprite = Resources.Load <Sprite>("Images/TierMenu/" + tier.fileName + "1"); if (!tier.isInteractable) { tierButton.buttonBgImage.color = MainColors.WhiteTransparent(110); tierButton.buttonBgImage.sprite = Resources.Load <Sprite>("Images/LockTier3"); } tierButton.GetComponent <Button>().onClick.AddListener(() => { PlayerPrefs.SetInt("CurrentTierId", _allTiers.IndexOf(tier)); PlayerPrefs.SetString("CurrentTierFileName", tier.fileName); SceneManager.LoadScene("MainMenu"); }); goTierMenuButton.transform.SetParent(spacerHorizontal, false); } }
// Use this for initialization void Start() { KinectManager = GameObject.Find("KinectManager"); _kinectManager = KinectManager.GetComponent <KinectManager>(); if (_kinectManager.displayUserMapSmall) { _kinectManager.displayUserMapSmall = false; } Color32 green = MainColors.GreenLight(); foreach (var side in UserDataObject.GetCurrentExercise().sides) { if (side.accomplished) { if (side.direction == "Left") { toggleLeft.isOn = true; imageToggleLeftBG.sprite = Resources.Load <Sprite>("Images/Toggle"); imageToggleLeftBG.color = MainColors.ToggleIsOn(); imageToggleLeftBGShadow.color = MainColors.SideSelectionShadow(); } else if (side.direction == "Right") { toggleRight.isOn = true; imageToggleRightBG.sprite = Resources.Load <Sprite>("Images/Toggle"); imageToggleRightBG.color = MainColors.ToggleIsOn(); imageToggleRightBGShadow.color = MainColors.SideSelectionShadow(); } } } exerciseLeftButton.onClick.AddListener(() => { PlayerPrefs.SetInt("CurrentSideId", 1); LoadNextScene("Left"); }); exerciseRightButton.onClick.AddListener(() => { PlayerPrefs.SetInt("CurrentSideId", 0); LoadNextScene("Right"); }); exerciseName.text = UserDataObject.GetCurrentExerciseName().ToUpper(); }
void Start() { // ----------------------------------------- // ------------ INITIALIZATIONS ------------ // ----------------------------------------- // Reference to exercise data of current user // _currentExerciseData = UserDataObject.currentUser.exerciseData[PlayerPrefs.GetInt("CurrentExerciseId")]; _currentExerciseData = UserDataObject.GetCurrentExercise(); // Todo no functionality yet --> track overall time for exercise or overall time needed for rep tempTimer = 0f; // ----------------------------------------- // ------------- UI COMPONENTS ------------- // ----------------------------------------- // Execution time _attemptExecutionTime = new Stopwatch(); // Duration donut imageRingTime.GetComponent <Image>(); counterText.GetComponent <Text>(); imageRingTime.type = Image.Type.Filled; imageRingTime.fillMethod = Image.FillMethod.Radial360; imageRingTime.fillAmount = 0f; // Colors for duration donut red = MainColors.Red(); darkOrange = MainColors.Orange(); yellow = MainColors.Yellow(); green = MainColors.GreenDark(); // Slider for progress // slider = slider.GetComponent<Slider>(); Debug.Log("isProgressGesture: " + _currentExerciseData.isProgressGesture); // if (!_currentExerciseData.isProgressGesture) // { // progressGroup.SetActive(false); // } }
void FillMenu() { // For current tier create tier basics, exercises and summary button //Text for the tier // _tierText.text = tier.tierName; // Instantiate a button gameobject from a prefab GameObject tierBasicGameObjectButton = Instantiate(exerciseLevelButton) as GameObject; // Get the script for the button to set its values ExerciseLevelButton tierBasicButton = tierBasicGameObjectButton.GetComponent <ExerciseLevelButton>(); tierBasicButton.buttonText.text = "Introduction"; // Set image for basic information button tierBasicGameObjectButton.GetComponent <Image>().sprite = Resources.Load <Sprite>("Images/Information/" + _currTier.fileName); tierBasicButton.bgImage.sprite = Resources.Load <Sprite>("Images/Information/InformationIcon"); tierBasicButton.bgImage.color = new Color32(255, 255, 255, 20); // If tier unlocked --> unlock the basic information for this tier if (_currTier.isInteractable) { tierBasicButton.unlocked = 1; tierBasicButton.GetComponent <Button>().interactable = true; } else { tierBasicButton.unlocked = 0; tierBasicButton.GetComponent <Button>().interactable = false; tierBasicGameObjectButton.GetComponent <Image>().color = new Color32(150, 150, 150, 255); } // Add listener for the button to load the appropriate scene tierBasicButton.GetComponent <Button>().onClick.AddListener(() => { SceneManager.LoadScene("TierInfo"); }); // Append the basic information button to the exercise spacer tierBasicGameObjectButton.transform.SetParent(spacerHorizontal, false); // Manage exercise data in the current tier foreach (var exercise in _currTier.exercises) { // Instantiate a button gameobject from a prefab GameObject gameObjectButton = Instantiate(exerciseLevelButton) as GameObject; // Get the script for the button to set its values ExerciseLevelButton button = gameObjectButton.GetComponent <ExerciseLevelButton>(); // Set the values regarding the current exercise button.buttonText.text = exercise.exerciseName; button.unlocked = exercise.unlocked; button.GetComponent <Button>().interactable = exercise.isInteractable; // Set image for exercise button // Debug.Log("Images/" + tier.fileName + "/" + exercise.fileName); button.bgImage.sprite = Resources.Load <Sprite>("Images/" + _currTier.fileName + "/" + exercise.fileName); // If exercise locked if (!exercise.isInteractable) { button.bgImage.color = MainColors.WhiteTransparent(3); gameObjectButton.GetComponent <Image>().sprite = Resources.Load <Sprite>("Images/LockExercise2"); gameObjectButton.GetComponent <Image>().color = MainColors.Grey(); } // Fill progress in button foreach (var side in exercise.sides) { if (side.accomplished) { button.progressImage.fillAmount += 0.5f; } } // Add listener for the button to set the PP and load the appropriate scene button.GetComponent <Button>().onClick.AddListener(() => { PlayerPrefs.SetInt("CurrentExerciseId", _currTier.exercises.IndexOf(exercise)); SceneManager.LoadScene("ExerciseSideSelection"); }); // Highlight current exercise if (PlayerPrefs.GetInt("CurrentExerciseId") == _currTier.exercises.IndexOf(exercise)) { Debug.Log("Current exercise to highlight: " + exercise.exerciseName); } // Append the exercise button to the exercise spacer gameObjectButton.transform.SetParent(spacerHorizontal, false); } // Instantiate a button gameobject from a prefab GameObject tierSumGameObjectButton = Instantiate(exerciseLevelButton) as GameObject; // Get the script for the button to set its values ExerciseLevelButton tierSumButton = tierSumGameObjectButton.GetComponent <ExerciseLevelButton>(); // Set the values regarding the summary tierSumButton.buttonText.text = "Summary"; // Set image for summary button tierSumGameObjectButton.GetComponent <Image>().sprite = Resources.Load <Sprite>("Images/Summary/SummaryIcon"); tierSumButton.bgImage.sprite = Resources.Load <Sprite>("Images/Summary/SummaryTierBG"); tierSumButton.bgImage.color = new Color32(255, 255, 255, 15); // If last exercise accomplished --> unlock the summary for this tier if (_currTier.exercises.Last().accomplished) { tierSumButton.unlocked = 1; tierSumButton.GetComponent <Button>().interactable = true; } else { tierSumButton.unlocked = 0; tierSumButton.GetComponent <Button>().interactable = false; tierSumButton.GetComponent <Image>().color = new Color32(150, 150, 150, 255); } // Add listener for the button to load the appropriate scene tierSumButton.GetComponent <Button>().onClick.AddListener(() => { SceneManager.LoadScene("TierSummary"); }); // Append the summary button to the exercise spacer tierSumGameObjectButton.transform.SetParent(spacerHorizontal, false); // SaveData(); }
private void OnGestureDetected(object sender, GestureEventArgs e, int bodyIndex) { var isDetected = e.IsBodyTrackingIdValid && e.IsGestureDetected; if (_kinectManager && _kinectManager.IsInitialized() && _kinectManager.IsUserDetected()) { long userId = _kinectManager.GetPrimaryUserID(); if (_kinectManager.IsJointTracked(userId, (int)_jointFootRight) && _kinectManager.IsJointTracked(userId, (int)_jointFootLeft)) { float jointPosFootLeftHeight = _kinectManager.GetJointKinectPosition(userId, (int)_jointFootLeft).y; float jointPosFootRightHeight = _kinectManager.GetJointKinectPosition(userId, (int)_jointFootRight).y; float jointPosFootLeftDepth = _kinectManager.GetJointKinectPosition(userId, (int)_jointFootLeft).z; float jointPosFootRightDepth = _kinectManager.GetJointKinectPosition(userId, (int)_jointFootRight).z; // if ((jointPosFootLeftDepth > jointPosFootRightDepth - _footDepthTolerance) && (jointPosFootLeftDepth < jointPosFootRightDepth + _footDepthTolerance) && // (jointPosFootRightDepth > jointPosFootLeftDepth - _footDepthTolerance) && (jointPosFootRightDepth < jointPosFootLeftDepth + _footDepthTolerance)) // { // _inStartingPosition = true; // } // else if (!_bothFeetUp) // { // _inStartingPosition = false; // } _inStartingPosition = true; rightFootHeightText.text = "R Height: " + jointPosFootRightHeight.ToString(); leftFootHeightText.text = "L Height: " + jointPosFootLeftHeight.ToString(); rightFootDepthText.text = "R Depth: " + jointPosFootRightDepth.ToString(); leftFootDepthText.text = "L Depth: " + jointPosFootLeftDepth.ToString(); // Check if in starting position and foot currentFootHeight is between initialFootHeight + difference tolerance if (_inStartingPosition && (jointPosFootLeftHeight > _initialStartingHeightLeft + _startingHeightDifference) && (jointPosFootRightHeight > _initialStartingHeightRight + _startingHeightDifference)) { _bothFeetUp = true; } else { _bothFeetUp = false; } } } // Check positions of joints of current exercise foreach (var check in UserDataObject.GetCurrentChecksArray()) { if (_exerciseExecutionValidationManager.GetMethodToCheck(check)) { checkItemList[Array.IndexOf(UserDataObject.GetCurrentChecksArray(), check)].checkToggle.isOn = true; checkItemList[Array.IndexOf(UserDataObject.GetCurrentChecksArray(), check)].checkImage.sprite = Resources.Load <Sprite>("Images/Toggle"); checkItemList[Array.IndexOf(UserDataObject.GetCurrentChecksArray(), check)].checkImage.color = MainColors.ToggleIsOn(); _methodCheckedArray[Array.IndexOf(UserDataObject.GetCurrentChecksArray(), check)] = true; } else { checkItemList[Array.IndexOf(UserDataObject.GetCurrentChecksArray(), check)].checkToggle.isOn = false; checkItemList[Array.IndexOf(UserDataObject.GetCurrentChecksArray(), check)].checkImage.sprite = Resources.Load <Sprite>("Images/IconNotChecked"); checkItemList[Array.IndexOf(UserDataObject.GetCurrentChecksArray(), check)].checkImage.color = MainColors.White(); _methodCheckedArray[Array.IndexOf(UserDataObject.GetCurrentChecksArray(), check)] = false; _checksPassed = false; } // Debug.Log(_exerciseExecutionValidationManager.GetMethodToCheck(check)); armsUpText.text = _checksPassed.ToString(); } bothFeetUpText.text = "DIFF: " + _startingHeightDifference + " |UP: " + _bothFeetUp + "| INPOS: " + _inStartingPosition; if (_exerciseExecutionValidationManager.LeftFootOnLine() || _exerciseExecutionValidationManager.RightFootOnLine()) { if (CanvasHandCursor.activeSelf) { _interactionManager.enabled = false; CanvasHandCursor.gameObject.SetActive(false); } } // Discrete Gesture tracking if ((e.GestureType == GestureType.Discrete)) { _gestureAccuracy = e.DetectionConfidence; for (int i = 0; i < _methodCheckedArray.Length; i++) { if (_methodCheckedArray[i] == false) { _gestureAccuracy -= 0.1f; } testText.text = _gestureAccuracy.ToString(); } if (_gestureAccuracy > 1.0f) { _gestureAccuracy = 1.0f; } _durationManager.SetProgress(_gestureAccuracy); if (GestureDetected(_gestureAccuracy, 0.4f, 1f) && _bothFeetUp) { if (CanvasHandCursor.activeSelf) { _interactionManager.enabled = false; CanvasHandCursor.gameObject.SetActive(false); } _durationManager.StartTimer(); if (MinTimeReached()) { audioSuccess.Play(); if (_currentRepetition == UserDataObject.GetCurrentRepetitionsArray().Last()) { Debug.Log("LASTREP"); successMainText.text = "Exercise finished!"; successSubText.text = "Preparing next exercise"; StartCoroutine("StartLastAnimateSuccess"); } else { StartCoroutine("StartAnimateSuccess"); } } confidenceIterator++; _currentRepetitionConfidence += _gestureAccuracy * 100; // testText.text = "if DISCRETE: " + e.IsGestureDetected.ToString() + " " + _gestureAccuracy; } else { if (_durationManager.IsTimerRunning() && _durationManager.GetlatestTimeInSeconds() <= _currentRepetition.minTime) { audioFail.Play(); Debug.Log("Activate handcursor"); // if (!CanvasHandCursor.activeSelf) // { // CanvasHandCursor.gameObject.SetActive(true); // _interactionManager.enabled = true; // } } if (_durationManager.IsTimerRunning()) { attemptsIterator++; } _durationManager.StopTimer(); // if tracked time is greater than given time of the repetition if (_durationManager.GetlatestTimeInSeconds() >= _currentRepetition.minTime) { _repsIterator += 1; ToggleAndCheckRepetition(); } // testText.text = "else DISCRETE: " + e.IsGestureDetected.ToString() + " " + _gestureAccuracy; } // testText.text = "DISCRETE: " + e.IsGestureDetected.ToString() + " " + e.DetectionConfidence; } else if ((e.GestureType == GestureType.Continuous)) { _gestureAccuracy = e.Progress; for (int i = 0; i < _methodCheckedArray.Length; i++) { if (_methodCheckedArray[i] == false) { _gestureAccuracy -= 0.1f; } testText.text = _gestureAccuracy.ToString(); } if (_gestureAccuracy > 1.0f) { _gestureAccuracy = 1.0f; } _durationManager.SetProgress(_gestureAccuracy); // if (_thirdCheckpoint) // { // _durationManager.StartTimer(); // // confidenceIterator++; // _currentRepetitionConfidence += e.Progress * 100; // // if (e.Progress <= 0.4f) // { // Debug.Log(e.Progress); // if (_durationManager.IsTimerRunning()) // { // _currentRepetition.attempts++; // Debug.Log("CURRENT REPETITION ATTEMPT: " + _currentRepetition.attempts); // // } // // _durationManager.StopTimer(); // // _thirdCheckpoint = false; // // // if tracked time is greater than given time of the repetition // if (_durationManager.GetlatestTimeInSeconds() >= _currentRepetition.minTime) // { // ToggleAndCheckRepetition(); // } // } // } // else // { // if (_secondCheckpoint && GestureDetected(e.Progress, 0.7f, 1f)) // { // _thirdCheckpoint = true; // } // else if (_firstCheckpoint && GestureDetected(e.Progress, 0.4f, 0.7f)) // Debug.Log(_bothFeetUp + " | " + _gestureAccuracy + " | " + e.Progress + " | "+ GestureDetected(_gestureAccuracy, 0.7f, 1f) + " | " + GestureDetected(e.Progress, 0.7f, 1f)); if (GestureDetected(_gestureAccuracy, _progressMinConfidence, 1f) && _bothFeetUp) { if (CanvasHandCursor.activeSelf) { _interactionManager.enabled = false; CanvasHandCursor.gameObject.SetActive(false); } _durationManager.StartTimer(); if (MinTimeReached()) { audioSuccess.Play(); if (_currentRepetition == UserDataObject.GetCurrentRepetitionsArray().Last()) { Debug.Log("LASTREP"); successMainText.text = "Exercise finished!"; successSubText.text = "Preparing next exercise"; StartCoroutine("StartLastAnimateSuccess"); } else { StartCoroutine("StartAnimateSuccess"); } } confidenceIterator++; _currentRepetitionConfidence += _gestureAccuracy * 100; // testText.text = "if CONTINUOUS: " + _gestureAccuracy; } else { if (_durationManager.IsTimerRunning() && _durationManager.GetlatestTimeInSeconds() <= _currentRepetition.minTime) { audioFail.Play(); Debug.Log("Activate handcursor"); // if (!CanvasHandCursor.activeSelf) // { // CanvasHandCursor.gameObject.SetActive(true); // _interactionManager.enabled = true; // } } if (_durationManager.IsTimerRunning()) { attemptsIterator++; Debug.Log("CURRENT REPETITION ATTEMPT: " + attemptsIterator); _durationManager.StopTimer(); } // if tracked time is greater than given time of the repetition if (_durationManager.GetlatestTimeInSeconds() >= _currentRepetition.minTime) { _repsIterator += 1; ToggleAndCheckRepetition(); } // testText.text = "else CONTINUOUS: " + _gestureAccuracy; } // } } }