using System; using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.UI; using System.IO; using UnityEngine.Video; using TMPro; public class AddGame : MonoBehaviour { public List trials = new List(); public RawImage TutorialPlayer; public RawImage TutorialPlayer2; public VideoClip add_tut; public VideoClip sub_tut; private VideoPlayer vp; private VideoSource videoSource; private VideoPlayer vp2; private VideoSource videoSource2; public Image fuel; //Audio private AudioSource audioSource; private AudioSource audioSource2; public struct Aufgabe { public int x, y, r; //op = 1: less, op = 2: more public int op; public Aufgabe(int p1, int p2, int p3, int p4) { x = p1; y = p2; r = p3; op = p4; } } public TMP_Text number; public TMP_Text level; public Camera cam; private string game; public SpriteRenderer background; private int touchCount = 0; const float sw= 2.5f;//stopwatch private float targetTime = sw; private float maxTargetTime = sw; //must be = targetTime private float targetTime2 = 0.1f; private float targetTime3 = 1.0f; private float targetTime4 = 0.8f; private ArrayList completed5 = new ArrayList(); private ArrayList completed10 = new ArrayList(); public List results = new List(); private int stage; //private UnityEngine.Random rnd = new UnityEngine.Random(); //private int count = 0; //private int count2 = 0; private int score = 0; //private int[] numbers10 = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 }; private Aufgabe[] aufgaben = new Aufgabe[48]; public new List audio = new List(); public Button startButton; public Button exitButton; public Image progressBar; public Image EvaluateTimer; public GameObject[] hand = new GameObject[10]; private bool[] fingers = new bool[10]; private float[] times = new float[10]; private int trialCount = 0; private bool logged = false; private int touchCount0; private bool logged2 = false; private bool logged3 = false; /*private float duration = 0.2f; private Color color1 = Color.blue; private Color color2 = Color.green; private Color color3 = Color.blue; private Color color4 = Color.red;*/ private int fingerCount = 0; private Trial trial; public GameObject scoreStar; public GameObject Finn; //private Vector3 posStar = new Vector3(); //private int scoreCount = 0; private bool evaluated = false; private int response = 0; private float minTime = 100000f; private float maxTime = 0f; private bool tutorialIsPlaying; private bool playNextTrial; private int error_count=0; private bool kurze_pause=false; //private bool switched=false; private int maxid=-1; private bool halbzeit=false; private void Awake() { scoreStar.SetActive(false); background.GetComponent().SetInteger("fade", 0); background.GetComponent().Play("Background_Idle", -1, 0f); StartCoroutine(prepareVideo()); StartCoroutine(prepareVideo2()); } IEnumerator prepareVideo() { vp = gameObject.AddComponent(); //Add AudioSource audioSource = gameObject.AddComponent(); //Disable Play on Awake for both Video and Audio vp.playOnAwake = false; audioSource.playOnAwake = false; vp.source = VideoSource.VideoClip; vp.audioOutputMode = VideoAudioOutputMode.AudioSource; //Assign the Audio from Video to AudioSource to be played vp.EnableAudioTrack(0, true); vp.SetTargetAudioSource(0, audioSource); audioSource.volume = 0.8f; //We want to play from video clip not from url vp.clip = add_tut; //Set video To Play then prepare Audio to prevent Buffering vp.Prepare(); //Wait until video is prepared while (!vp.isPrepared) { //Debug.Log("Preparing Video"); yield return null; } Debug.Log("Done Preparing Video"); //Assign the Texture from Video to RawImage to be displayed TutorialPlayer.texture = vp.texture; } IEnumerator prepareVideo2() { vp2 = gameObject.AddComponent(); //Add AudioSource audioSource2 = gameObject.AddComponent(); //Disable Play on Awake for both Video and Audio vp2.playOnAwake = false; audioSource2.playOnAwake = false; vp2.source = VideoSource.VideoClip; vp.audioOutputMode = VideoAudioOutputMode.AudioSource; //Assign the Audio from Video to AudioSource to be played vp.EnableAudioTrack(0, true); vp.SetTargetAudioSource(0, audioSource2); audioSource.volume = 0.8f; //We want to play from video clip not from url vp2.clip = sub_tut; //Set video To Play then prepare Audio to prevent Buffering vp2.Prepare(); //Wait until video is prepared while (!vp2.isPrepared) { //Debug.Log("Preparing Video"); yield return null; } Debug.Log("Done Preparing Video"); //Assign the Texture from Video to RawImage to be displayed TutorialPlayer2.texture = vp2.texture; } void Start() { number.text = " "; number.gameObject.SetActive(true); level.text = "LEVEL " + Gamestate.Instance.getLevel(); int[] v1 = new int[] { 3,5,5,3,5,3,3,5,5,3,3,5,8,10,5,9,10,8,9,10,10,9,8,10}; int[] v2 = new int[] { 1,2,1,2,2,1,2,1,1,2,1,2,6, 7,1,8, 7,6,8, 6, 6,8,6, 7}; int[] v3 = new int[] { 2,3,4,1,3,2,1,4,4,1,2,3,2, 3,4,1, 3,2,1, 4, 4,1,2, 3}; int[] v4 = new int[] { 2,3,4,1,3,2,1,4,4,1,2,3,2, 3,4,1, 3,2,1, 4, 4,1,2, 3}; int[] v5 = new int[] { 3,5,5,3,5,3,3,5,5,3,3,5,6,10,5,9,10,8,9,10,10,9,8,10}; int[] v6 = new int[] { 1,2,1,2,2,1,2,1,1,2,1,2,6, 7,1,8, 7,6,8, 6, 6,8,8, 7}; //x+y=r Aufgabe a1; int j=0; for (int i=0; i < Gamestate.Instance.getNumberTrials()/2; i++) { a1.x = v2[i]; a1.y = v3[i]; a1.r = v1[i]; a1.op = 1; aufgaben[j] = a1; j++; } //x-y=r for (int i = 0; i < Gamestate.Instance.getNumberTrials()/2; i++) { a1.x = v5[i]; a1.y = v6[i]; a1.r = v4[i]; a1.op = 2; aufgaben[j] = a1; j++; } for (int i = 0; i < 10; i++) { fingers[i] = false; times[i] = 0.0f; } //aufgabenKeys = reshuffle(lessKeys); //moreKeys = reshuffle(moreKeys); //numbers10 = reshuffle(numbers10); progressBar.fillAmount = 0; EvaluateTimer.fillAmount=0; //EvaluateTimer.fillClockwise = false; foreach (GameObject go in hand) { go.GetComponent().enabled = false; } foreach (RawImage go in results) { go.enabled = false; } //stage = 1; } int[] reshuffle(int[] numbers) { // Knuth shuffle algorithm :: courtesy of Wikipedia :) for (int t = 0; t < numbers.Length; t++) { int tmp = numbers[t]; int r = UnityEngine.Random.Range(t, numbers.Length); numbers[t] = numbers[r]; numbers[r] = tmp; } return numbers; } /* int selectRandomNumber_5() { if (s_numbers5.Count == 0) s_numbers5 = new ArrayList(reshuffle(numbers5)); int r = (int)s_numbers5[0]; s_numbers5.RemoveAt(0); return r; } int selectRandomNumber_10() { if (s_numbers10.Count == 0) s_numbers10 = new ArrayList(reshuffle(numbers10)); int r = (int)s_numbers10[0]; s_numbers10.RemoveAt(0); return r; } */ public void setProgressBar(int val) { //Debug.Log("setProgressBar: " + val.ToString()); float t = Gamestate.Instance.getNumberTrials()*10f; progressBar.fillAmount = val / t; } public void setEvaluateTimer(float val) { //Debug.Log("setEvaluate: " + val.ToString()); //float t = Gamestate.Instance.getNumberTrials()*10f; EvaluateTimer.fillAmount = val/maxTargetTime;//(Gamestate.Instance.getNumberTrials()*10) ; } void evaluateTouchInput() { Debug.Log("----EVALUATE 1--Begin---------------"); Debug.Log("touchCount: " + touchCount.ToString()); foreach (Touch touch in Input.touches) { TouchSer tser = new TouchSer(); tser.TouchID = touch.fingerId.ToString(); tser.Timestamp = touch.deltaTime.ToString(); tser.X = touch.position.x; tser.Y = touch.position.y; trial.T.Add(tser); if (maxid < touch.fingerId) { maxid = touch.fingerId; } } fingerCount = 0; minTime = 1000000f; maxTime = 0f; //do your stuff here. for (int i = 0; i < 10; i++) { //Debug.Log("times[" + i + "]: " + times[i].ToString()); if (fingers[i] == true) fingerCount += 1; if (times[i] != 0f) { if (times[i] < minTime) minTime = times[i]; if (times[i] > maxTime) maxTime = times[i]; } } //Debug.Log("minTime: " + minTime.ToString()); //Debug.Log("maxTime: " + maxTime.ToString()); if ((maxTime - minTime) > 0.15) //start tutorial? fingerCount = 0; if (trial.Op == "+") { if (fingerCount == trial.X) { audio[11].Play(); if (Gamestate.Instance.getLevel() == "1") { number.text = trial.X.ToString()+"+ _ =" + trial.R.ToString(); results[trial.X-1].GetComponent().enabled = false; results[trial.R-1].GetComponent().enabled = true; } else if (Gamestate.Instance.getLevel() == "2") { number.text = trial.X.ToString()+"+ _ =" + trial.R.ToString(); } else if (Gamestate.Instance.getLevel() == "3") { number.text = "_ + _ ="; } audio[trial.X - 1].Play(); trial.Correct = "y"; error_count = 0; response = 1; } else { number.text = " "; audio[12].Play(); response = 2; trial.Correct = "n"; error_count += 1; } } else { if (fingerCount == trial.X) { audio[11].Play(); if (Gamestate.Instance.getLevel() == "1") { number.text = trial.X.ToString()+"- _ =" + trial.R.ToString(); results[trial.X-1].GetComponent().enabled = false; results[trial.R-1].GetComponent().enabled = true; } else if (Gamestate.Instance.getLevel() == "2") { number.text = trial.X.ToString()+"- _ =" + trial.R.ToString(); } else if (Gamestate.Instance.getLevel() == "3") { number.text = "_ - _ ="; } audio[trial.X - 1].Play(); trial.Correct = "y"; error_count = 0; response = 1; } else { number.text = " "; audio[12].Play(); response = 2; trial.Correct = "n"; error_count += 1; } } evaluated = true; Debug.Log("-----EVALUATE 1----END----------------------"); } void evaluateTouchInput2() { Debug.Log("------- EVAL_TOUCH_INPUT2 --Begin----------------------"); Debug.Log("touchCount: " + touchCount.ToString()); foreach (Touch touch in Input.touches) { if (touch.fingerId > maxid) { TouchSer tser = new TouchSer(); tser.TouchID = touch.fingerId.ToString(); tser.Timestamp = touch.deltaTime.ToString(); tser.X = touch.position.x; tser.Y = touch.position.y; trial.T.Add(tser); } } //Debug.Log("trial.t2.:" + trial.T.Count.ToString()); fingerCount = 0; minTime = 1000000f; maxTime = 0f; //do your stuff here. for (int i = 0; i < 10; i++) { //Debug.Log("fingers[" + i + "]: " + fingers[i].ToString()); if (fingers[i] == true) fingerCount += 1; } for (int i = trial.X; i < trial.R; i++) { //Debug.Log("times[" + i + "]: " + times[i].ToString()); if (times[i] != 0f) { if (times[i] < minTime) minTime = times[i]; if (times[i] > maxTime) maxTime = times[i]; } } //Debug.Log("minTime: " + minTime.ToString()); //Debug.Log("maxTime: " + maxTime.ToString()); if ((maxTime - minTime) > 0.15) //start tutorial? fingerCount = 0; if (fingerCount == trial.R) { score = score + 10; audio[11].Play(); trial.Correct2 = "y"; foreach (GameObject go in hand) { go.GetComponent().Play("StarFadeOut", -1, 0f); } scoreStar.SetActive(true); scoreStar.GetComponent().Play("StarMove", -1, 0f); setProgressBar(score); error_count = 0; response = 1; if (trial.Op == "+") { number.text = trial.X.ToString() + " + " + trial.Y.ToString() + " = " + trial.R.ToString(); audio[14].Play(); audio[trial.Y - 1].PlayDelayed(0.2f); audio[16].PlayDelayed(0.9f); audio[trial.R-1].PlayDelayed(1.2f); } else { number.text = trial.X.ToString() + " - " + trial.Y.ToString() + " = " + trial.R.ToString(); audio[15].Play(); audio[trial.Y - 1].PlayDelayed(0.4f); audio[16].PlayDelayed(1.1f); audio[trial.R-1].PlayDelayed(1.4f); } } else { number.text = " "; audio[12].Play(); response = 2; trial.Correct2 = "n"; error_count += 1; } evaluated = true; Debug.Log("------- EVAL_TOUCH_INPUT2 --End----------------------"); } void Update() { switch (game) { case "running": if (!logged) { //Debug.Log("running"); logged = true; } targetTime -= Time.deltaTime; if (fingers[0] == true) { //if (!EvaluateTimer.GetComponent().enabled) EvaluateTimer.GetComponent().enabled=true; setEvaluateTimer(targetTime); } if (targetTime <= 0.0f & fingers[0] == true) { game = "evaluate"; break; //evaluateTouchInput(); } foreach (Touch touch in Input.touches) { switch (touch.phase) { case TouchPhase.Began: //Debug.Log("phase began"); touchCount += 1; times[touchCount - 1] = Time.time; fingers[touchCount - 1] = true; audio[13].Play(); //if (touchCount <= 10) //{ //hand[touchCount].GetComponent().enabled = true; //hand[touchCount].GetComponent().SetBool("fadeout", false); //hand[touchCount].GetComponent().Play("StarFadeIn", -1, 0f); //} targetTime = sw; break; case TouchPhase.Ended: //Debug.Log("phase ended"); if (touchCount > 1) touchCount -= 1; fingers[touchCount] = false; //hand[touchCount + 1].GetComponent().SetBool("fadeout", true); //hand[touchCount + 1].GetComponent().enabled = false; targetTime = sw; break; default: break; } } break; case "running2": if (!logged) { int tc = touchCount -1; //Debug.Log("running2 + touchcount: " + touchCount.ToString() + " fingers["+ tc.ToString()+"]: "+fingers[tc].ToString()); evaluated = false; logged = true; touchCount0 = touchCount; //showDiff(); } //Debug.Log("Time.deltaTime: " + Time.deltaTime.ToString()); //Debug.Log("targetTime: " + targetTime.ToString()); targetTime -= Time.deltaTime; if (fingers[0] == true) { //if (!EvaluateTimer.GetComponent().enabled) EvaluateTimer.GetComponent().enabled=true; setEvaluateTimer(targetTime); } if (targetTime <= 0.0f) { game = "evaluate2"; break; //evaluateTouchInput(); } foreach (Touch touch in Input.touches) { switch (touch.phase) { case TouchPhase.Began: //Debug.Log("phase began"); touchCount += 1; int tc = touchCount -1; times[tc] = Time.time; fingers[tc] = true; //Debug.Log("fingers[" + tc.ToString() + "]: " + fingers[tc].ToString()); audio[13].Play(); //if (touchCount <= 10) //{ //hand[touchCount].GetComponent().enabled = true; //hand[touchCount].GetComponent().SetBool("fadeout", false); //hand[touchCount].GetComponent().Play("StarFadeIn", -1, 0f); //} targetTime = sw; break; case TouchPhase.Ended: //Debug.Log("phase ended"); if (touchCount > 1) touchCount -= 1; fingers[touchCount] = false; hand[touchCount].GetComponent().SetBool("fadeout", true); //hand[touchCount + 1].GetComponent().enabled = false; targetTime = sw; break; default: break; } } break; case "evaluate": if (!logged2) { //Debug.Log("evaluate"); logged2 = true; } if (!evaluated) evaluateTouchInput(); //targetTime3 -= Time.deltaTime; //if (targetTime3 <= 0.0f) //{ if (response == 1) { if (trial.Op == "+") { for (int i = trial.X; i < trial.R; i++) { Debug.Log("i: " + i); hand[i].GetComponent().enabled = true; hand[i].GetComponent().SetBool("fadeout", false); hand[i].GetComponent().Play("StarFadeIn_green", -1, 0f); } } else { for (int i = trial.X-1; i >= trial.R; i--) { Debug.Log("ii: " + i); //hand[i].GetComponent().enabled = true; hand[i].GetComponent().SetBool("fadeout", false); hand[i].GetComponent().Play("StarFadeIn_green", -1, 0f); } } logged = false; logged2 = false; targetTime = sw; game = "running2"; //targetTime2 = 0.1f; //targetTime3 = 1.0f; } if (response == 2) game = "red_blink"; //} break; case "evaluate2": if (!logged2) { //Debug.Log("evaluate2"); logged2 = true; } if (!evaluated) evaluateTouchInput2(); targetTime3 -= Time.deltaTime; if (targetTime3 <= 0.0f) { targetTime3 = 1.0f; trial.Score=score; trials.Add(trial); game = "show_result"; } break; case "show_result": targetTime3 -= Time.deltaTime; if (targetTime3 <= 0.0f) { if (response == 1) game = "green_blink"; if (response == 2) game = "red_blink"; //trials.Add(trial); } break; case "halb_zeit": targetTime3 -= Time.deltaTime; level.text ="Minus-Aufgaben"; //tutorialIsPlaying=false; //game="tutorial"; if (targetTime3 <= 0.0f) { if (Input.touchCount > 0) { Debug.Log("-------------------------------------------------HALBZEIT---------------------------------------"); level.text = " "; halbzeit=true; game = "tutorial"; //trials.Add(trial); } } break; case "kurze_pause": targetTime3 -= Time.deltaTime; //level.text ="Weiter so!!!"; //tutorialIsPlaying=false; //game="tutorial"; if (targetTime3 <= 0.0f) { if (Input.touchCount > 0) { background.GetComponent().SetInteger("fade", 2); Debug.Log("-----------kurze_pause-----------"); level.text = " "; kurze_pause=true; Finn.SetActive(false); game = "next_trial"; //trials.Add(trial); } } break; case "green_blink": targetTime -= Time.deltaTime; //float t = Mathf.PingPong(Time.time, duration) / duration; //cam.backgroundColor = Color.Lerp(color1, color2, t); if (targetTime <= 0.0f) { number.text = " "; for (int i = 0; i < 10; i++) { hand[i].GetComponent().SetBool("fadeout", true); } targetTime2 -= Time.deltaTime; //dump(trial); if (targetTime2 <= 0.0f) { playNextTrial=false;//nextTrial(); game="next_trial"; } } break; case "red_blink": targetTime -= Time.deltaTime; //float t2 = Mathf.PingPong(Time.time, duration) / duration; //cam.backgroundColor = Color.Lerp(color3, color4, t2); if (targetTime <= 0.0f) { //cam.backgroundColor = Color.black; number.text = " "; for (int i = 0; i < 10; i++) { hand[i].GetComponent().SetBool("fadeout", true); } if (error_count >= 5) { tutorialIsPlaying=false; game="tutorial"; break; } targetTime2 -= Time.deltaTime; //dump(trial); if (targetTime2 <= 0.0f) { playNextTrial=false;//nextTrial(); game="next_trial"; } } break; case "tutorial": targetTime4 -= Time.deltaTime; //background = GetComponent().SetBool("fadeout", true); background.GetComponent().SetInteger("fade", 1); exitButton.gameObject.SetActive(false); startButton.gameObject.SetActive(false); fuel.gameObject.SetActive(false); progressBar.gameObject.SetActive(false); level.text=" "; for (int i = 0; i < 10; i++) { hand[i].GetComponent().enabled = false; } //background.GetComponent().Play("Background_Fader", -1,0f); if (targetTime4 <= 0.0f) { if(!tutorialIsPlaying) { //Debug.Log("background anim state1 = "+background.GetComponent().GetCurrentAnimatorStateInfo(0).fullPathHash.ToString()); if (trialCount < Gamestate.Instance.getNumberTrials()/2) { Debug.Log("playTutorial()++++++++++++++++++"); StartCoroutine(playTutorial()); } else { Debug.Log("playTutorial2()------------------"); StartCoroutine(playTutorial2()); } } } break; case "next_trial": if(!playNextTrial) nextTrial(); break; case "ending": if (!logged3) { //Debug.Log("ended"); number.text = " "; trialCount = 0; /*switch(Gamestate.Instance.getLevel()) { case "1": if(!switched) { Gamestate.Instance.setLevel("2"); switched = true; } break; case "2": if(!switched) { Gamestate.Instance.setLevel("3"); switched = true; } break; }*/ targetTime -= Time.deltaTime; //float t = Mathf.PingPong(Time.time, duration) / duration; //cam.backgroundColor = Color.Lerp(color1, color2, t); if (targetTime <= 0.0f) { logged3 = true; Gamestate.Instance.setGamePoints(score); //foreach(Trial t in trials) { // dump(t); //} savePlayerData(); //cam.backgroundColor = Color.black; DontDestroyOnLoad(Gamestate.Instance); Gamestate.Instance.startScoreScene(); } } break; } } public void startProc() { if (Gamestate.Instance.getTutorial()) { tutorialIsPlaying=false; //Debug.Log("background anim state0 = "+background.GetComponent().GetCurrentAnimatorStateInfo(0).fullPathHash.ToString()); game="tutorial"; //return; } else { playNextTrial = false; game="next_trial";//nextTrial(); } } /* Start of the game. Starts by pressing the play-button*/ public void nextTrial() { maxid = -1; background.GetComponent().SetInteger("fade",3); targetTime4 = 0.8f; //Debug.Log("background anim state3 = "+background.GetComponent().GetCurrentAnimatorStateInfo(0).fullPathHash.ToString()); //background.GetComponent().SetInteger("fade",0); progressBar.gameObject.SetActive(true); level.text = " "; targetTime3 = 2.0f; //setze Sterne zurück foreach (GameObject go in hand) { go.GetComponent().enabled = false; } foreach (RawImage go in results) { go.GetComponent().enabled = false; } if (trialCount == Gamestate.Instance.getNumberTrials()/2 && !halbzeit) { StartCoroutine(prepareVideo2()); //audio[17].PlayDelayed(0.5f); game= "halb_zeit"; return; } else if (trialCount > 0 && trialCount < Gamestate.Instance.getNumberTrials() && trialCount % 8 == 0 && !kurze_pause) { background.GetComponent().SetInteger("fade",1); exitButton.gameObject.SetActive(false); startButton.gameObject.SetActive(false); Finn.SetActive(true); fuel.gameObject.transform.localPosition = new Vector3(311,-213,0); progressBar.gameObject.transform.localPosition = new Vector3(311.6f,-232,0); float i = UnityEngine.Random.value; if (error_count < 3) { if (i < 0.25) { level.text = "Super !!!"; audio[18].PlayDelayed(0.2f); } else if (i >=0.25 && i < 0.5) { level.text = "Toll !!!"; audio[19].PlayDelayed(0.2f); } else if (i >= 0.5 && i < 0.75) { level.text = "Sehr gut !!!"; audio[20].PlayDelayed(0.2f); } else { level.text = "Prima !!!"; audio[21].PlayDelayed(0.2f); } } else { level.text = "Bleib dran !!!"; audio[22].PlayDelayed(0.2f); } game= "kurze_pause"; return; } else if (trialCount < Gamestate.Instance.getNumberTrials()) { game = "running"; } else { targetTime = sw; game = "ending"; return; } playNextTrial=true; kurze_pause=false; Finn.SetActive(false); fuel.gameObject.transform.localPosition = new Vector3(900,600,0); progressBar.gameObject.transform.localPosition = new Vector3(900.6f,577.8f,0); trial = new Trial(); trial.ID = Gamestate.Instance.getID(); trial.Game = Gamestate.Instance.getGame(); trial.Level = Gamestate.Instance.getLevel(); trial.Date = DateTime.Now.Date.ToShortDateString(); trial.Time = DateTime.Now.TimeOfDay.ToString(); trial.Onset = Time.time.ToString(); trial.T.Clear(); evaluated = false; Gamestate.Instance.setAnimPlaying(true); scoreStar.SetActive(false); startButton.gameObject.SetActive(false); //exitButton.gameObject.SetActive(false); exitButton.gameObject.SetActive(true); fuel.gameObject.SetActive(true); /* if (Gamestate.Instance.getLevel() == "1") number.gameObject.SetActive(false); else number.gameObject.SetActive(true); */ touchCount = 0; //starte Evaluierung nach 2 sek targetTime = sw; //Animationstimer, warten auf fadeout der Sterne targetTime2 = 0.1f; //warte 1 sek. auf Evaluierung targetTime3 = 1.0f; //zeige x gelbe und y gruene Sterne x+y=r trial.X = aufgaben[trialCount].x; // UnityEngine.Random.Range(1, 5); trial.Y = aufgaben[trialCount].y; // UnityEngine.Random.Range(1, 5); trial.R = aufgaben[trialCount].r;// numbers10[trialCount];// UnityEngine.Random.Range(1, 5); if (aufgaben[trialCount].op == 1) trial.Op = "+"; if (aufgaben[trialCount].op == 2) trial.Op = "-"; for (int i = 0; i < trial.X; i++) { hand[i].GetComponent().enabled = true; hand[i].GetComponent().SetBool("fadeout", false); hand[i].GetComponent().Play("StarFadeIn", -1, 0f); } //int level = Int32.Parse(Gamestate.Instance.getLevel()); if (Gamestate.Instance.getLevel() == "1") results[aufgaben[trialCount].x-1].GetComponent().enabled = true; number.text = trial.X.ToString(); //setze touchtime und ob finger gedrueckt zurück for (int i = 0; i < 10; i++) { fingers[i] = false; times[i] = 0.0f; } trialCount += 1; trial.TrialCounter = trialCount; } public void exitGame() { //Gamestate.Instance.setGamePoints(score); //Gamestate.Instance.setGame("Count"); //Gamestate.Instance.setLevel("1"); if(game != "ending") { savePlayerData(); } DontDestroyOnLoad(Gamestate.Instance); Gamestate.Instance.menuState(); } private void OnApplicationPause(bool pauseStatus) { if(game != "ending") { savePlayerData(); } } private void OnApplicationQuit() { if(game != "ending") { savePlayerData(); } } public void savePlayerData() { // string bauen und zeilenweise rausschreiben //Debug.Log("save data on "+Application.persistentDataPath+"/playerData"+Gamestate.Instance.GetPlayerData().ID+".txt"); StreamWriter sw = new StreamWriter(Application.persistentDataPath+"/playerData"+Gamestate.Instance.getID()+".txt", true); //File.Open(Application.persistentDataPath+"/playerData"+Gamestate.Instance.GetPlayerData().ID+".dat",FileMode.Append); //BinaryFormatter bf = new BinaryFormatter(); string header= "Date Time TrialOnset ID Game Level Trial TargetNum1 TargetNum2 TargetNum3 TargetOp Score Correct Correct2 t1ID t1X t1Y t1deltaTime " + "t2ID t2X t2Y t2deltaTime t3ID t3X t3Y t3deltaTime t4ID t4X t4Y t4deltaTime t5ID t5X t5Y t5deltaTime t6ID t6X t6Y t6deltaTime "+ "t7ID t7X t7Y t7deltaTime t8ID t8X t8Y t8deltaTime t9ID t9X t9Y t9deltaTime t10ID t10X t10Y t10deltaTime"; sw.WriteLine(header); foreach (Trial t in trials) { string line = t.Date + " " + t.Time + " " + t.Onset + " " + t.ID + " " + t.Game + " " + t.Level + " " + t.TrialCounter + " " + t.X + " " + t.Y + " " + t.R + " " + t.Op + " " + t.Score + " " + t.Correct + " " + t.Correct2; int i=0; foreach(TouchSer item in t.T) { line = line + " " + item.TouchID + " " + item.X.ToString() + " " + item.Y.ToString() + " " + item.Timestamp; i++; } for (int j = i; j <10; j++) { line = line + " " + "99" + " " + "0" + " " + "0" + " " + "0"; } //Debug.Log("line: " + line); //dump(trial); sw.WriteLine(line); } sw.Close(); } IEnumerator playTutorial() { tutorialIsPlaying = true; TutorialPlayer.enabled=true; //Add VideoPlayer to the GameObject //Play Video vp.Play(); //Play Sound audioSource.Play(); //Debug.Log("Playing Video"); while (vp.isPlaying) { //Debug.LogWarning("Video Time: " + Mathf.FloorToInt((float)vp.time)); yield return null; } //TutorialPlayer.GetComponent().SetBool("fadeout",true);//.Play("tutorial2", -1, 0f); TutorialPlayer.enabled = false; background.GetComponent().SetInteger("fade",2); //yield return new WaitForSeconds(0.3f); //Debug.Log("background anim state2 = "+background.GetComponent().GetCurrentAnimatorStateInfo(0).fullPathHash.ToString()); //Debug.Log("background anim state3 = "+background.GetComponent().GetCurrentAnimatorStateInfo(0).fullPathHash.ToString()); /*var currentState = background.GetComponent().GetCurrentAnimatorStateInfo(0); while(currentState.fullPathHash == Animator.StringToHash("Base Layer.Player_standing")) { yield return null; }*/ //yield return new WaitForSeconds(0.3f); Debug.Log("Done Playing Video"); //background.GetComponent().SetBool("fade_out", false); //background.GetComponent().SetBool("idle_in",false); error_count=0; playNextTrial=false; //targetTime4 = 0.3f; game="next_trial"; } IEnumerator playTutorial2() { tutorialIsPlaying = true; TutorialPlayer2.enabled=true; //Add VideoPlayer to the GameObject //Play Video vp2.Play(); //Play Sound audioSource2.Play(); //Debug.Log("Playing Video"); while (vp2.isPlaying) { //Debug.LogWarning("Video Time: " + Mathf.FloorToInt((float)vp.time)); yield return null; } //TutorialPlayer.GetComponent().SetBool("fadeout",true);//.Play("tutorial2", -1, 0f); TutorialPlayer2.enabled = false; background.GetComponent().SetInteger("fade",2); //yield return new WaitForSeconds(0.3f); //Debug.Log("background anim state2 = "+background.GetComponent().GetCurrentAnimatorStateInfo(0).fullPathHash.ToString()); //Debug.Log("background anim state3 = "+background.GetComponent().GetCurrentAnimatorStateInfo(0).fullPathHash.ToString()); /*var currentState = background.GetComponent().GetCurrentAnimatorStateInfo(0); while(currentState.fullPathHash == Animator.StringToHash("Base Layer.Player_standing")) { yield return null; }*/ //yield return new WaitForSeconds(0.3f); Debug.Log("Done Playing Video"); //background.GetComponent().SetBool("fade_out", false); //background.GetComponent().SetBool("idle_in",false); error_count=0; playNextTrial=false; //targetTime4 = 0.3f; game="next_trial"; } public void dump(Trial t) { Debug.Log("------------------TRIAL-START------------------"); Debug.Log("date: " + t.Date); Debug.Log("time: " + t.Time); Debug.Log("trialOnset: " + t.Onset); Debug.Log("game: " + t.Game); Debug.Log("level: " + t.Level); Debug.Log("score: " + t.Score); Debug.Log("ID: " + t.ID); Debug.Log("Trial_counter: " + t.TrialCounter); Debug.Log("x: " + t.X); Debug.Log("y: " + t.Y); Debug.Log("r: " + t.R); Debug.Log("Correct: " + t.Correct); Debug.Log("Correct2: " + t.Correct2); foreach (TouchSer item in t.T) { Debug.Log("touch.id: " + item.TouchID); Debug.Log("touch.x: " + item.X.ToString()); Debug.Log("touch.y: " + item.Y.ToString()); Debug.Log("touch.time: " + item.Timestamp); } Debug.Log("------------------TRIAL-END------------------"); } }