// Use this for initialization void Start() { KinectManager = GameObject.Find("KinectManager"); _kinectManager = KinectManager.GetComponent <KinectManager>(); if (!_kinectManager.displayUserMapSmall) { _kinectManager.displayUserMapSmall = true; } _allTiers = UserDataObject.GetAllTiers(); FillTierMenu(); }
private void ToggleAndCheckRepetition() { StopTracking(); _minTimeAlreadyReached = false; _bothFeetUp = false; _inStartingPosition = false; textReps.text = "Reps " + _repsIterator + "/" + UserDataObject.GetCurrentRepetitionsArray().Length; Debug.Log("ACCOMPLISHED REPETITION"); Debug.Log("Activate Handcursor"); // if (!CanvasHandCursor.activeSelf) // { // CanvasHandCursor.gameObject.SetActive(true); // _interactionManager.enabled = true; // } // Save the time and confidence for the current repetition _currentRepetition.userTime = _durationManager.GetlatestTimeInSeconds(); _currentRepetition.confidence = _currentRepetitionConfidence / confidenceIterator; _currentRepetition.attempts = attemptsIterator; Debug.Log("Repetition time: " + _currentRepetition.userTime + " || confidence: " + _currentRepetition.confidence); // Toggle current repetition _currentRepetition.accomplished = true; _toggleArray[Array.IndexOf(UserDataObject.GetCurrentRepetitionsArray(), _currentRepetition)].isOn = true; // Check if last repetition if (_currentRepetition == UserDataObject.GetCurrentRepetitionsArray().Last()) { // Exercise and side accomplished _currentExerciseData.accomplished = true; UserDataObject.GetCurrentSide().accomplished = true; // Set values for side attempts, confidence, and time regarding repetitions UserDataObject.GetCurrentSide().userTime = 0.0f; UserDataObject.GetCurrentSide().confidence = 0.0f; UserDataObject.GetCurrentSide().attempts = 0; foreach (var repetition in UserDataObject.GetCurrentRepetitionsArray()) { UserDataObject.GetCurrentSide().userTime += repetition.userTime; UserDataObject.GetCurrentSide().confidence += repetition.confidence; UserDataObject.GetCurrentSide().attempts += repetition.attempts; } // Set the avg usertime and confidence for the current side UserDataObject.GetCurrentSide().userTime /= UserDataObject.GetCurrentRepetitionsArray().Length; UserDataObject.GetCurrentSide().confidence /= UserDataObject.GetCurrentRepetitionsArray().Length; // Set values for exercise attempts, confidence, and time regarding sides sideAccomplishedCounter = 0; _currentExerciseData.confidence = 0.0f; _currentExerciseData.userTime = 0.0f; _currentExerciseData.attempts = 0; foreach (var side in UserDataObject.GetCurrentExercise().sides) { if (side.accomplished) { sideAccomplishedCounter++; _currentExerciseData.confidence += side.confidence; _currentExerciseData.userTime += side.userTime; _currentExerciseData.attempts += side.attempts; } } // Set the avg usertime and confidence for the current exercise _currentExerciseData.userTime /= sideAccomplishedCounter; _currentExerciseData.confidence /= sideAccomplishedCounter; // If all sides accomplished bool allSidesAccomplished = true; SideData nextSide; foreach (var side in _currentExerciseData.sides) { if (side.accomplished == false) { allSidesAccomplished = false; } } if (allSidesAccomplished) { // If last exercise --> accomplish current tier Debug.Log("PlayerPrefs.GetInt(CurrentExerciseId)" + PlayerPrefs.GetInt("CurrentExerciseId")); Debug.Log("UserDataObject.GetCurrentTierErcisesLength()" + UserDataObject.GetCurrentTierErcisesLength()); if (PlayerPrefs.GetInt("CurrentExerciseId") == UserDataObject.GetCurrentTierErcisesLength() - 1) { // todo All exercises accomplished congratulations or so UserDataObject.GetCurrentTier().accomplished = true; // If last tier reached --> do nothing if (PlayerPrefs.GetInt("CurrentTierId") == UserDataObject.GetAllTiers().Count - 1) { } else // If not last tier --> unlock next tier { TierData nextTier = UserDataObject.GetNextTier(); nextTier.isInteractable = true; } } else // If not last exercise --> unlock next exercise { ExerciseData nextExerciseData = UserDataObject.GetNextExercise(); nextExerciseData.isInteractable = true; nextExerciseData.unlocked = 1; // UserDataObject.currentUser.exerciseData[PlayerPrefs.GetInt("CurrentExerciseId") + 1].isInteractable = true; // UserDataObject.currentUser.exerciseData[PlayerPrefs.GetInt("CurrentExerciseId") + 1].unlocked = 1; } } // Save data to user json file SaveCurrentExerciseData(); // Load the summary scene StartCoroutine(loadSummaryScene()); } // If not last repetition --> current repetition is next repetition else { _currentRepetition = UserDataObject.GetCurrentRepetitionsArray()[Array.IndexOf(UserDataObject.GetCurrentRepetitionsArray(), _currentRepetition) + 1]; PlayerPrefs.SetInt("CurrentRepetitionId", Array.IndexOf(UserDataObject.GetCurrentRepetitionsArray(), _currentRepetition)); startTrackingAgain = true; Debug.Log("STARTTRAKCINGAGAIN" + startTrackingAgain); // Save data to user json file SaveCurrentExerciseData(); } Debug.Log("-----------------------"); Debug.Log("TOGGLEANDSAVE"); Debug.Log("-----------------------"); // Reset all variables needed for next repetition _currentRepetitionConfidence = 0; confidenceIterator = 0; attemptsIterator = 0; _durationManager.ResetlatestTimeInSeconds(); _durationManager.ResetProgress(); _firstCheckpoint = false; _secondCheckpoint = false; pufferList.Clear(); if (startTrackingAgain) { StartCoroutine("StartTracking"); // StartCoroutine("RewindAnimateSuccess"); } }