コード例 #1
0
    IEnumerator setUserInfo(string url, float xPOS, float yPOS, float zPOS, int userID, float xROT, float yROT, float zROT)
    {
        WWWForm form = new WWWForm();

        form.AddField("xPOS", xPOS.ToString());
        form.AddField("yPOS", yPOS.ToString());
        form.AddField("zPOS", zPOS.ToString());
        form.AddField("userID", userID.ToString());

        form.AddField("xROT", xROT.ToString());
        form.AddField("yROT", yROT.ToString());
        form.AddField("zROT", zROT.ToString());

        UnityWebRequest uwr = UnityWebRequest.Post(url, form);

        yield return(uwr.SendWebRequest());

        string          retVal = uwr.downloadHandler.text;
        jsonFormatArray root   = JsonUtility.FromJson <jsonFormatArray>(retVal);

        for (int i = 0; i < root.users.Length; i++)
        {
            xPOS_L = root.users[i].xPOS;
            yPOS_L = root.users[i].yPOS;
            zPOS_L = root.users[i].zPOS;

            xROT_L = root.users[i].xROT;
            yROT_L = root.users[i].yROT;
            zROT_L = root.users[i].zROT;

            userID = root.users[i].ID;

            Vector3    pos = new Vector3(xPOS_L, yPOS_L, zPOS_L);
            Quaternion rot = Quaternion.Euler(xROT_L, yROT_L, zROT_L);

            foreach (var _spawnedUser in _spawnedUsers)
            {
                if (_spawnedUser.ID == userID)
                {
                    _spawnedUser.GO.transform.position = pos;

                    _spawnedUser.GO.transform.Find("ModelRoot").rotation = rot;
                }
            }
        }
    }
コード例 #2
0
    IEnumerator GetRequest(string uri)
    {
        UnityWebRequest uwr = UnityWebRequest.Get(uri);

        yield return(uwr.SendWebRequest());

        if (uwr.result == UnityWebRequest.Result.ConnectionError)
        {
            Debug.Log("Error While Sending: " + uwr.error);
        }
        else
        {
            string          retVal = uwr.downloadHandler.text;
            jsonFormatArray root   = JsonUtility.FromJson <jsonFormatArray>(retVal);

            for (int i = 0; i < root.users.Length; i++)
            {
                xPOS_L = root.users[i].xPOS;
                yPOS_L = root.users[i].yPOS;
                zPOS_L = root.users[i].zPOS;

                xROT_L = root.users[i].xROT;
                yROT_L = root.users[i].yROT;
                zROT_L = root.users[i].zROT;

                userID = root.users[i].ID;

                Vector3    pos  = new Vector3(xPOS_L, yPOS_L, zPOS_L);
                Quaternion rot  = Quaternion.Euler(xROT_L, yROT_L, zROT_L);
                GameObject inGO = Instantiate(mainUser, pos, Quaternion.identity);

                inGO.transform.Find("ModelRoot").rotation = rot;

                _spawnedUsers.Add(new spawnedUsers(userID, inGO));
            }
        }
    }