private void initTestData() { testData = new TestData() { userStartTime = System.DateTime.Now.ToString("MM/dd/yyyy hh:mm:ss"), userData = userData, ipInfo = "", snenasMotionData = new List <SnenaMotionData>(), rightObjectsList = new List <TestObjects>(), selectedObjectsList = new List <TestObjects>(), colorTestResult = new ColorTestResult(), textTestResult = new TextTestResult() }; //curSnenaMotionData = new SnenaMotionData() { i = 0, act = new List<int[]>() }; curSnenaMotionData = new SnenaMotionData() { i = 0, act = new List <UserActivity>() }; lastAction = new int[16]; }
//void StartAction(float speedUp) { StartCoroutine(RotateCamera(2f, -speedUp, "End rotation")); } // switch between scenas public void NextScene(int delta) // switch scenes //utility.logDebug("NextScene cur="+ curScene +" delta="+ delta); //utility.logDebug("Next"); { isActionSave = false; isHintDisplay = false; isDisplayTimer = false; animVR = false; trDirect = false; SceneEventSystem.enabled = false; //Camera.main.GetComponent<GvrPointerPhysicsRaycaster>().enabled = false; // Debug.Log("curScene=" + curScene +" delta="+ delta+" "+ JsonUtility.ToJson(curSnenaMotionData)); curScene += delta; if (!dataSended) { if (delta > 0) { testData.snenasMotionData.Add(curSnenaMotionData); } curfocusObjCode = new int[11] { -1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; //curSnenaMotionData = new SnenaMotionData(){i = curScene, act = new List<int[]>()}; Debug.Log(JsonUtility.ToJson(curSnenaMotionData)); curSnenaMotionData = new SnenaMotionData() { i = 0, act = new List <UserActivity>() }; } if (rootObj) { Destroy(rootObj); } if (TimerCanvas) { Destroy(TimerCanvas); } switch (curScene) { case -1: // change language menu rootObj = utility.ShowSwitchlngMenu(userLang); StartCoroutine(utility.rotateText(rootObj, true, 2, "", 0)); trDirect = true; break; case 0: // show a intro message Debug.Log("Start 0 scene"); rootObj = utility.ShowMessage(Data.getMessage(userLang, "Intro"), "Next", Data.getMessage(userLang, "btnNext"), new Vector2(1200, 400), TextAnchor.MiddleCenter, new Vector2(0, 40)); utility.CreateButton(rootObj.transform.GetChild(0).gameObject.transform.GetChild(0).gameObject.transform, "LangSw", Data.getMessage(userLang, "btnLangSw"), "LangSw", "", new Vector3(400, 230, 0), new Vector2(400, 60)); try { txtVR = (GameObject)Instantiate(Resources.Load <GameObject>("VR")); addVR(rootObj, new Vector3(0f, 5, 0)); animVR = true; } catch (System.Exception e) { Debug.Log("Can not load VR nodel"); } trDirect = true; break; case 1: // show a select gender message rootObj = utility.ShowGenderMenu(userLang); trDirect = true; break; case 2: // show a select birthday message rootObj = utility.ShowDigitsKeyboard(userLang, "Birth"); trDirect = true; break; case 3: // show a start test 1 message curTestIndex = 0; string msg1 = string.Format(Data.getMessage(userLang, "Test1"), Data.getMessage(userLang, "color_" + testsConfig[curTestIndex, 0]), Data.getMessage(userLang, "obj_" + testsConfig[curTestIndex, 0])); //Debug.Log("Test1=" + msg1); rootObj = utility.ShowMessage(msg1, "Next", Data.getMessage(userLang, "btnStart"), new Vector2(1200, 400), TextAnchor.MiddleCenter, new Vector2(0, 40)); StartCoroutine(utility.rotateText(rootObj, true, 2, "newObj", 0)); trDirect = true; break; case 4: // start test 1 curTestIndex = 0; rootObj = utility3D.CreateObjsArray(false); isHintDisplay = true; isDisplayTimer = false; break; case 5: // show a start test 2 message curTestIndex = 1; string msg2 = string.Format(Data.getMessage(userLang, "Test2"), Data.getMessage(userLang, "color_" + testsConfig[curTestIndex, 1]), Data.getMessage(userLang, "obj_" + testsConfig[curTestIndex, 0]), testsConfig[curTestIndex, 5]); rootObj = utility.ShowMessage(msg2, "Next", Data.getMessage(userLang, "btnStart"), new Vector2(1200, 400), TextAnchor.MiddleCenter, new Vector2(0, 40)); utility3D.createTarget(rootObj, testsConfig[0, 1]); trDirect = true; break; case 6: //start test 2 with a time limit curTestIndex = 1; rootObj = utility3D.CreateObjsArray(true); isHintDisplay = true; isDisplayTimer = true; break; case 7: // show a color test start message rootObj = utility.ShowMessage(Data.getMessage(userLang, "IntroColTest"), "Next", Data.getMessage(userLang, "btnStart"), new Vector2(1200, 400), TextAnchor.MiddleCenter, new Vector2(0, 40)); trDirect = true; break; case 8: // start color test //Debug.Log("Start color test "+JsonUtility.ToJson(testData.colorTestResult)); if (testData.colorTestResult.selected != null) { testData.colorTestResult.selected.Clear(); } else { testData.colorTestResult.selected = new List <TestAnswer>(); } Debug.Log("Start color test " + JsonUtility.ToJson(testData.colorTestResult)); testData.colorTestResult.energy = 0; testData.colorTestResult.stress = 0; testData.colorTestResult.totalTime = 0; //Debug.Log("Start color test " + JsonUtility.ToJson(testData.colorTestResult)); rootObj = colorTest.showColors("selAllCol"); GameObject msgObj2 = utility.ShowMessage(Data.getMessage(userLang, "selAllCol"), "", Data.getMessage(userLang, "btnStart"), new Vector2(1200, 200), TextAnchor.MiddleCenter, new Vector2(0, 20)); msgObj2.transform.SetParent(rootObj.transform); msgObj2.transform.position = new Vector3(0, 5.4f, 16); trDirect = true; break; case 9: // show a start text test message string strTxtIntro = string.Format(Data.getMessage(userLang, "IntroTextTest"), Data.getQuestionsCount(userLang)); rootObj = utility.ShowMessage(strTxtIntro, "Next", Data.getMessage(userLang, "btnStart"), new Vector2(1200, 400), TextAnchor.MiddleCenter, new Vector2(0, 40)); trDirect = true; break; case 10: // start a text test initTable(); NextQuestion(); trDirect = true; break; case 11: // show results //initTable(); // for test only!! rootObj = utility.showResult(userLang, testData.colorTestResult.stress, testData.colorTestResult.energy, testData.textTestResult.Name1, testData.textTestResult.Name2, testData.textTestResult.Value1, testData.textTestResult.Value2, testData.textTestResult.Power); StartCoroutine(utility.rotateText(rootObj, true, 2, "", 0)); trDirect = true; isTimerShowResult = true; break; case 12: // show a start text test message rootObj = utility.ShowMessage(Data.getMessage(userLang, "msgAbout"), "Back", Data.getMessage(userLang, "btnBack"), new Vector2(1200, 600), TextAnchor.MiddleCenter, new Vector2(0, 40)); StartCoroutine(utility.rotateText(rootObj, true, 2, "", 0)); trDirect = true; break; default: Debug.Log("Not Found current scene index"); break; } userSceneDataTime[0] = 0f; userSceneDataTime[1] = 0f; trackingTime[1] = 0f; SceneEventSystem.enabled = true; actFrmsCnt = 0; if (!dataSended) { isActionSave = true; } }
// on the cusror timed click on an active object in a scena private void ClickSelectEvent() { isTimer = false; Debug.Log("clickSelectEvent=" + curfocusType + "=" + curfocusObj); utility.logDebug("ClickTimed"); switch (curfocusType) { case "Next": // start next scena GameObject model = GameObject.Find("Model"); if (model) { Destroy(model); } StartCoroutine(utility.rotateText(rootObj, false, 2, "NextScene", 1)); break; case "Test": // test scenes activity GameObject gm = GameObject.Find(curfocusObj); StartCoroutine(utility3D.appearObject(gm, false)); //Debug.Log(testData.selectedObjectsList.Count + "="+ JsonUtility.ToJson(testData.selectedObjectsList)); testData.selectedObjectsList[testData.selectedObjectsList.Count - 1].objs.Add( new TestObject() { time = Mathf.RoundToInt(userSceneDataTime[1] * 1000), i = curfocusObjCode[0], lx = curfocusObjCode[5], ly = curfocusObjCode[6], lz = curfocusObjCode[7], rx = curfocusObjCode[8], type = curfocusObjCode[1], // cur obj type color = curfocusObjCode[2], // cur obj color }); userSceneDataTime[1] = 0f; testsConfig[curTestIndex, 4]++; // if this is a right object if (curfocusObjCode[0] != 0) { testsConfig[curTestIndex, 3]++; } //Debug.Log("obj:"+ curfocusObj + " result right:" + testsConfig[curTestIndex, 3] + " total:" + testsConfig[curTestIndex, 4]); // if a testing person reach a limit of objects if (testsConfig[curTestIndex, 4] >= testsConfig[curTestIndex, 2]) { testEnd(); } else { string msg = string.Format(Data.getMessage(userLang, "Test_hint"), Data.getMessage(userLang, "color_" + testsConfig[curTestIndex, 1]), Data.getMessage(userLang, "obj_" + testsConfig[curTestIndex, 0]), testsConfig[curTestIndex, 4], testsConfig[curTestIndex, 2]); if (isHintDisplay) { msg += string.Format(Data.getMessage(userLang, "Test_timer"), Mathf.Floor(testTime).ToString()); } if (hintText) { hintText.text = msg; } } // Debug.Log("result2: right:"+testsConfig[curTestIndex, 3] + " total:"+testsConfig[curTestIndex, 4]); break; case "Keyboard": // email input scena, typing if (curfocusObj.Contains("DEL")) { string str = TextInput.text; if (str.Length > 0) { TextInput.text = str.Substring(0, str.Length - 1); } } else { if (TextInput) { TextInput.text += curfocusObj; } } break; case "KeyboardDigit": // input date string strDigit = TextInput.text; int pos = strDigit.IndexOf('X'); char[] chars = strDigit.ToCharArray(); if (curfocusObj.Contains("DEL")) { Debug.Log(" digts = " + strDigit + " pos=" + pos); if (pos > 0) { int jDig; for (jDig = pos - 1; jDig >= 0; jDig--) { if (!chars[jDig].Equals(' ')) { chars[jDig] = 'X'; TextInput.text = new string(chars); break; } } } } else { if (TextInput) { chars[pos] = curfocusObj.ToCharArray()[0]; TextInput.text = new string(chars); if (pos > 22) { StartCoroutine(utility.rotateText(rootObj, false, 2, "NextScene", 1)); } } } break; case "EnterName": // save user name userData.name = TextInput.text; StartCoroutine(utility.rotateText(rootObj, false, 2, "NextScene", 1)); break; case "EnterEmail": // save user email userData.email = TextInput.text; StartCoroutine(utility.rotateText(rootObj, false, 2, "NextScene", 1)); break; case "Exit": Application.Quit(); break; // exit from app case "CloseHelp": if (modalWindow) { GameObject.Destroy(modalWindow); } ; rootObj.SetActive(true); break; case "ShowHelp": rootObj.SetActive(false); if (modalWindow) { GameObject.Destroy(modalWindow); } string[] arrNameHelp = curfocusObj.Split('_'); string msgHelp = string.Format(Data.getMessage(userLang, "dsc" + arrNameHelp[0]), arrNameHelp[1]); modalWindow = utility.ShowMessage(msgHelp, "CloseHelp", Data.getMessage(userLang, "btnClose"), new Vector2(1400, 700), TextAnchor.MiddleCenter, new Vector2(0, 40)); break; // exit from app case "selOneCol": // select only one color StartCoroutine(colorTest.FadeTo(GameObject.Find("b_" + curfocusObj))); int colorIndex = 0; int.TryParse(curfocusObj, out colorIndex); testsConfig[0, 1] = colorIndex; testsConfig[1, 1] = colorIndex; //Debug.Log(testsConfig[1, 1]); StartCoroutine(utility.rotateText(rootObj, false, 2, "NextScene", 1)); break; case "selAllCol": // select colors one by one StartCoroutine(colorTest.FadeTo(GameObject.Find("b_" + curfocusObj))); int colorI = 0; int.TryParse(curfocusObj, out colorI); testData.colorTestResult.selected.Add(new TestAnswer { id = colorI, nm = 0, t = Mathf.RoundToInt(userSceneDataTime[1] * 1000) }); userSceneDataTime[1] = 0f; if (testData.colorTestResult.selected.Count > 6) { float s = 0; float e = 0; float[] kArray = new float[] { 8.1f, 6.8f, 6, 5.3f, 4.7f, 4, 3.2f, 1.8f }; for (int i = 0; i < testData.colorTestResult.selected.Count; i++) { if (i < 3) { if (testData.colorTestResult.selected[i].id == 0 || testData.colorTestResult.selected[i].id == 6 || testData.colorTestResult.selected[i].id == 7) { s += kArray[i]; } } if (i > 4) { if (testData.colorTestResult.selected[i].id == 1 || testData.colorTestResult.selected[i].id == 2 || testData.colorTestResult.selected[i].id == 3 || testData.colorTestResult.selected[i].id == 4) { s += kArray[7 - i]; } } if (testData.colorTestResult.selected[i].id == 2 || testData.colorTestResult.selected[i].id == 3 || testData.colorTestResult.selected[i].id == 4) { e += kArray[i]; } //Debug.Log("Calculate: i=" +i+" color="+testData.colorTestResult.selected[i].id + " s=" +s+" e="+e); // } testData.colorTestResult.stress = Mathf.RoundToInt(100 * s / 42); testData.colorTestResult.energy = Mathf.RoundToInt(100 * (e - 9) / 12); testData.colorTestResult.totalTime = Mathf.RoundToInt(userSceneDataTime[0] * 1000); //Debug.Log("Color test result= " + JsonUtility.ToJson(testData.colorTestResult)); StartCoroutine(utility.rotateText(rootObj, false, 5, "NextScene", 1)); } break; case "NextQuestion": // text test action int surKey = 0; int.TryParse(curfocusObj, out surKey); testData.textTestResult.answers.Add(new TestAnswer { id = curQuestionKey, nm = surKey, t = Mathf.RoundToInt(userSceneDataTime[1] * 1000) }); userSceneDataTime[1] = 0f; //Debug.Log("item = " + JsonUtility.ToJson(testData.textTestResult.answers)); if (surKey == 0) { if (Data.Answers["+"].Contains(curQuestionKey)) { testData.textTestResult.extra++; } if (Data.Answers["n"].Contains(curQuestionKey)) { testData.textTestResult.stabil++; } } else { if (Data.Answers["-"].Contains(curQuestionKey)) { testData.textTestResult.extra++; } } if (questionsCount > testData.textTestResult.answers.Count) { StartCoroutine(utility.rotateText(rootObj, false, 5, "NextQuestion", 1)); } else { float cnt = Data.getQuestionsCount(userLang) / 2; float resExtra = (testData.textTestResult.extra - cnt / 2) / cnt; float resStabil = (testData.textTestResult.stabil - cnt / 2) / cnt; testData.textTestResult.totalTime = Mathf.RoundToInt(userSceneDataTime[0] * 1000); float a = Mathf.Atan2(resStabil, resExtra); string[] pTypeName = new string[2]; float[] pTypeValue = new float[2]; float mid = Mathf.PI / 4; float pi_2 = Mathf.PI / 2; testData.textTestResult.Power = Mathf.RoundToInt(Mathf.Sqrt(Mathf.Pow(resExtra, 2) + Mathf.Pow(resStabil, 2))); float mod_a = Mathf.Abs(a); if (mod_a <= mid) { pTypeName[0] = "Choleric"; pTypeName[1] = "Sanguine"; pTypeValue[0] = Mathf.Abs(mid + a) / pi_2; pTypeValue[1] = Mathf.Abs(mid - a) / pi_2; } else if (mod_a >= 3 * mid) { pTypeName[0] = "Phlegmatic"; pTypeName[1] = "Melancholic"; if (a > 0) { pTypeValue[0] = Mathf.Abs(a - 3 * mid) / pi_2; pTypeValue[1] = Mathf.Abs(5 * mid - a) / pi_2; } else { pTypeValue[0] = Mathf.Abs(-5 * mid - a) / pi_2; pTypeValue[1] = Mathf.Abs(-3 * mid - a) / pi_2; } } else { if (testData.textTestResult.stabil > 0) { pTypeName[0] = "Choleric"; pTypeName[1] = "Melancholic"; pTypeValue[0] = Mathf.Abs(3 * mid - a) / pi_2; pTypeValue[1] = Mathf.Abs(mid - a) / pi_2; } else { pTypeName[0] = "Phlegmatic"; pTypeName[1] = "Sanguine"; pTypeValue[0] = Mathf.Abs(-mid - a) / pi_2; pTypeValue[1] = Mathf.Abs(-3 * mid - a) / pi_2; } } testData.textTestResult.Name1 = pTypeName[0]; testData.textTestResult.Value1 = Mathf.RoundToInt(100 * pTypeValue[0]); testData.textTestResult.Name2 = pTypeName[1]; testData.textTestResult.Value2 = Mathf.RoundToInt(100 * pTypeValue[1]); //Debug.Log("Test result2 = " + JsonUtility.ToJson(testData.textTestResult)); isActionSave = false; testData.snenasMotionData.Add(curSnenaMotionData); sendDataToServer(); dataSended = true; StartCoroutine(utility.rotateText(rootObj, false, 5, "NextScene", 1)); } break; case "LangSw": animVR = false; StartCoroutine(utility.rotateText(rootObj, false, 2, "NextScene", -1)); break; case "LangSwMenu": // change language action Debug.Log("obj= " + curfocusObj); userLang = curfocusObj; StartCoroutine(utility.rotateText(rootObj, false, 2, "NextScene", 1)); break; case "GenderSwMenu": Debug.Log("obj= " + curfocusObj); userData.gender = curfocusObj; StartCoroutine(utility.rotateText(rootObj, false, 2, "NextScene", 1)); break; case "Back": StartCoroutine(utility.rotateText(rootObj, false, 2, "NextScene", -1)); break; case "Repeat": // repeat all tests initTestData(); // curSnenaMotionData = new SnenaMotionData() { i = 0, act = new List<int[]>() }; curSnenaMotionData = new SnenaMotionData() { i = 0, act = new List <UserActivity>() }; curScene = 3; dataSended = false; NextScene(0); break; case "StartGyro": runText.enabled = false; runText.text = ""; NextScene(1); break; default: Debug.Log("clickSelectEvent not found action for " + name); break; } OnExitTimed(); }