コード例 #1
0
        private static void PickAllGetAnswer(GameObject go,
                                             ref QuestionDetails questionDetails)
        {
            //Debug.Log(go.transform.GetChild(1).GetChild(0).name +
            //          " is in Multiple");
            var toggles = go.transform.GetChild(1).GetChild(0)
                          .GetComponentsInChildren <Toggle>().ToList();

            questionDetails.SelectedAnswer = "";
            for (var i = 0; i < toggles.Count; ++i)
            {
                if (toggles[i].isOn)
                {
                    questionDetails.SelectedAnswer += "|" +
                                                      questionDetails
                                                      .OfferedAnswerList[i];
                }
            }

            if (questionDetails.SelectedAnswer.Length > 1)
            {
                questionDetails.SelectedAnswer =
                    questionDetails.SelectedAnswer.Substring(1);
            }
        }
コード例 #2
0
        private GameObject DebriefSetup(QuestionDetails questionDetails)
        {
            //make sure prefab works in the scene where it should be placed. drag and drop a prefab question in test explorer.
            var tempPrefab = MultipleSetup(questionDetails);

            var imageSelection = tempPrefab.transform.GetChild(1);

            imageSelection.gameObject.GetComponent <HorizontalLayoutGroup>()
            .childAlignment = TextAnchor.MiddleCenter;

            var temp = new GameObject();
            var img  = temp.AddComponent <RawImage>();

            img.GetComponent <RectTransform>().sizeDelta =
                new Vector2(Screen.width / 3, Screen.height / 3);

            temp.AddComponent <ImageDisplay>();
            temp.AddComponent <AudioPlayer>();
            var questionId = questionDetails.QuestionId;

            //DICK
            //get image location given question_id

            StartCoroutine(LoadQueryImageEnumerator(questionId));

            //}

            temp.transform.SetParent(imageSelection, false);
            temp.transform.SetAsLastSibling();
            return(tempPrefab);
        }
コード例 #3
0
        private static void NumericGetAnswer(GameObject go,
                                             ref QuestionDetails questionDetails)
        {
            var parent = go.transform.GetChild(1).GetChild(0).GetChild(0)
                         .GetChild(0).GetChild(0).GetChild(0).GetComponent <Text>().text;

            questionDetails.SelectedAnswer = parent;
        }
コード例 #4
0
        private GameObject PickAllSetup(QuestionDetails currentDetails)
        {
            var tempPrefab = MultipleSetup(currentDetails);

            Destroy(tempPrefab.transform.GetChild(1).GetChild(0).GetChild(0)
                    .gameObject);
            return(tempPrefab);
        }
コード例 #5
0
        private GameObject MessegeSetup(QuestionDetails questionDetails)
        {
            var tempPrefab =
                InstatiatePrefabAndPopulateAnswer(MessegePrefab,
                                                  questionDetails.QuestionString);

            return(tempPrefab);
        }
コード例 #6
0
        /// <summary>
        ///     Sets up a question with an <see cref="InputField" />
        /// </summary>
        /// <param name="questionDetails">A list consisting of a question and the rest is answers</param>
        /// <returns>returns an instantiated GameObject</returns>
        private GameObject FreeResponseSetUp(QuestionDetails questionDetails)
        {
            var tempPrefab =
                InstatiatePrefabAndPopulateAnswer(FreeResponsePrefab,
                                                  questionDetails.QuestionString);

            return(tempPrefab);
        }
コード例 #7
0
        private static void ScaleGetAnswer(GameObject go,
                                           ref QuestionDetails questionDetails)
        {
            var rawValue =
                go.transform.GetChild(1).GetChild(0).GetChild(0)
                .GetChild(0).GetComponent <Slider>().normalizedValue;
            var percent = 5 * Mathf.CeilToInt(rawValue * 100 / 5);

            questionDetails.SelectedAnswer = percent + "%";
        }
コード例 #8
0
        /// <summary>
        ///     Sets up a question prefab with a several <see cref="Button" />
        /// </summary>
        /// <param name="questionDetails">A list consisting of a question and the rest is answers</param>
        /// <returns>returns an instantiated GameObject</returns>
        /// <remarks>ToList() is used because Unity's <see cref="Dropdown" /> does not accept Itterables.</remarks>
        private GameObject ScalarSetup(QuestionDetails questionDetails)
        {
            var tempPrefab =
                InstatiatePrefabAndPopulateAnswer(ScalarPrefab,
                                                  questionDetails.QuestionString);
            var answerSelection = tempPrefab.transform.GetChild(1).GetChild(0)
                                  .GetChild(1);

            //Debug.Log(answerSelection.name + " is in ScalarSetup");
            PopulateAnswers(answerSelection, questionDetails.OfferedAnswerList);
            return(tempPrefab);
        }
コード例 #9
0
        /// <summary>
        ///     Calls specific method based on which question type it is.
        /// </summary>
        /// <param name="currentDetails"></param>
        /// <returns></returns>
        private GameObject FindOutQuestionType(QuestionDetails currentDetails)
        {
            //Debug.Log(currentDetails.Type);
            switch (currentDetails.QuestionType)
            {
            case "FreeResponse":
                return(FreeResponseSetUp(currentDetails));

            case "Multiple":
                return(MultipleSetup(currentDetails));

            case "Scalar":
                return(ScalarSetup(currentDetails));

            case "Numerical":
                return(NumericSetup(currentDetails));

            //special cases bellow

            case "Intro":
                return(MessegeSetup(currentDetails));

            case "Outro":
                return(MessegeSetup(currentDetails));

            case "Debrief":
                return(DebriefSetup(currentDetails));

            case "IfYesRespond":
                return(MultipleSetup(currentDetails));

            case "IfNoRespond":
                return(MultipleSetup(currentDetails));

            case "IfScalarLessThan3Respond":
                return(MultipleSetup(currentDetails));

            case "Scale":
                return(ScaleSetup(currentDetails));

            case "TLX":
                return(ScaleSetup(currentDetails));

            case "PickAll":
                return(PickAllSetup(currentDetails));
            }

            Debug.Log(string.Format("Question of type '{0}' does not exist",
                                    currentDetails.QuestionType));

            return(FreeResponseSetUp(currentDetails));
        }
コード例 #10
0
        private static IEnumerator UploadPreferredLvlOfAutonomy(
            QuestionDetails questionDetail)
        {
            var lvlOfAuto = 0;

            for (;
                 lvlOfAuto < questionDetail.OfferedAnswerList.Count - 1;
                 ++lvlOfAuto)
            {
                if (questionDetail.OfferedAnswerList[lvlOfAuto] ==
                    questionDetail.SelectedAnswer)
                {
                    break;
                }
            }
            if (lvlOfAuto >= questionDetail.OfferedAnswerList.Count)
            {
                lvlOfAuto = 0;
            }
            var dic =
                new Dictionary <string, int>
            {
                { "lvl_of_autonomy", lvlOfAuto },
                { "question_id", int.Parse(questionDetail.QuestionId) },
                {
                    "mission_id",
                    ParticipantBehavior.Participant.CurrentMission - 1
                }
            };


            var jsonDic = JsonConvert.SerializeObject(dic, Formatting.Indented);

            var form = new WWWForm();

            form.AddField("json", jsonDic);
            using (var www =
                       UnityWebRequest.Post(ServerURL.UPDATE_LVL_OF_AUTONOMY, form))
            {
                //Debug.Log(jsonDic);
                yield return(www.SendWebRequest());

                if (www.isNetworkError || www.isHttpError)
                {
                    Debug.Log(www.error);
                }
                else
                {
                    Debug.Log(www.downloadHandler.text + " is result");
                }
            }
        }
コード例 #11
0
        /// <summary>
        ///     Loads a prefab based on List of info about the question.
        /// </summary>
        /// <param name="questionDetails">
        ///     Follows the format of :
        ///     question_type, question string, answer, ..., answer
        /// </param>
        private void LoadPrefab(QuestionDetails questionDetails)
        {
            var go = FindOutQuestionType(questionDetails);

            go.transform.SetParent(gameObject.transform);
            go.name = _questionIndex.ToString();
            go.GetComponent <RectTransform>().sizeDelta = go.transform.parent
                                                          .GetComponent <RectTransform>().sizeDelta;
            go.GetComponent <RectTransform>().position = go.transform.parent
                                                         .GetComponent <RectTransform>().position;
            if (_go.Count != 0)
            {
                var x = _go.Last();
                x.SetActive(false);
            }

            _go.Add(go);
        }
コード例 #12
0
        private static void IfScalarLessThan3RespondGetAnswer(GameObject go,
                                                              ref QuestionDetails questionDetails)
        {
            var toggles = go.transform.GetChild(1).GetChild(0)
                          .GetComponentsInChildren <Toggle>().ToList();

            for (var i = 0; i < toggles.Count; ++i)
            {
                if (toggles[i].isOn)
                {
                    questionDetails.SelectedAnswer =
                        questionDetails.OfferedAnswerList[i] +
                        (i < 3
                            ? go.transform.GetChild(1).GetChild(1)
                         .GetComponent <InputField>().text
                            : "");
                    break;
                }
            }
        }
コード例 #13
0
        /// <summary>
        ///     Sets up the Scale Prefab in unity with answers and a questinon/
        /// </summary>
        /// <param name="questionDetails"></param>
        /// <returns></returns>
        private GameObject ScaleSetup(
            QuestionDetails questionDetails)
        {
            var tempPrefab =
                InstatiatePrefabAndPopulateAnswer(ScalePrefab,
                                                  questionDetails.QuestionString);

            //Sets the text on the right side of the scale.
            tempPrefab.transform.GetChild(1).GetChild(0)
            .GetChild(0).GetChild(0).GetChild(0).GetChild(0)
            .GetComponent <Text>().text =
                questionDetails.OfferedAnswerList[0];

            //Sets the text on the right side of the scale.
            tempPrefab.transform.GetChild(1).GetChild(0)
            .GetChild(0).GetChild(0).GetChild(0).GetChild(1)
            .GetComponent <Text>().text =
                questionDetails.OfferedAnswerList[1];
            return(tempPrefab);
        }
コード例 #14
0
        //tested
        private static void ScalarGetAnswer(GameObject go,
                                            ref QuestionDetails questionDetails)
        {
            //Debug.Log(go.transform.GetChild(1).GetChild(0).name +
            //          " is in Scalar");
            var toggles = go.transform.GetChild(1).GetChild(0)
                          .GetComponentsInChildren <Toggle>().ToList();

            for (var i = 0; i < toggles.Count; ++i)
            {
                if (toggles[i].isOn)
                {
                    //Debug.Log(i + " = i");
                    questionDetails.SelectedAnswer =
                        questionDetails.OfferedAnswerList[i];
                    return;
                }
            }

            questionDetails.SelectedAnswer = "Not Answered";
        }
コード例 #15
0
        private void UploadQuery(ref QuestionDetails questionDetails)
        {
            const string sql = "INSERT INTO dbsurveys.participant_result " +
                               "(survey_id, question_id, offered_answer_id, participant_answer_text, participant_id)" +
                               " VALUE ('{0}','{1}','{2}','{3}','{4}');";
            var particiapantId = 0;

            if (ParticipantBehavior.Instance != null)
            {
                particiapantId = ParticipantBehavior.Participant.Data.Id;
            }

            var sqlQuery = string.Format(
                sql,
                _surveyNumber,
                questionDetails.QuestionId,
                questionDetails.OfferedAnswerId,
                questionDetails.SelectedAnswer,
                particiapantId);

            Debug.Log("Nope just a Tide Ad " + sqlQuery);
            StartCoroutine(UploadQueryEnumerator(sqlQuery));
        }
コード例 #16
0
        private static void IfNoRespondGetAnswer(GameObject go,
                                                 ref QuestionDetails questionDetails)
        {
            var toggles = go.transform.GetChild(1).GetChild(0)
                          .GetComponentsInChildren <Toggle>().ToList();

            for (var i = 0; i < toggles.Count; ++i)
            {
                if (toggles[i].isOn)
                {
                    questionDetails.SelectedAnswer =
                        questionDetails.OfferedAnswerList[i] +
                        (i == 1
                            ? " " + go.transform.GetChild(1).GetChild(1)
                         .GetChild(2)
                         .GetComponent <Text>().text
                            : "");
                    return;
                }
            }

            questionDetails.SelectedAnswer = "Not Answered";
        }
コード例 #17
0
        /// <summary>
        ///     Sets up a question prefab with a several <see cref="Button" />
        /// </summary>
        /// <param name="questionDetails">A list consisting of a question and the rest is answers</param>
        /// <returns>returns an instantiated GameObject</returns>
        /// <remarks>ToList() is used because Unity's <see cref="Dropdown" /> does not accept Itterables.</remarks>
        private GameObject NumericSetup(QuestionDetails questionDetails)
        {
            var tempPrefab =
                InstatiatePrefabAndPopulateAnswer(NumericPrefab,
                                                  questionDetails.QuestionString);
            var answerSelection = tempPrefab.transform.GetChild(1).GetChild(0)
                                  .GetChild(0);
            //Debug.Log(answerSelection.name);
            var answerList = new List <string>();

            foreach (var answer in questionDetails.OfferedAnswerList)
            {
                var rangeOrAnswer = Regex.Split(answer, @"-");
                if (rangeOrAnswer.Length > 1)
                {
                    int initialRange;
                    int.TryParse(rangeOrAnswer[0], out initialRange);
                    int finalRange;
                    int.TryParse(rangeOrAnswer[1], out finalRange);
                    for (var i = initialRange; i < finalRange; ++i)
                    {
                        answerList.Add(i.ToString());
                    }
                }
                else
                {
                    answerList.Add(answer);
                }
            }

            var dropdown = answerSelection.GetChild(0).GetChild(0)
                           .GetComponent <Dropdown>();

            dropdown.AddOptions(answerList);
            return(tempPrefab);
        }