コード例 #1
0
ファイル: AccountManager.cs プロジェクト: Symon799/ROTEOS
    public IEnumerator updateLevels()
    {
        Debug.Log("Welcome to Levels Getter");
        UnityWebRequest allLevelsRequest = _webRequester.Get("https://immense-lake-57494.herokuapp.com/levels", null);

        yield return(new WaitUntil(() => allLevelsRequest.isDone)); // To replace with personnal levels

        MetaData currentMetaData;

        if (MetaDataAction.metadataExists())
        {
            currentMetaData = MetaDataAction.readMetaData();
        }
        else
        {
            currentMetaData        = new MetaData();
            currentMetaData.levels = new List <level>();
        }


        Debug.Log("Finish downloading...");

        if (allLevelsRequest.responseCode != 200)
        {
            yield return(null);
        }

        Debug.Log("Start parsing... " + allLevelsRequest.downloadHandler.text);

        Levels allLevels = JsonUtility.FromJson <Levels>("{\"all\":" + allLevelsRequest.downloadHandler.text + "}");

        foreach (Level level in allLevels.all)
        {
            Debug.Log("OBJET LEVEL : " + JsonUtility.ToJson(level));
            if (!currentMetaData.levels.Exists(x => x.id == Convert.ToInt64(level.id)))
            {
                string filePath = Path.Combine(Application.persistentDataPath, "Levels/" + level.name);
                File.WriteAllText(filePath, JsonUtility.ToJson(level.json));
                currentMetaData.levels.Add(MetaDataAction.LevelToMetaDataLevel(level));
            }
        }

        Debug.Log("Current Meta Data... " + JsonUtility.ToJson(currentMetaData));

        yield return(MetaDataAction.modifyMetaData(currentMetaData));

        menuManager.StartMenu();
    }