Ejemplo n.º 1
0
    IEnumerator MainLoop()
    {
        while (true)
        {
            jsonRequest = UnityWebRequest.Get("http://10.0.100.5/PracticeFMS/json");

            yield return(jsonRequest.SendWebRequest());

            if (jsonRequest.isHttpError || jsonRequest.isNetworkError)
            {
                PFMSConnected = false;
                continue;
            }

            try
            {
                JSONPayload tmp_jsonPayload = JsonUtility.FromJson <JSONPayload>(jsonRequest.downloadHandler.text);
                if (tmp_jsonPayload.Version == null)
                {
                    PFMSConnected = false;
                    continue;
                }
                PFMSConnected = true;
                jsonPayload   = tmp_jsonPayload;
            } catch (Exception e)
            {
                Debug.LogError("Exception: " + e.ToString());
                Debug.Log(jsonRequest.downloadHandler.text);
            }
        }
    }
Ejemplo n.º 2
0
    /// <summary>
    /// Gets a random word from the JSON input.
    /// </summary>
    Payload GetRandomWord()
    {
        JSONPayload jInfo = jsonLoader.GetJSONInfo();

        int index = Random.Range(0, jInfo.payload.Count);

        return(jInfo.payload[index]);
    }
Ejemplo n.º 3
0
    /// <summary>
    /// Extracts the JSON from its file and puts it in its appropriate class.
    /// </summary>
    void LoadJSON()
    {
        FileInfo     fInfo  = new FileInfo(Application.streamingAssetsPath + "/myworld.ver1.words.json");
        StreamReader reader = fInfo.OpenText();

        string text;
        string jsonText = "";

        //Read all the text from the file and store it in jsonText.
        do
        {
            text      = reader.ReadLine();
            jsonText += text;
        }while (text != null);
        reader.Close();

        jsonInfo = JsonUtility.FromJson <JSONPayload>(jsonText);

        SanitiseText();
    }