private IEnumerator ShowMenu(UIFader fader, SelectionSlider slider) { yield return(StartCoroutine(fader.InteruptAndFadeIn())); yield return(StartCoroutine(slider.WaitForBarToFill())); yield return(StartCoroutine(fader.InteruptAndFadeOut())); }
void Start() { m_SelectionSlider = GetComponentInChildren <SelectionSlider>(); if (m_SelectionSlider != null) { m_SelectionSlider.OnBarFilled += OnBarFilled; } }
private IEnumerator WaitForBarToFill(SelectionSlider slider) { yield return(StartCoroutine(slider.WaitForBarToFill())); barFilled = true; //Check if ask for assignation if (slider.name == "TagAssignationSlider") { //We fade the assignation steps and remove the autoassignation button VRTracker.instance.autoAssignation = false; VRTracker.instance.assignationComplete = false; } }
private void Awake() { IList <GuiModelBase> myGuiModels = new List <GuiModelBase>(); /* adding text contents */ DoubleTextStatement Stat2_2_0 = new DoubleTextStatement(Color.white, "- 60歲 -", "你開始邁向退休的年紀", GuiPrefabUtils.DoubleTextFirstGazeDuration, GuiPrefabUtils.DoubleTextSecondGazeDuration, vrCamera, myGuiModels); SingleTextStatement Stat2_2_1 = new SingleTextStatement(Color.white, "女兒也已經30歲\n到了結婚的年齡", GuiPrefabUtils.SingleTextGazeDuration, vrCamera, myGuiModels); SingleTextStatement Stat2_3 = new SingleTextStatement(Color.white, "看著她也擁有自己的家庭\n你感到放心安慰", GuiPrefabUtils.SingleTextGazeDuration, vrCamera, myGuiModels); DoubleChoiceQuestion Q2 = new DoubleChoiceQuestion(Color.white, "她要搬離你的家\n和她的丈夫一起居住了 ……", "無奈接受", "欣然接受", vrCamera, myGuiModels, SceneSwitchControl.Scene5Q2Name); SingleTextStatement Stat3_0 = new SingleTextStatement(Color.white, "這時你才發現,原來你不捨得", GuiPrefabUtils.SingleTextGazeDuration, vrCamera, myGuiModels); SingleTextStatement Stat3_1 = new SingleTextStatement(Color.white, "她已經長大了,你無從改變 ……", GuiPrefabUtils.SingleTextGazeDuration, vrCamera, myGuiModels); DoubleTextStatement Stat3_2_0 = new DoubleTextStatement(Color.white, "- 82歲 -", "你患上末期癌症,需要長期進出醫院", GuiPrefabUtils.DoubleTextFirstGazeDuration, GuiPrefabUtils.DoubleTextSecondGazeDuration, vrCamera, myGuiModels); SingleTextStatement Stat3_2_1 = new SingleTextStatement(Color.white, "你回來了", GuiPrefabUtils.SingleTextGazeDuration, vrCamera, myGuiModels); Stat3_2_1.AddPlayAudioOnUiFadeInComplete(GuiPrefabUtils.SceneSoundEffectVolume, false, hospitalCurtainClip); SingleTextStatement Stat3_3 = new SingleTextStatement(Color.white, "你年老乏力的身體\n就如嬰孩時期般軟弱無力", GuiPrefabUtils.SingleTextGazeDuration, vrCamera, myGuiModels); scene5Q3ClipSource = Stat3_3.AddPlayAudioOnUiFadeInComplete(GuiPrefabUtils.SceneSoundEffectVolume, true, scene5Q3Clip); SingleTextStatement Stat3_4 = new SingleTextStatement(Color.white, "當你看到你女兒、女婿、\n孫子、親友全都圍在你床邊\n文珊靠在你床邊,哭成淚人的樣子時 ……", 6f, vrCamera, myGuiModels); SingleTextStatement Stat3_5 = new SingleTextStatement(Color.white, "你就意識到自己是差不多走到盡頭了", 4f, vrCamera, myGuiModels); SingleTextStatement Stat3_6 = new SingleTextStatement(Color.white, "你忽然想起過往很多和文珊的經歷片段", 4f, vrCamera, myGuiModels); SingleTextStatement Stat3_7 = new SingleTextStatement(Color.white, "第一次約會、第一次吵架、結婚、生小孩、\n一起為工作煩惱、一起為小孩擔憂、\n互相鼓勵、互相安慰 ……", 6f, vrCamera, myGuiModels); DoubleChoiceQuestion Q3 = new DoubleChoiceQuestion(Color.white, "慢慢的\n你的臉頰也流下了兩行淚水 ……", "默然不語", "跟文珊說:\n「謝謝你,\n我愛你。」", vrCamera, myGuiModels, SceneSwitchControl.Scene5Q3Name); Vector3 pos2 = GuiPrefabUtils.GetSelectionSlider2Text(Q3.underlyingGameObj).gameObject.transform.position; GuiPrefabUtils.GetSelectionSlider2Text(Q3.underlyingGameObj).gameObject.transform.position = new Vector3(pos2.x, pos2.y + 0.2f, pos2.z); SingleTextStatement Stat4_0 = new SingleTextStatement(Color.white, "這就是你的理想人生嗎?\n有時你會這樣問自己", 4f, vrCamera, myGuiModels); scene5Q4ClipSource = Stat4_0.AddPlayAudioOnUiFadeInReachThreshold(0.5f, true, scene5Q4Clip, 0f); SingleTextStatement Stat4_1 = new SingleTextStatement(Color.white, "漸漸的,你又開始聽到心臟微微的跳動\n感受到身體被一種暖流包裹", 4f, vrCamera, myGuiModels); Stat4_1UiFader = GuiPrefabUtils.GetUiFader(Stat4_1.underlyingGameObj); //heartbeatAudio = Stat4_1.AddPlayAudioOnUiFadeInComplete(GuiPrefabUtils.SceneSoundEffectVolume, true, heartbeatClip); Stat4_1.AddPlayAnimationOnUiFadeInComplete(heartbeatAnimationControl); SingleTextStatement Stat4_2 = new SingleTextStatement(Color.white, "生命,悄悄消逝 ……", 4f, vrCamera, myGuiModels); SingleChoiceQuestion Q4 = new SingleChoiceQuestion(Color.white, "你願意離開這個世界\n結束這一趟人生旅程嗎?", "我願意", vrCamera, myGuiModels); Q4UiFader = GuiPrefabUtils.GetUiFader(Q4.underlyingGameObj); scene5Q4LoopClipSource = Q4.AddPlayAudioOnUiFadeInReachThreshold(GuiPrefabUtils.SceneSoundEffectVolume, true, scene5Q4LoopClip, 0f); passAwaySelectionSlider = GuiPrefabUtils.GetSelectionSlider(Q4.underlyingGameObj); Q4.SetOnFilledAudioClipForSlider(null); SingleTextStatement Stat4_A = new SingleTextStatement(Color.white, "「我也愛你。」\n文珊抹一抹眼淚,跟你說", 4f, vrCamera, myGuiModels); SingleTextStatement End_1 = new SingleTextStatement(Color.white, "人生 …… 總是經歷選擇、擁有與失去\n你未必可以完全掌控你的人生\n更無法回到過去再來一次", GuiPrefabUtils.LastSceneSingleTextGazeDuration, vrCamera, myGuiModels); //UIFader End_1UiFader = GuiPrefabUtils.GetUiFader(End_1.underlyingGameObj); //End_1UiFader.m_FadeSpeed = 0.2f; SingleTextStatement End_2 = new SingleTextStatement(Color.white, "但是 …… 以甚麼心態面對人生起跌\n如何與你覺得重要的人相處\n是可以由你來決定", GuiPrefabUtils.LastSceneSingleTextGazeDuration, vrCamera, myGuiModels); SingleTextStatement End_3 = new SingleTextStatement(Color.white, "人,只可活一次!", GuiPrefabUtils.LastSceneSingleTextGazeDuration, vrCamera, myGuiModels); SingleTextStatement End_4 = new SingleTextStatement(Color.white, "回到現實,你會如何繼續你的人生呢?", GuiPrefabUtils.LastSceneSingleTextGazeDuration, vrCamera, myGuiModels); SingleTextStatement End_5 = new SingleTextStatement(Color.white, "(請脫下眼鏡,遵循工作人員指示離開)", 3600f, vrCamera, myGuiModels); //SingleTextStatement /* end of adding text contents */ /* setting next stories or next scenes */ Stat2_2_0.AddNextStory(Stat2_2_1); Stat2_2_1.AddNextStory(Stat2_3); Stat2_3.AddNextStory(Q2); Q2.AddNextStory(Stat3_0, DoubleChoiceQuestion.SelectionSlider1Or2.Slider1); Q2.AddNextStory(Stat3_0, DoubleChoiceQuestion.SelectionSlider1Or2.Slider2); Stat3_0.AddNextStory(Stat3_1); Stat3_1.AddNextStory(Stat3_2_0); Stat3_2_0.AddNextStory(Stat3_2_1); Stat3_2_1.AddNextStory(Stat3_3); Stat3_3.AddNextStory(Stat3_4); Stat3_4.AddNextStory(Stat3_5); Stat3_5.AddNextStory(Stat3_6); Stat3_6.AddNextStory(Stat3_7); Stat3_7.AddNextStory(Q3); Q3.AddNextStory(Stat4_0, DoubleChoiceQuestion.SelectionSlider1Or2.Slider1); Q3.AddNextStory(Stat4_A, DoubleChoiceQuestion.SelectionSlider1Or2.Slider2); Stat4_0.AddNextStory(Stat4_1); Stat4_1.AddNextStory(Stat4_2); Stat4_2.AddNextStory(Q4); Stat4_A.AddNextStory(Stat4_0); //Q4.AddNextScene(vrCamera.GetComponent<VRCameraFade>(), // GuiPrefabUtils.CameraFadeDuration, SceneSwitchControl.Scene5dName); Q4.AddNextStory(End_1); End_1.AddNextStory(End_2); End_2.AddNextStory(End_3); End_3.AddNextStory(End_4); End_4.AddNextStory(End_5); /* end of setting next stories or next scenes */ /* setting start gui */ Stat2_2_0.SetAsStartGui(storyStartManager); /* end of setting start gui */ /* activating guis */ // [Important] This is needed because the prefab game objects are set to be inactive so that the OnEnable event is not called during Prefab Instantiation. foreach (GuiModelBase myGuiModel in myGuiModels) { myGuiModel.SetActive(true); } /* end of activating guis */ }
void OnLevelWasLoaded(int level) { switch (level) { case 0: //Start Debug.Log("Scene Loaded: StartScene"); break; case 1: //Lobby Debug.Log("Scene Loaded: Lobby"); if (motionBase != null) { motionBase.transform.position = new Vector3(0.0f, 1.3f, 0.0f); } lobbyInstructions = GameObject.FindGameObjectWithTag("LobbyInstructions"); lobbyInstructions.SetActive(false); breakInstructions = GameObject.FindGameObjectWithTag("BreakInstructions"); breakInstructions.SetActive(false); finishedInstructions = GameObject.FindGameObjectWithTag("FinishedInstructions"); finishedInstructions.SetActive(false); SelectionSlider slider = lobbyInstructions.GetComponentInChildren <SelectionSlider>(); slider.OnBarFilled += slider_OnBarFilled; SelectionSlider slider2 = breakInstructions.GetComponentInChildren <SelectionSlider>(); slider2.OnBarFilled += slider_OnBarFilled; targetOne = GameObject.FindGameObjectWithTag("TargetOne"); targetTwo = GameObject.FindGameObjectWithTag("TargetTwo"); if (targetOne != null && targetTwo != null) { targetOneImage = targetOne.GetComponentInChildren <Image>(); targetTwoImage = targetTwo.GetComponentInChildren <Image>(); targetOneImage.CrossFadeAlpha(0.0f, 0.1f, true); targetTwoImage.CrossFadeAlpha(0.0f, 0.1f, true); targetOne.SetActive(false); targetTwo.SetActive(false); targetOneFadedOut = true; targetTwoFadedOut = true; } if (runNumber > 0 && runNumber % numberOfRunsBeforeBreak == 0) { breakInstructions.SetActive(true); onBreak = true; } cameraFade.FadeIn(false); break; case 2: //City Debug.Log("Scene Loaded: City"); condition = conditions.Dequeue(); if (recorder != null && !recorder.currentelyRecording()) { recorder.startRecording("PedSimCity_" + participantID + "_Run" + runNumber + "_Condition" + condition); } trafficLightChangeDelay = originalTrafficChangeDelay; if (motionBase != null) { motionBase.transform.position = motionBaseStartPosition; if (runNumber > 0) { motionBase.transform.Rotate(Vector3.up, 180f); } } if (guiArrows != null) { guiArrows.Hide(); } controller = GameObject.FindGameObjectWithTag("TrialIntersection").GetComponent <IntersectionController>(); targetVehicle = GameObject.FindGameObjectWithTag("TrialVehicle"); //period that the pedestrain light counts down to RED/DON'T WALK in s //float pedestrianChangeInterval = streetWidth / walkingSpeed; //time from start of vehicle movement to ped light green, in s float goSignalDelay = fadeInDelay + trafficLightChangeDelay + trafficLightYellowInterval + vehicleClearanceInterval + walkInterval; Debug.Log("Go signal delay: " + goSignalDelay); timer = goSignalDelay; //if condition == 0, we are in the no car condition, disable target car if (condition == 0) { targetVehicle.SetActive(false); Debug.Log("Condition 0: trial car disabled."); } else { float trialCarOffset = calculateTrialCarOffset(goSignalDelay); Debug.Log("Condition " + condition + ":"); Debug.Log("trial car offset: " + trialCarOffset); //if we're an even condition we need to flip the car around for the near lane trials if (condition % 2 == 0) { targetVehicle.transform.Rotate(Vector3.up, 180); targetVehicle.transform.position = new Vector3(targetVehicle.transform.position.x, 0, -49.8f); } Vector3 trialCarPosition = new Vector3(targetVehicle.transform.position.x + trialCarOffset, 0, targetVehicle.transform.position.z); targetVehicle.transform.position = trialCarPosition; Debug.Log("new trial car position: " + trialCarPosition.ToString()); } cameraFade.FadeIn(false); break; default: Debug.Log("Scene Loaded: " + level); break; } }
// Unity calls this function at the beginning private IEnumerator Start() { // Get the settings and store them into settings object settings = Settings.CreateFromJSON(); API_KEY = settings.api_key; LANG = settings.lang; // Commented code above provides an opportunity to change questions dynamically with the given json file @given path /* * WWW www = new WWW("file:///C:/Users/eminserdar.guzel/Desktop/icerik.json"); * WWW www = new WWW("file:///C:/Users/eda.mutlu/Desktop/icerik.json"); * yield return www; * settings = JsonUtility.FromJson<Settings>(www.text); */ // Reset the camera position ResetCameraPosition(); // Make the intro text visible SetVisibile(introCanvas, true); if (Microphone.devices.Length <= 0) { Debug.Log("Microphone not connected!"); // Throw a warning message at the console if there isn't SetVisibile(micWarningText.gameObject, true); } // Wait for slider to be filled yield return(StartCoroutine(confirmButton.WaitForBarToFill())); SetVisibile(micWarningText.gameObject, false); // Make the intro objects invisible SetVisibile(introTimerText, true); SetVisibile(introText, false); SetVisibile(confirmButton.gameObject, false); // Countdown before entering the first room yield return(StartCoroutine(StartTimerWithText(introTimerText, introCountDownTime))); // Make the intro scene completely invisible SetVisibile(introCanvas, false); // foreach (Scene scene in settings.scenes) { ResetCameraPosition(); /* * if (scene.name == "Bedroom") room = bedroom; * else if (scene.name == "Club") room = club; * else if (scene.name == "Kitchen") room = kitchen; * else room = living; */ GameObject room = Resources.Load(scene.name) as GameObject; room = Instantiate(room, room.transform.position, Quaternion.identity); room.transform.SetParent(roomCollapser.transform); // Countdown in order to give some time to player to look around roomCountDownTime = scene.countdown_time; // Show remaining time SetVisibile(roomTimerText, true); yield return(StartCoroutine(StartRoomTimer(roomCountDownTime))); //Make invisble the timer and then the room SetVisibile(roomTimerText, false); Destroy(room); foreach (Question question in scene.questions) { questionText.text = question.description; result = ""; foreach (SelectionSlider button in answerButtons) { Destroy(button.gameObject); } answerButtons.Clear(); // Start room timer SetVisibile(roomTimerText, true); ResetCameraPosition(); // Display the question SetVisibile(questionCanvas, true); questionCanvas.GetComponent <Animator>().SetTrigger("QuestionCanvasAnimation"); questionCanvas.GetComponent <Animator>().SetTrigger("StopAnimation"); SetVisibile(sttCorrectAnswer.gameObject, false); // If the question answer type is Speech To Text according to JSON file that we have given if (question.answer_type == "stt") { SetVisibile(stt, true); // The code block derived from http://answers.unity3d.com/questions/479064/microphone-detect-speech-start-end.html // Check if there is at least one microphone connected if (Microphone.devices.Length <= 0) { SetVisibile(roomTimerText, false); Debug.Log("Microphone not connected!"); // Throw a warning message at the console if there isn't SetVisibile(micWarningText.gameObject, true); yield return(new WaitForSeconds(3.0f)); SetVisibile(micWarningText.gameObject, false); } else // At least one microphone is present { //Set 'micConnected' to true micConnected = true; //Get the default microphone recording capabilities Microphone.GetDeviceCaps(null, out minFreq, out maxFreq); // According to the documentation, if minFreq and maxFreq are zero, the microphone supports any frequency... if (minFreq == 0 && maxFreq == 0) { //...Meaning 44100 Hz can be used as the recording sampling rate maxFreq = 44100; } //Get the attached AudioSource component goAudioSource = this.GetComponent <AudioSource>(); // Display mic image & recording text SetVisibile(sttRecording, true); // Ready to record yield return(StartCoroutine(StartRecording(5))); SetVisibile(roomTimerText, false); // Store the resulting string of SpeechToText func. this.mutex = false; SpeechToText(); SetVisibile(sttRecording, false); SetVisibile(sttProcessing, true); while (!this.mutex) { yield return(new WaitForSeconds(0.5f)); } SetVisibile(sttProcessing, false); // Display the user's answer sttAnswerText.text = result; SetVisibile(sttAnswerText.gameObject, true); // Check if the answer is correct or not // ...Change the color of the text accordingly if (result.ToLower() == question.correct_answer.ToLower()) { correctAnswers += 1; sttAnswerText.color = Color.green; } else { falseAnswers += 1; sttAnswerText.color = Color.red; // Display the correct answer SetVisibile(sttCorrectAnswer.gameObject, true); sttCorrectAnswer.text = "Doğru cevap: " + question.correct_answer.ToLower(); } yield return(new WaitForSeconds(5.0f)); SetVisibile(sttAnswerText.gameObject, false); SetVisibile(sttCorrectAnswer.gameObject, false); SetVisibile(questionCanvas, false); // Delete the .wav file used // File.Delete(filePath); } SetVisibile(stt, false); } else { int i = 0; int answersCount = question.answers.Count; // Total number of answers comes from JSON file foreach (Answer answer in question.answers) { answerButtons.Add(Instantiate(buttonPrefab, BUTTON_POSITONS[answersCount - 2, i], Quaternion.identity)); // Create a new answer button for each answer and set position answerButtons[i].transform.SetParent(questionCanvas.transform); // Make the button's parent as question canvas answerButtons[i].m_TrueAnswer = answer.correct; // To check whether the answer is correct, set the true or false according to JSON that we have given answerButtons[i].GetComponentInChildren <Text>().text = question.answers.ElementAt(i).answer; // Set the text of button according to JSON file answerButtons[i].m_Feedback = question.has_feedback && question.answer_type == "multiple_choices" ? question.answers.ElementAt(i).feedback : ""; i++; } //Countdown to answer the given question yield return(StartCoroutine(StartQuestionTimer(questionCountDownTime))); int index = 0; bool flag = false; string feedback = ""; // Find the selected answer & it's index foreach (SelectionSlider answerButton in answerButtons) { if (answerButton.m_BarFilled) { feedback = answerButtons[index].m_Feedback; if (answerButton.m_TrueAnswer) { flag = true; break; } } index++; } // If one of the answers is selected and it's the correct one, increment the count of the correct answers. // Otherwise, increment the count of the false answers if (flag) { correctAnswers += 1; } else { falseAnswers += 1; } // Make the current question canvas and the timer invisible SetVisibile(roomTimerText, false); SetVisibile(questionCanvas, false); yield return(new WaitForSeconds(1.0f)); if (question.has_feedback) { // Reset the camera position ResetCameraPosition(); SetVisibile(feedbackCanvas, true); if (question.fb_type == "text") { feedbackText.text = feedback; SetVisibile(feedbackText.gameObject, true); // Create an VR interactive button SelectionSlider feedbackButton = Instantiate(buttonPrefab, new Vector3(0.0f, 70.0f, 60.0f), Quaternion.identity) as SelectionSlider; feedbackButton.transform.SetParent(feedbackCanvas.transform); feedbackButton.GetComponentInChildren <Text>().text = "Tamam!"; // When the feedback button has been filled, skip the feedback part yield return(StartCoroutine(feedbackButton.WaitForBarToFill())); SetVisibile(feedbackText.gameObject, false); Destroy(feedbackButton.gameObject); } else if (question.fb_type == "video") { SetVisibile(screen, true); SetVisibile(videoPlayer.gameObject, true); /* To play the video full screen and near the camera * GameObject camera = GameObject.Find("Camera"); * videoPlayer.renderMode = VideoRenderMode.CameraNearPlane; */ //videoPlayer.url = feedback; /* * Following line of code is used for making it work in the android device as well * feedback should be something like "mov_bbb.mp4" and it also should be located in the Resoursec directory */ videoPlayer.clip = Resources.Load(feedback) as VideoClip; videoPlayer.Play(); while (videoPlayer.isPlaying) { yield return(new WaitForSeconds(1.0f)); } SetVisibile(videoPlayer.gameObject, false); SetVisibile(screen, false); } SetVisibile(feedbackCanvas, false); } // Calculate total time spent while answering questions totalTime += timeToAnswer; timeToAnswer = 0; } questionCanvas.GetComponent <Animator>().ResetTrigger("QuestionCanvasAnimation"); questionCanvas.GetComponent <Animator>().ResetTrigger("StopAnimation"); } // Make the question canvas invisible SetVisibile(questionCanvas, false); SetVisibile(sttAnswerText.gameObject, false); yield return(StartCoroutine(DisplayResults())); } }