Beispiel #1
0
 // Initial PlayerPrefs creation for each Level --> set unlock value
 void SaveData()
 {
     if (PlayerPrefs.HasKey("Exercise0Unlocked"))
     {
         Debug.Log("Exercise0Unlocked exists");
         return;
     }
     else
     {
         Debug.Log("Exercise0Unlocked exists NOT");
         GameObject[] allButtons = GameObject.FindGameObjectsWithTag("ExerciseButton");
         foreach (GameObject buttons in allButtons)
         {
             ExerciseLevelButton button = buttons.GetComponent <ExerciseLevelButton>();
             PlayerPrefs.SetInt("Exercise" + button.buttonText.text + "Unlocked", button.unlocked);
         }
     }
 }
Beispiel #2
0
    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();
    }