Пример #1
0
    private IEnumerator get_request(string uri)
    {
        using (UnityWebRequest request = UnityWebRequest.Get(uri))
        {
            yield return(request.SendWebRequest());

            if (request.isNetworkError)
            {
                Debug.Log("Error: " + request.error);
            }
            else
            {
                Debug.Log("\nRecieved: " + request.downloadHandler.text);

                _model = JsonConvert.DeserializeObject <speedrun.GameModel>(request.downloadHandler.text);

                string path = Application.persistentDataPath + "/" + _model.data.id;
                Directory.CreateDirectory(path);

                if (_title != null)
                {
                    _title.text = _model.data.names.international;
                }
                // Removed functionality since it really doesn't seem to work at all!

                //     speedrun.PlatformCache cache = GameListManager._platform_cache;
                //     foreach(string key in _model.data.platforms) {
                //         _system.text = "";
                //         if (cache.platforms.ContainsKey(key)) {
                //             _system.text += ", " +  GameListManager._platform_cache.platforms[key].name;
                //         } else {
                //             _system.text = "Unknown";
                //         }
                //     }
                // }
                StartCoroutine(get_texture());
            }
        }
    }
Пример #2
0
    public static speedrun.RunModel load_game_model(string game_id)
    {
        //string path = Application.persistentDataPath + "/" + game_id + "/splits/split.json";
        string path = PlayerPrefs.GetString(game_id);

        if (File.Exists(path))
        {
            //BinaryFormatter formatter = new BinaryFormatter();
            FileStream   fs = new FileStream(path, FileMode.Open);
            StreamReader sr = new StreamReader(fs);

            string json = sr.ReadToEnd();
            sr.Close();
            fs.Close();
            speedrun.RunModel model = JsonConvert.DeserializeObject <speedrun.RunModel>(json);
            return(model);
        }
        else
        {
            Debug.Log("no file found for: " + path);
            Debug.Log("creating from known data");

            string game_path = Application.persistentDataPath + "/" + game_id + "/gameinfo.bgi";

            BinaryFormatter    formatter  = new BinaryFormatter();
            FileStream         fs         = new FileStream(game_path, FileMode.Open);
            speedrun.GameModel game_model = formatter.Deserialize(fs) as speedrun.GameModel;
            fs.Close();

            speedrun.RunModel model = new speedrun.RunModel();
            model.run = new speedrun.Run();
            model.run.game_meta.thumb_path = "game_thumb.png";
            model.run.game_meta.name       = game_model.data.names.international;

            // also need to write it to file, so we aren't missing it next time!

            return(model);
        }
    }