Ejemplo n.º 1
0
    public void OnEnable()
    {
        allUserChats        = new GameObject[numberOfUsers];
        scrollRectTransform = content_go.GetComponent <RectTransform>();
        //read json
        chat = GameObject.Find("Utility").GetComponent <JSONHelper>().GetChat();

        //create prefab instances
        for (int i = 0; i < numberOfUsers; i++)
        {
            CreateAllUserChats();
        }
    }
Ejemplo n.º 2
0
    IEnumerator ReadJSON()
    {
        string path = "";

        if (Application.platform == RuntimePlatform.WindowsEditor || Application.platform == RuntimePlatform.WindowsPlayer)
        {
            path = Application.streamingAssetsPath + "/Chat.json";

            if (File.Exists(path))
            {
                string JSONString = File.ReadAllText(path);
                chat = JsonUtility.FromJson <JSONChat>(JSONString);
            }
            else
            {
                Debug.Log("doesnt find JSON");
            }
        }


        else if (Application.platform == RuntimePlatform.Android)
        {
            path = Path.Combine(Application.streamingAssetsPath + "/", "Chat.json");

            UnityWebRequest www = UnityWebRequest.Get(path);
            yield return(www.SendWebRequest());

            if (www.isNetworkError || www.isHttpError)
            {
                Debug.Log(www.error);
            }
            else
            {
                print("json file: " + www.downloadHandler.text);
            }

            chat = JsonUtility.FromJson <JSONChat>(www.downloadHandler.text);
        }

        Debug.Log("username: " + chat.username);
    }
Ejemplo n.º 3
0
 public void SetContent(JSONChat _chat)
 {
     chat = _chat;
 }