Example #1
0
    public void TurnEnded(Collision2D collision, GameObject pig)
    {
        TaskObservation taskObservation = new TaskObservation();

        taskObservation.TargetPosition = new float[] { currentTargetPosition.x, currentTargetPosition.y };
        taskObservation.Error          = new float[2] {
            0, 0
        };
        taskObservation.TaskName   = currentTaskRecommendation.TaskName;
        taskObservation.Difficulty = currentTaskRecommendation.Difficulty;

        //if player failed to hit the pig
        if (pig != null && collision.gameObject != pig)
        {
            //Get distance between bird hit point and pig position
            Vector2 error = collision.GetContact(0).point - (Vector2)pig.transform.position;
            taskObservation.Error[0] = error.x;
            taskObservation.Error[1] = error.y;
        }

        moduleConnection.SubmitTaskObservation(taskObservation);
    }
Example #2
0
    private IEnumerator UploadingTaskObservation(TaskObservation taskObservation, Action <bool> callback)
    {
        string query = @"mutation submitTaskObservations ($in: TaskObservationsInput!) {submitTaskObservations(taskObservations: $in) {_id}}";

        string variable = "{ \"in\": " + JsonUtility.ToJson(taskObservation) + "}";

        Debug.Log("Task Observation: " + JsonUtility.ToJson(taskObservation));

        using (UnityWebRequest www = client.Query(query, variable, "submitTaskObservations"))
        {
            yield return(www.SendWebRequest());

            if (www.isNetworkError)
            {
                Debug.Log(www.error);

                callback?.Invoke(false);
            }
            else
            {
                string responseString = www.downloadHandler.text;

                bool isError = IsResponseError(responseString);

                if (isError)
                {
                    Debug.Log("response:" + responseString);
                }
                else
                {
                    this.Turns++;
                }
                callback?.Invoke(!isError);
            }
        }
    }
Example #3
0
 public void SubmitTaskObservation(TaskObservation taskObservation, Action <bool> callback = null)
 {
     taskObservation.User = userId;
     StartCoroutine(UploadingTaskObservation(taskObservation, callback));
 }