예제 #1
0
 public void LoadTierMenuScene()
 {
     if (!UserDataObject.GetCurrentExercise().isInteractable)
     {
         UserDataObject.GetCurrentExercise().isInteractable = true;
         UserDataObject.GetCurrentExercise().unlocked       = 1;
     }
     SceneManager.LoadScene("TierMenu");
 }
    // 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();
    }
예제 #3
0
    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);
//		}
    }
예제 #4
0
    // Use this for initialization
    void Start()
    {
        // Enable handcursor in execution mode
        KinectManager = GameObject.Find("KinectManager");
//		KinectManager.GetComponent<InteractionManager>().showHandCursor = true;

        _kinectManager = KinectManager.GetComponent <KinectManager>();
        if (!_kinectManager.displayUserMapSmall)
        {
            _kinectManager.displayUserMapSmall = true;
        }

        Debug.Log("Enable handcursor");

        imageConfidenceList  = new List <Image>();
        imageTimeList        = new List <Image>();
        imageAttemptsList    = new List <Image>();
        imageTimeValue       = new List <float>();
        imageConfidenceValue = new List <float>();
        imageAttemptsValue   = new List <float>();

        // Set the title of current exercise
        exerciseNameText.text = UserDataObject.GetCurrentExerciseName().ToUpper();
        textStandingLeg.text  = UserDataObject.GetCurrentSide().direction;

        // Output summary data from exercise
        OutputData();

        _currentExercise = UserDataObject.GetCurrentExercise();
        _lastExercise    = UserDataObject.GetLastTierExercise();

        Debug.Log("GetCurrentExercise: " + UserDataObject.GetCurrentExercise().fileName);
        Debug.Log("GetLastTierExercise " + UserDataObject.GetLastTierExercise().fileName);
        Debug.Log(PlayerPrefs.GetInt("CurrentExerciseId"));

        // Check if a side is not accomplished
        foreach (var side in _currentExercise.sides)
        {
            Debug.Log(side.direction);
            Debug.Log(side.accomplished);
            if (side.accomplished == false)
            {
                sideNotAccomplished = true;
            }
        }

        // Not last exercise --> load following exercise
        if (_currentExercise != _lastExercise || sideNotAccomplished)
        {
            Debug.Log("any sideNotAccomplished? : " + sideNotAccomplished);
            if (sideNotAccomplished)
            {
                buttonNextExercise.GetComponentInChildren <Text>().text = "Next Side";
                buttonNextExercise.onClick.AddListener(() =>
                {
                    Debug.Log("currentside id : " + PlayerPrefs.GetInt("CurrentSideId"));

                    if (PlayerPrefs.GetInt("CurrentSideId") == 0)
                    {
                        Debug.Log("LOAD LEFT");
                        PlayerPrefs.SetInt("CurrentSideId", 1);
                        LoadNextScene("Left");
                    }
                    else if (PlayerPrefs.GetInt("CurrentSideId") == 1)
                    {
                        Debug.Log("LOAD RIGHT");
                        PlayerPrefs.SetInt("CurrentSideId", 0);
                        LoadNextScene("Right");
                    }
                });
            }
            else             // all sides accomplished --> load next exercise
            {
                PlayerPrefs.SetInt("CurrentExerciseId", PlayerPrefs.GetInt("CurrentExerciseId") + 1);
                buttonNextExercise.onClick.AddListener(() =>
                {
                    SceneManager.LoadScene("ExerciseSideSelection");
                });
            }
        }
        else         // all exercises completed --> load TierMenu
        {
            buttonNextExercise.GetComponentInChildren <Text>().text = "Level Summary";
            buttonNextExercise.onClick.AddListener(() =>
            {
                SceneManager.LoadScene("TierSummary");
            });
        }
    }
    // Use this for initialization
    void Start()
    {
        // -----------------------------------------
        // ------------ INITIALIZATIONS ------------
        // -----------------------------------------

        CanvasHandCursor = GameObject.Find("CanvasHandCursor");

        // Disable handcursor in execution mode TODO all disable in testmode, enable in production
        bodyManager = GameObject.Find("BodyManager");

        KinectManager = GameObject.Find("KinectManager");
        if (KinectManager == null)
        {
            return;
        }

        _kinectManager      = KinectManager.GetComponent <KinectManager>();
        _interactionManager = _kinectManager.GetComponent <InteractionManager>();

        if (CanvasHandCursor.activeSelf)
        {
            _interactionManager.enabled = false;
            CanvasHandCursor.gameObject.SetActive(false);
        }

        Debug.Log("IsUserDetected: " + _kinectManager.IsUserDetected());


        _exerciseExecutionValidationManager = ExerciseExecutionValidationManager.GetComponent <ExerciseExecutionValidationManager>();

        // Reference to exercise data of current user
//		_currentExerciseData = UserDataObject.currentUser.exerciseData[PlayerPrefs.GetInt("CurrentExerciseId")];
        _currentExerciseData = UserDataObject.GetCurrentExercise();
        _lastExercise        = UserDataObject.GetLastTierExercise();

        // Duration manager
        _durationManager = durationManager.GetComponent <DurationManager>();

        _minTimeAlreadyReached = false;
        _repsIterator          = 0;

        _methodCheckedArray = new bool[UserDataObject.GetCurrentChecksArray().Length];

        // -----------------------------------------
        // ------------- UI COMPONENTS -------------
        // -----------------------------------------

        // Exercise name
        titleText.text       = UserDataObject.GetCurrentExerciseName().ToUpper();
        standingLegText.text = UserDataObject.GetCurrentSide().direction;
        successPanel         = successPanel.GetComponent <CanvasGroup>(); // TODO implement success animation for rep

        foreach (var check in UserDataObject.GetCurrentChecksArray())
        {
            GameObject gameObjectCheckItem = Instantiate(checkItem);
            CheckItem  currentCheckItem    = gameObjectCheckItem.GetComponent <CheckItem>();

            currentCheckItem.methodName       = check.methodName;
            currentCheckItem.description.text = check.description;
            checkItemList.Add(currentCheckItem);

            gameObjectCheckItem.transform.SetParent(checkSpacer, false);
        }

        // Array of Toggles
        _toggleArray = new Toggle[UserDataObject.GetCurrentRepetitionsArray().Length];

        // Create and check toggles for each rep of current exercise
        foreach (var repetition in UserDataObject.GetCurrentRepetitionsArray())
        {
            GameObject gameObjectToggle = Instantiate(toggle);
            Toggle     currentToggle    = gameObjectToggle.GetComponent <Toggle>();

            _toggleArray[Array.IndexOf(UserDataObject.GetCurrentRepetitionsArray(), repetition)] = currentToggle;

            // Check if exercise not already accomplished
            if (!_currentExerciseData.accomplished)
            {
                // look for accomplished reps, check regarding toggles and set current rep
                if (repetition.accomplished)
                {
                    _repsIterator += 1;
                    currentToggle.GetComponent <Toggle>().isOn = true;
                }
                else if (_currentRepetition == null)
                {
                    _currentRepetition = repetition;
                }
            }
            else             // If exercise already accomplished
            {
                // Set first rep as current rep
                if (_currentRepetition == null)
                {
                    repetition.attempts   = 0;
                    repetition.confidence = 0.0f;
                    repetition.userTime   = 0.0f;

                    _currentRepetition = repetition;
                }
            }
            // Append GO to group
            gameObjectToggle.transform.SetParent(toggleGroup, false);
        }
        textReps.text = "Reps " + _repsIterator + "/" + UserDataObject.GetCurrentRepetitionsArray().Length;

        // Set ID of current repetition
        PlayerPrefs.SetInt("CurrentRepetitionId", Array.IndexOf(UserDataObject.GetCurrentRepetitionsArray(), _currentRepetition));

        // -----------------------------------------
        // ---------------- KINECT -----------------
        // -----------------------------------------

        _bodyManager = bodyManager.GetComponent <BodyManager>();
        if (_bodyManager == null)
        {
            return;
        }

        _kinectSensor = _bodyManager.GetSensor();

        _bodies = _bodyManager.GetBodies();
        Debug.Log(_bodyManager + " | " + _bodies);

        // Initialize gesture detector object
        _gestureDetectorList = new List <GestureDetector>();
        for (int bodyIndex = 0; bodyIndex < _bodies.Length; bodyIndex++)
        {
            _gestureDetectorList.Add(new GestureDetector(_kinectSensor));
        }

        // Foot joints for getting positions
        _jointFootRight           = KinectInterop.JointType.FootRight;
        _jointFootLeft            = KinectInterop.JointType.FootLeft;
        _startingHeightDifference = UserDataObject.GetCurrentExerciseStartingHeightDifference();
        heightTestIterator        = 0;

        // Initial foot position
        if (_kinectManager.IsUserDetected())
        {
            long userId = _kinectManager.GetPrimaryUserID();

            if (_kinectManager.IsJointTracked(userId, (int)_jointFootRight) &&
                _kinectManager.IsJointTracked(userId, (int)_jointFootLeft))
            {
                _initialStartingHeightLeft  = _kinectManager.GetJointKinectPosition(userId, (int)_jointFootLeft).y;
                _initialStartingHeightRight = _kinectManager.GetJointKinectPosition(userId, (int)_jointFootRight).y;

                initialLeftFootText.text  += _initialStartingHeightLeft.ToString();
                initialRightFootText.text += _initialStartingHeightRight.ToString();
            }
        }
        _bothFeetUp         = false;
        _inStartingPosition = false;


        if (UserDataObject.GetCurrentExerciseFileName() == "WalkForward")
        {
            _progressMinConfidence = 0.8f;
        }
        if (UserDataObject.GetCurrentExerciseFileName() == "BobOne")
        {
            _progressMinConfidence = 0.4f;
        }
        Debug.Log("_progressMinConfidence: " + _progressMinConfidence);
    }
    public void ManageNextScene()
    {
        Debug.Log("GetCurrentExercise: " + UserDataObject.GetCurrentExercise().fileName);
        Debug.Log("GetLastTierExercise: " + UserDataObject.GetLastTierExercise().fileName);
        Debug.Log("CurrentExercise ID: " + PlayerPrefs.GetInt("CurrentExerciseId"));

        // Check if a side is not accomplished
        foreach (var side in _currentExerciseData.sides)
        {
            Debug.Log("side direction: " + side.direction);
            Debug.Log("side accomplished: " + side.accomplished);
            if (side.accomplished == false)
            {
                _sideNotAccomplished = true;
            }
        }

        // Not last exercise --> load following side
        if (_currentExerciseData != _lastExercise || _sideNotAccomplished)
        {
            Debug.Log("any sideNotAccomplished? : " + _sideNotAccomplished);
            if (_sideNotAccomplished)
            {
                // TODO change subtitle of success GO

                if (PlayerPrefs.GetInt("CurrentSideId") == 0)
                {
                    Debug.Log("LOAD LEFT");
                    PlayerPrefs.SetInt("CurrentSideId", 1);
                    PlayerPrefs.SetString("CurrentSide", "Left");
                    LoadNextScene("ExerciseInfo");
                }
                else if (PlayerPrefs.GetInt("CurrentSideId") == 1)
                {
                    Debug.Log("LOAD RIGHT");
                    PlayerPrefs.SetInt("CurrentSideId", 0);
                    PlayerPrefs.SetString("CurrentSide", "Right");
                    LoadNextScene("ExerciseInfo");
                }
            }
            else             // all sides accomplished --> load next exercise
            {
                // TODO change subtitle of success GO
                UserDataObject.GetNextExercise().isInteractable = true;
                UserDataObject.GetNextExercise().unlocked       = 1;

                PlayerPrefs.SetInt("CurrentExerciseId", PlayerPrefs.GetInt("CurrentExerciseId") + 1);
                LoadNextScene("ExerciseSideSelection");
            }
        }
        else         // all exercises completed --> load TierMenu
        {
            // TODO change subtitle of success GO
            UserDataObject.GetNextTier().isInteractable = true;

            if (!UserDataObject.GetCurrentExercise().isInteractable)
            {
                UserDataObject.GetCurrentExercise().isInteractable = true;
                UserDataObject.GetCurrentExercise().unlocked       = 1;
            }


            LoadNextScene("TierMenu");
        }
        SaveCurrentExerciseData();
    }
    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");
        }
    }