Exemplo n.º 1
0
    /// <summary>
    /// loads saved user data, if it exists
    /// </summary>
    /// <param name="topic">Chosen topic of the user</param>
    void LoadUserData(Topic topic)
    {
        Debug.Log(folderDataPath);
        if (File.Exists(folderDataPath))
        {
            string data = File.ReadAllText(folderDataPath);
            userData = JsonUtility.FromJson <UserData> (data);

            switch (topic)
            {
            case Topic.ADD:
                Debug.Log("Add");
                DisableAll();
                contents [0].gameObject.SetActive(true);
//				scrollContainers [0].gameObject.SetActive (true);
                scroll            = scrollContainers.gameObject.GetComponent <ScrollSnapRect> ();
                scroll._container = contents [0];
                scroll._scrollRectRect.gameObject.GetComponent <ScrollRect> ().content = contents [0];
                contents [0].localPosition      = origPosition;
                scroll._container.localPosition = origPosition;
                scroll.sceneNames = scroll.GetComponent <SceneNamesReader> ().GetAddSceneNames();
                scroll.SetPageCount(scroll.sceneNames.Length);
                scroll.SetPagePositions();
                scroll.SetCurrentScene(0);
                gameObject.GetComponentInChildren <LevelSelector> ().LoadUserData(topic, userData.currentAdditionSimilarFractionsLevel);
                break;

            case Topic.SUB:
                Debug.Log("Sub");
                DisableAll();
                contents [1].gameObject.SetActive(true);
//				scrollContainers [1].gameObject.SetActive (true);
                scroll            = scrollContainers.gameObject.GetComponent <ScrollSnapRect> ();
                scroll._container = contents [1];
                scroll._scrollRectRect.gameObject.GetComponent <ScrollRect> ().content = contents [1];
                contents[1].localPosition       = origPosition;
                scroll._container.localPosition = origPosition;
                scroll.sceneNames = scroll.GetComponent <SceneNamesReader> ().GetSubSceneNames();
                scroll.SetPageCount(scroll.sceneNames.Length);
                scroll.SetPagePositions();
                scroll.SetCurrentScene(0);
                gameObject.GetComponentInChildren <LevelSelector> ().LoadUserData(topic, userData.currentSubtractionSimilarFractionsLevel);
                break;

            case Topic.MIXED:
                Debug.Log("Mixed");
                DisableAll();
                contents [2].gameObject.SetActive(true);
//				scrollContainers.gameObject.SetActive (true);
                scroll            = scrollContainers.gameObject.GetComponent <ScrollSnapRect> ();
                scroll._container = contents [2];
                scroll._scrollRectRect.gameObject.GetComponent <ScrollRect> ().content = contents [2];
                contents[2].localPosition       = origPosition;
                scroll._container.localPosition = origPosition;
                scroll.sceneNames = scroll.GetComponent <SceneNamesReader> ().GetDisSceneNames();
                scroll.SetPageCount(scroll.sceneNames.Length);
                scroll.SetPagePositions();
                scroll.SetCurrentScene(0);
                gameObject.GetComponentInChildren <LevelSelector> ().LoadUserData(topic, userData.currentDissimilarFractionsLevel);
                break;
            }
            Debug.Log("[SELECT SCENE SCREEN]: Loaded user data");
        }
        else
        {
            Debug.Log("Unable to read the saved user data, file doesn't exist");
            userData = new UserData();
        }
    }